org.inxar.syntacs.analyzer
Interface Input

All Known Implementing Classes:
StandardInput

public interface Input

The Input interface is responsible for presenting a raw character stream to the Lexer in a way that makes the lexing process easier. Since all the methods in this interface deal with character handling, they all end in "ch". This was not the case originally --- only getch() was named with the ch-suffix. But I thought fetch(), retch() and strech() were so exceedingly clever that I converted the rest of the names to the ch-suffix-convention.


Method Summary
 int atch()
          "At char" (no argument): Returns the current absolute position of the input (the offset), as though an index into an array.
 void atch(int offset)
          "At char (with argument)": Sets the input position to the given argument.
 int atln()
          "At line": Returns the current line number.
 void bach(int len)
          "backup chars": Moves the input "back" the given number of characters.
 int broach()
          Returns the forthcoming char without advancing the buffer (like a `peek').
 void fetch(int offset, int length, char[] dst, int dstoff)
          "Fetch chars": Copies the region from offset with given length into the dst array provided starting at the given destination offset.
 int getch()
          "Get char": Gets the next char and advances the offset by one.
 void initch(Object src)
          Initialize the Input source to the given Object.
 void patch(int offset, char[] src, int srcoff, int length)
          "Patch": change the given region starting at the given offset.
 char retch(int offset)
          "Return char": get the the char at the given offset.
 char[] retch(int offset, int length)
          "Return chars": Gets the region from offset to length as a new character array.
 String stretch(int offset, int length)
          "Return chars as String": fetches the stretch of characters from offset to length as a new string.
 

Method Detail

initch

public void initch(Object src)
            throws IOException
Initialize the Input source to the given Object.

broach

public int broach()
Returns the forthcoming char without advancing the buffer (like a `peek'). If the end of the buffer has been reached, -1 is returned.

getch

public int getch()
          throws EOFException,
                 IOException
"Get char": Gets the next char and advances the offset by one. If the end of input symbol has already been returned and getch() is called again, EOFException is thrown. Underlying IOExceptions that may occur are delegated to the caller.

bach

public void bach(int len)
"backup chars": Moves the input "back" the given number of characters. For example, if the state of the input over the sequence 'abc' is after position 2 (0,1,2; therefore directly after 'c'), ungetch(3) would move the input pointer back three characters and therefore to the beginning (just before 'a').

retch

public char[] retch(int offset,
                    int length)
"Return chars": Gets the region from offset to length as a new character array. Retch stands for `return characters', but also invokes the vulgar sense of the word by `throwing up' new arrays.
Throws:
ArrayIndexOutOfBoundsException - if the region ifs not valid.

retch

public char retch(int offset)
"Return char": get the the char at the given offset.

stretch

public String stretch(int offset,
                      int length)
"Return chars as String": fetches the stretch of characters from offset to length as a new string.
Throws:
ArrayIndexOutOfBoundsException - if the region ifs not valid.

fetch

public void fetch(int offset,
                  int length,
                  char[] dst,
                  int dstoff)
"Fetch chars": Copies the region from offset with given length into the dst array provided starting at the given destination offset.
Throws:
ArrayIndexOutOfBoundsException - if the region ifs not valid.

patch

public void patch(int offset,
                  char[] src,
                  int srcoff,
                  int length)
"Patch": change the given region starting at the given offset. This is used only in lexical error correction.

atch

public int atch()
"At char" (no argument): Returns the current absolute position of the input (the offset), as though an index into an array.

atch

public void atch(int offset)
"At char (with argument)": Sets the input position to the given argument.

atln

public int atln()
"At line": Returns the current line number.