gnu.text
Class Lexer

java.lang.Object
  extended by java.io.Reader
      extended by gnu.text.Lexer
All Implemented Interfaces:
java.io.Closeable, java.lang.Readable
Direct Known Subclasses:
Lexer, LispReader, XQParser, XslTranslator

public class Lexer
extends java.io.Reader

Framework for implementing lexical scanners and parsers.


Field Summary
protected  boolean interactive
           
protected  int nesting
           
protected  LineBufferedReader port
           
 char[] tokenBuffer
          For building tokens of various kinds.
 int tokenBufferLength
          The number of chars of tokenBuffer that are used.
 
Fields inherited from class java.io.Reader
lock
 
Constructor Summary
Lexer(LineBufferedReader port)
           
Lexer(LineBufferedReader port, SourceMessages messages)
           
 
Method Summary
 boolean checkErrors(java.io.PrintWriter out, int max)
          Returns true if any error were seen.
 boolean checkNext(char ch)
          Check if the next character matches a given character.
 void clearErrors()
           
 void close()
           
 void eofError(java.lang.String msg)
           
 void eofError(java.lang.String message, int startLine, int startColumn)
           
 void error(char severity, java.lang.String message)
           
 void error(char severity, java.lang.String filename, int line, int column, java.lang.String message)
           
 void error(java.lang.String message)
           
 void fatal(java.lang.String message)
           
 int getColumnNumber()
           
 SourceError getErrors()
           
 int getLineNumber()
           
 SourceMessages getMessages()
           
 java.lang.String getName()
           
 LineBufferedReader getPort()
           
 boolean isInteractive()
           
 void mark()
          Start tentative parsing.
 int peek()
           
 void popNesting(char save)
          Exit a nested expression, reversing pushNesting
 char pushNesting(char promptChar)
          Enter a nested expression.
 int read()
           
 int read(char[] buf, int offset, int length)
           
static long readDigitsInBuffer(LineBufferedReader port, int radix)
          Read digits, up to the first non-digit or the buffer limit
 int readOptionalExponent()
          Read an optional signed integer.
 void reset()
          Stop tentative parsing.
 boolean seenErrors()
           
 void setInteractive(boolean v)
           
 void setMessages(SourceMessages messages)
           
protected  void skip_quick()
           
 void skip()
           
 void tokenBufferAppend(int ch)
          Append one character to tokenBuffer, resizing it if need be.
protected  void unread_quick()
           
protected  void unread()
           
 void unread(int ch)
           
 
Methods inherited from class java.io.Reader
mark, markSupported, read, read, ready, skip
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

port

protected LineBufferedReader port

interactive

protected boolean interactive

nesting

protected int nesting

tokenBuffer

public char[] tokenBuffer
For building tokens of various kinds.


tokenBufferLength

public int tokenBufferLength
The number of chars of tokenBuffer that are used.

Constructor Detail

Lexer

public Lexer(LineBufferedReader port)

Lexer

public Lexer(LineBufferedReader port,
             SourceMessages messages)
Method Detail

pushNesting

public char pushNesting(char promptChar)
Enter a nested expression. This is used in interactive mode to control whether to continue past end of line, depending on whether the expression is incomplete.

Parameters:
promptChar - Used in prompt string to indicate type of nesting.
Returns:
The previous value of promptChar, to be passed to popNesting.

popNesting

public void popNesting(char save)
Exit a nested expression, reversing pushNesting

Parameters:
save - Saved values return by prior pushNesting

getPort

public final LineBufferedReader getPort()

close

public void close()
           throws java.io.IOException
Specified by:
close in interface java.io.Closeable
Specified by:
close in class java.io.Reader
Throws:
java.io.IOException

read

public int read()
         throws java.io.IOException
Overrides:
read in class java.io.Reader
Throws:
java.io.IOException

read

public int read(char[] buf,
                int offset,
                int length)
         throws java.io.IOException
Specified by:
read in class java.io.Reader
Throws:
java.io.IOException

unread

public void unread(int ch)
            throws java.io.IOException
Throws:
java.io.IOException

peek

public int peek()
         throws java.io.IOException
Throws:
java.io.IOException

skip

public void skip()
          throws java.io.IOException
Throws:
java.io.IOException

unread

protected void unread()
               throws java.io.IOException
Throws:
java.io.IOException

unread_quick

protected void unread_quick()
                     throws java.io.IOException
Throws:
java.io.IOException

checkNext

public boolean checkNext(char ch)
                  throws java.io.IOException
Check if the next character matches a given character.

Parameters:
ch - The character to match against.
Returns:
if the character read matches On a match, the position is advanced following that character.
Throws:
java.io.IOException

skip_quick

protected void skip_quick()
                   throws java.io.IOException
Throws:
java.io.IOException

getMessages

public SourceMessages getMessages()

setMessages

public void setMessages(SourceMessages messages)

checkErrors

public boolean checkErrors(java.io.PrintWriter out,
                           int max)
Returns true if any error were seen. Prints and clears the errors.

Parameters:
out - where to write the error message to
max - maximum number of messages to print (can be 0)

getErrors

public SourceError getErrors()

seenErrors

public boolean seenErrors()

clearErrors

public void clearErrors()

error

public void error(char severity,
                  java.lang.String filename,
                  int line,
                  int column,
                  java.lang.String message)

error

public void error(char severity,
                  java.lang.String message)

error

public void error(java.lang.String message)

fatal

public void fatal(java.lang.String message)
           throws SyntaxException
Throws:
SyntaxException

eofError

public void eofError(java.lang.String msg)
              throws SyntaxException
Throws:
SyntaxException

eofError

public void eofError(java.lang.String message,
                     int startLine,
                     int startColumn)
              throws SyntaxException
Throws:
SyntaxException

readOptionalExponent

public int readOptionalExponent()
                         throws java.io.IOException
Read an optional signed integer. If there is no integer in the input stream, return 1. For excessively large exponents, return Integer.MIN_VALUE or Integer.MAX_VALUE.

Throws:
java.io.IOException

readDigitsInBuffer

public static long readDigitsInBuffer(LineBufferedReader port,
                                      int radix)
Read digits, up to the first non-digit or the buffer limit

Returns:
the digits seen as a non-negative long, or -1 on overflow

getName

public java.lang.String getName()

getLineNumber

public int getLineNumber()

getColumnNumber

public int getColumnNumber()

isInteractive

public boolean isInteractive()

setInteractive

public void setInteractive(boolean v)

tokenBufferAppend

public void tokenBufferAppend(int ch)
Append one character to tokenBuffer, resizing it if need be.


mark

public void mark()
          throws java.io.IOException
Start tentative parsing. Must be followed by a reset.

Throws:
java.io.IOException

reset

public void reset()
           throws java.io.IOException
Stop tentative parsing. Return to position where we called mark.

Overrides:
reset in class java.io.Reader
Throws:
java.io.IOException