gnu.text

Class Lexer

Known Direct Subclasses:
Lexer, LispReader, XQParser, XslTranslator

public class Lexer
extends 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.

Constructor Summary

Lexer(LineBufferedReader port)
Lexer(LineBufferedReader port, SourceMessages messages)

Method Summary

boolean
checkErrors(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(String msg)
void
eofError(String message, int startLine, int startColumn)
void
error(String message)
void
error(char severity, String message)
void
error(char severity, String filename, int line, int column, String message)
void
fatal(String message)
int
getColumnNumber()
SourceError
getErrors()
int
getLineNumber()
SourceMessages
getMessages()
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)
void
skip()
protected void
skip_quick()
void
tokenBufferAppend(int ch)
Append one character to tokenBuffer, resizing it if need be.
protected void
unread()
void
unread(int ch)
protected void
unread_quick()

Field Details

interactive

protected boolean interactive

nesting

protected int nesting

port

protected LineBufferedReader port

tokenBuffer

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

tokenBufferLength

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

Constructor Details

Lexer

public Lexer(LineBufferedReader port)

Lexer

public Lexer(LineBufferedReader port,
             SourceMessages messages)

Method Details

checkErrors

public boolean checkErrors(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)

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.

clearErrors

public void clearErrors()

close

public void close()
            throws java.io.IOException

eofError

public void eofError(String msg)
            throws SyntaxException

eofError

public void eofError(String message,
                     int startLine,
                     int startColumn)
            throws SyntaxException

error

public void error(String message)

error

public void error(char severity,
                  String message)

error

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

fatal

public void fatal(String message)
            throws SyntaxException

getColumnNumber

public int getColumnNumber()

getErrors

public SourceError getErrors()

getLineNumber

public int getLineNumber()

getMessages

public SourceMessages getMessages()

getName

public String getName()

getPort

public final LineBufferedReader getPort()

isInteractive

public boolean isInteractive()

mark

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

peek

public int peek()
            throws java.io.IOException

popNesting

public void popNesting(char save)
Exit a nested expression, reversing pushNesting
Parameters:
save - Saved values return by prior pushNesting

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.

read

public int read()
            throws java.io.IOException

read

public int read(char[] buf,
                int offset,
                int length)
            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

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.

reset

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

seenErrors

public boolean seenErrors()

setInteractive

public void setInteractive(boolean v)

setMessages

public void setMessages(SourceMessages messages)

skip

public void skip()
            throws java.io.IOException

skip_quick

protected void skip_quick()
            throws java.io.IOException

tokenBufferAppend

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

unread

protected void unread()
            throws java.io.IOException

unread

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

unread_quick

protected void unread_quick()
            throws java.io.IOException