/* ----------------------------------------------------------------------------- Copyright 2019-2021 Kevin P. Barry Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. ----------------------------------------------------------------------------- */ // Author: Kevin P. Barry [ta0kira@gmail.com] // Reader of discrete blocks of data. // // Params: // - #x: The value type to be read. @value interface BlockReader<|#x> { // Read a block of the given size. // // Notes: // - Negative values can have any behavior. // - This should gracefully handle block sizes that exceed available input. readBlock (Int) -> (#x) // Returns true iff nothing further can be read. pastEnd () -> (Bool) } // Line-based text reader. concrete TextReader { // Create from a BlockReader. @type fromBlockReader (BlockReader) -> (TextReader) // Create and read all data from a block reader. // // Notes: // - If the BlockReader is also a PersistentResource, make sure to separately // clean it up afterward. @type readAll (BlockReader) -> (String) // Return the next line of data, up to '\n' or '\r'. // // Notes: // - This does not automatically handle varying newline types. @value readNextLine () -> (String) // Returns true iff nothing further can be read. @value pastEnd () -> (Bool) } // Simple input sources. concrete SimpleInput { refines BlockReader // Returns a BlockReader for standard input. @type stdin () -> (BlockReader) }