# IO:TextRider

This is a port of the writer part of TextRider to IO. Reader and scanner were dropped. Don't use the riders with non-blocking channels.

### Import List

        Ascii
        CharClass
        Exception
        IO
        LRealStr
        Object
        Object

Class List
OverflowError | Raised if the parsed datatype has correct syntax but it interpetation is not valid, because of numerical overflow or similar reason.
Reader |
Writer |

Class Summary: OverflowError [Detail]

      +---Exception.Exception
           |
           +---Exception.Checked
                |
                +---IO.Error
                     |
                     +--IO:TextRider.OverflowError

Raised if the parsed datatype has correct syntax but it interpetation is not valid, because of numerical overflow or similar reason.

Constructor Summary
NewOverflowError(STRING): OverflowError
Inherited Methods
From Exception.Exception: GetMessage, Name, WriteBacktrace From IO.Error: INIT

Class Summary: Reader [Detail]

      +--IO:TextRider.Reader

Field Summary
channel-: ByteChannel The channel on which this reader is operating.
Constructor Summary
ConnectReader(ByteChannel): Reader Create a new instance of Reader that is initialized with IO.ByteChannel ch.
Method Summary
[AquireBufferWithSize](LONGINT)
[ConsumeWhiteSpace]()
INIT(ByteChannel) Initializes an already allocated Reader with the IO.ByteChannel ch.
ReadBool(VAR BOOLEAN) Sets ``bool=TRUE`' if input equals ``TRUE`', and ``bool=FALSE`' if input equals ``FALSE`'.
ReadChar(VAR CHAR) Read a character.
ReadHex(VAR LONGINT) Reads a Oberon-2 hex value.
ReadIdentifier(VAR ARRAY OF CHAR) Reads an Oberon-2 identifier.
ReadInt(VAR INTEGER) See Reader.ReadLInt.
ReadLInt(VAR LONGINT) Returns the long integer constant lint at the current position according to the format ``IntConst = [whitespace] ["+"|"-"] digit`'.
ReadLine(VAR ARRAY OF CHAR) Reads a sequence of characters into s; reading continues until an end-of-line character is encountered, the array s is full, or r reaches the end of the channel.
[ReadLineBuffer]()
ReadLn() This method reads and discards all characters up to and including the next end-of-line character.
ReadSInt(VAR SHORTINT) See Reader.ReadLInt.
ReadString(VAR ARRAY OF CHAR) Reads in a sequence of characters enclosed in single (') or double (") quote marks.
SetEOL(SHORTINT) Define which character token is interpreted as line end.

Class Summary: Writer [Detail]

      +--IO:TextRider.Writer

Field Summary
channel-: ByteChannel The channel on which this writer is operating.
error-: Error If any of the write methods encounters an error, then the corresponding exception is stored here.
Constructor Summary
ConnectWriter(ByteChannel): Writer
Method Summary
INIT(ByteChannel)
SetEol(ARRAY OF CHAR, INTEGER) Sets new end of line marker.
WriteBool(BOOLEAN)
WriteChar(CHAR)
WriteHex(LONGINT, LONGINT)
WriteInt(INTEGER, LONGINT)
WriteLInt(LONGINT, LONGINT)
WriteLReal(LONGREAL, LONGINT, LONGINT) Writes the value lreal in the format produced by LRealStr.RealToFloat.
WriteLRealEng(VAR LONGREAL, LONGINT, LONGINT) Writes the value lreal in the format produced by LRealStr.RealToEng.
WriteLRealFix(VAR LONGREAL, LONGINT, LONGINT) Writes the value lreal in the format produced by LRealStr.RealToFixed.
WriteLn() Write a newline.
WriteObject(Object)
WriteReal(REAL, LONGINT, LONGINT) As Writer.WriteLReal.
WriteRealEng(REAL, LONGINT, LONGINT) As Writer.WriteLRealEng.
WriteRealFix(REAL, LONGINT, LONGINT) As Writer.WriteLRealFix.
WriteSInt(SHORTINT, LONGINT)
WriteSet(SET) Write s in Oberon-2 set notation.
WriteString(ARRAY OF CHAR)
WriteStringRegion(ARRAY OF CHAR, LONGINT, LONGINT)

Type Summary
[Buffer] = POINTER TO ARRAY OF CHAR

Procedure Summary
NewProtocolError(STRING): ProtocolError
RaiseOverflowError(STRING)
RaiseProtocolError(STRING)

Constant Summary
eolCR The EOL token is a single Ascii.cr.
eolCRLF The EOL token is a single Ascii.cr+Ascii.lf.
eolLF The EOL token is a single Ascii.lf.
maxLengthEol Maximum length of an end of line character sequence.

Class Detail: OverflowError

Constructor Detail

### NewOverflowError

    PROCEDURE NewOverflowError(msg: STRING): OverflowError

Class Detail: Reader

Field Detail

### channel

    FIELD channel-: ByteChannel

> The channel on which this reader is operating.

Constructor Detail

### ConnectReader

    PROCEDURE ConnectReader(ch: ByteChannel): Reader

> Create a new instance of Reader that is initialized with IO.ByteChannel ch.

> Pre-condition: ch is in blocking mode.

Method Detail

### AquireBufferWithSize

    PROCEDURE (r: Reader) [AquireBufferWithSize](size: LONGINT)

### ConsumeWhiteSpace

    PROCEDURE (r: Reader) [ConsumeWhiteSpace]()
      RAISES Error;

### INIT

    PROCEDURE (r: Reader) INIT(ch: ByteChannel)

> Initializes an already allocated Reader with the IO.ByteChannel ch.

> Pre-condition: ch is in blocking mode.

### ReadBool

    PROCEDURE (r: Reader) ReadBool(VAR bool: BOOLEAN)
      RAISES Error;

> Sets ``bool=TRUE`' if input equals ``TRUE`', and ``bool=FALSE`' if input equals ``FALSE`'. If no bool value is available a IO.FormatError exception is raised.

> Pre-condition: ``input=[whitespace] ["TRUE"|"FALSE"]`'

### ReadChar

    PROCEDURE (r: Reader) ReadChar(VAR ch: CHAR)
      RAISES Error;

> Read a character. "End of line" tokens are normalized to Ascii.lf.

> Note: If no character is available a IO.FormatError exception is be raised.

### ReadHex

    PROCEDURE (r: Reader) ReadHex(VAR int: LONGINT)
      RAISES Error;

> Reads a Oberon-2 hex value.

> If no hex number is available a IO.FormatError exception is raised.

> Pre-condition: ``input = [whitespace] digit {hexdigit}`'.

### ReadIdentifier

    PROCEDURE (r: Reader) ReadIdentifier(VAR s: ARRAY OF CHAR)
      RAISES Error;

> Reads an Oberon-2 identifier.

> If s is not large enough to hold the entire input, an OverflowError exception is generated. If no identifier is available a IO.FormatError exception is raised.

> Pre-condition: ``input = [whitespace] letter {letter | digit}`'.

> s must a least have a size of 2.

### ReadInt

    PROCEDURE (r: Reader) ReadInt(VAR int: INTEGER)
      RAISES Error;

> See Reader.ReadLInt.

### ReadLInt

    PROCEDURE (r: Reader) ReadLInt(VAR lint: LONGINT)
      RAISES Error;

> Returns the long integer constant lint at the current position according to the format ``IntConst = [whitespace] ["+"|"-"] digit`'.

> If no integer is available a IO.FormatError exception is raised. If the parsed value is too big an OverflowError is raised.

### ReadLine

    PROCEDURE (r: Reader) ReadLine(VAR s: ARRAY OF CHAR)
      RAISES Error;

> Reads a sequence of characters into s; reading continues until an end-of-line character is encountered, the array s is full, or r reaches the end of the channel. The end-of-line character is discarded and s is always terminated with 0X. If r is already positioned at an end-of-line character, s returns as an empty string.

> s returns with the sequence of characters that have been read so far (terminated by 0X). s must be big enough to hold the line, or a IO.FormatError exception is raised.

> Reading past the end of file causes a IO.FormatError exception. The content of s is undefined in this case.

> Caution: If reading multiple lines of input and an integer, real, etc. has just been read, the channel may be positioned at a eol character and this method will return an empty string.

### ReadLineBuffer

    PROCEDURE (r: Reader) [ReadLineBuffer]()
      RAISES Error;

### ReadLn

    PROCEDURE (r: Reader) ReadLn()
      RAISES Error;

> This method reads and discards all characters up to and including the next end-of-line character.

### ReadSInt

    PROCEDURE (r: Reader) ReadSInt(VAR sint: SHORTINT)
      RAISES Error;

> See Reader.ReadLInt.

### ReadString

    PROCEDURE (r: Reader) ReadString(VAR s: ARRAY OF CHAR)
      RAISES Error;

> Reads in a sequence of characters enclosed in single (') or double (") quote marks. The opening quote must be the same as the closing quote and must not occur within the string. Characters are read until the terminating quote mark is encountered, an invalid character is read (end-of-line is always considered invalid), there are no more characters available in the channel, or the string s is full. s is always terminated with 0X.

> Strings without a terminating quote generate a IO.FormatError exception. If s is not large enough to hold the entire input, a OverflowError exception is generated.

> If the strings contains illegal characters (``char<" "`') a IO.FormatError exception is generated.

> Upon encountering an error, the value of s is undefined.

> Pre-condition: ``input = [whitespace] '"' {char} '"' | [whitespace] "'" {char} "'"`'.

> s must at least have a size of 1.

### SetEOL

    PROCEDURE (r: Reader) SetEOL(type: SHORTINT)

> Define which character token is interpreted as line end. Currently available are eolLF, which is in general used by UNIX, eolCR, which is used by Mac OS, and eolCRLF, which is used by DOS, Windows and various text based network protocols.

Class Detail: Writer

Field Detail

### channel

    FIELD channel-: ByteChannel

> The channel on which this writer is operating.

### error

    FIELD error-: Error

> If any of the write methods encounters an error, then the corresponding exception is stored here. This field is sticky. That is, is stays NIL until the first error, and it keeps the first error's exception.

Constructor Detail

### ConnectWriter

    PROCEDURE ConnectWriter(ch: ByteChannel): Writer

> Pre-condition: ch is in blocking mode.

Method Detail

### INIT

    PROCEDURE (w: Writer) INIT(ch: ByteChannel)

### SetEol

    PROCEDURE (w: Writer) SetEol(marker: ARRAY OF CHAR;
                     markerLen: INTEGER)

> Sets new end of line marker. If the passed string marker does not fit into the writer's field ``w.eol`', then nothing is done. The empty marker is permitted. The default value for newly created writer is CharClass.systemEol.

> Pre-condition: (0 <= markerLen < LEN (marker)) & (markerLen <= maxLengthEol)

### WriteBool

    PROCEDURE (w: Writer) WriteBool(bool: BOOLEAN)

### WriteChar

    PROCEDURE (w: Writer) WriteChar(ch: CHAR)

### WriteHex

    PROCEDURE (w: Writer) WriteHex(lint: LONGINT;
                       d: LONGINT)

### WriteInt

    PROCEDURE (w: Writer) WriteInt(int: INTEGER;
                       n: LONGINT)

### WriteLInt

    PROCEDURE (w: Writer) WriteLInt(lint: LONGINT;
                        n: LONGINT)

### WriteLReal

    PROCEDURE (w: Writer) WriteLReal(lreal: LONGREAL;
                         n: LONGINT;
                         k: LONGINT)

> Writes the value lreal in the format produced by LRealStr.RealToFloat.

### WriteLRealEng

    PROCEDURE (w: Writer) WriteLRealEng(VAR lreal: LONGREAL;
                            n: LONGINT;
                            k: LONGINT)

> Writes the value lreal in the format produced by LRealStr.RealToEng.

### WriteLRealFix

    PROCEDURE (w: Writer) WriteLRealFix(VAR lreal: LONGREAL;
                            n: LONGINT;
                            k: LONGINT)

> Writes the value lreal in the format produced by LRealStr.RealToFixed.

### WriteLn

    PROCEDURE (w: Writer) WriteLn()

> Write a newline.

### WriteObject

    PROCEDURE (w: Writer) WriteObject(obj: Object)

### WriteReal

    PROCEDURE (w: Writer) WriteReal(real: REAL;
                        n: LONGINT;
                        k: LONGINT)

> As Writer.WriteLReal.

### WriteRealEng

    PROCEDURE (w: Writer) WriteRealEng(real: REAL;
                           n: LONGINT;
                           k: LONGINT)

> As Writer.WriteLRealEng.

### WriteRealFix

    PROCEDURE (w: Writer) WriteRealFix(real: REAL;
                           n: LONGINT;
                           k: LONGINT)

> As Writer.WriteLRealFix.

### WriteSInt

    PROCEDURE (w: Writer) WriteSInt(sint: SHORTINT;
                        n: LONGINT)

### WriteSet

    PROCEDURE (w: Writer) WriteSet(s: SET)

> Write s in Oberon-2 set notation.

### WriteString

    PROCEDURE (w: Writer) WriteString(s: ARRAY OF CHAR)

### WriteStringRegion

    PROCEDURE (w: Writer) WriteStringRegion(s: ARRAY OF CHAR;
                                start: LONGINT;
                                end: LONGINT)

Type Detail

### Buffer

    TYPE [Buffer] = POINTER TO ARRAY OF CHAR

Procedure Detail

### NewProtocolError

    PROCEDURE NewProtocolError(msg: STRING): ProtocolError

### RaiseOverflowError

    PROCEDURE RaiseOverflowError(msg: STRING)
      RAISES OverflowError;

### RaiseProtocolError

    PROCEDURE RaiseProtocolError(msg: STRING)
      RAISES ProtocolError;

Constant Detail

### eolCR

    CONST eolCR

> The EOL token is a single Ascii.cr.

### eolCRLF

    CONST eolCRLF

> The EOL token is a single Ascii.cr+Ascii.lf.

### eolLF

    CONST eolLF

> The EOL token is a single Ascii.lf.

### maxLengthEol

    CONST maxLengthEol

> Maximum length of an end of line character sequence. This value is system dependent, and always larger or equal to 2.