Package gnu.text
Class Lexer
java.lang.Object
java.io.Reader
gnu.text.Lexer
- All Implemented Interfaces:
Closeable
,AutoCloseable
,Readable
- Direct Known Subclasses:
Lexer
,LispReader
,XQParser
,XslTranslator
Framework for implementing lexical scanners and parsers.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected int
protected gnu.kawa.io.InPort
protected boolean
char[]
For building tokens of various kinds.int
The number of chars of tokenBuffer that are used. -
Constructor Summary
ConstructorsConstructorDescriptionLexer
(gnu.kawa.io.InPort port) Lexer
(gnu.kawa.io.InPort port, SourceMessages messages) -
Method Summary
Modifier and TypeMethodDescriptionboolean
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
void
close()
void
void
void
void
void
void
int
Return the current (zero-based) column number.int
Get the current line number.getName()
final gnu.kawa.io.InPort
getPort()
boolean
boolean
True if input may be incomplete or actively edited.void
mark()
Start tentative parsing.int
peek()
void
popNesting
(char save) Exit a nested expression, reversing pushNestingchar
pushNesting
(char promptChar) Enter a nested expression.int
read()
int
read
(char[] buf, int offset, int length) int
Read a Unicode character (codepoint) by checking for surrogates.boolean
readDelimited
(String delimiter) Scan until a given delimiter.static long
readDigits
(gnu.kawa.io.InPort port, int radix) static long
readDigitsInBuffer
(gnu.kawa.io.InPort port, long ival, int radix) Read digits, up to the first non-digit or the buffer limitint
int
Read an optional signed integer.int
Deprecated.void
reset()
Stop tentative parsing.boolean
void
setInteractive
(boolean v) void
setMessages
(SourceMessages messages) void
setTentative
(boolean v) void
skip()
protected void
void
tokenBufferAppend
(int ch) Append one character to tokenBuffer, resizing it if need be.protected void
unread()
void
unread
(int ch) protected void
Methods inherited from class java.io.Reader
mark, markSupported, nullReader, read, read, ready, skip, transferTo
-
Field Details
-
port
protected gnu.kawa.io.InPort port -
tentative
protected boolean tentative -
nesting
protected int nesting -
tokenBuffer
public char[] tokenBufferFor building tokens of various kinds. -
tokenBufferLength
public int tokenBufferLengthThe number of chars of tokenBuffer that are used.
-
-
Constructor Details
-
Lexer
public Lexer(gnu.kawa.io.InPort port) -
Lexer
-
-
Method Details
-
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 gnu.kawa.io.InPort getPort() -
close
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Specified by:
close
in classReader
- Throws:
IOException
-
read
- Overrides:
read
in classReader
- Throws:
IOException
-
readUnicodeChar
Deprecated.UsereadCodePoint()
.Read a Unicode character (codepoint) by checking for surrogates.- Throws:
IOException
-
readCodePoint
Read a Unicode character (codepoint) by checking for surrogates.- Throws:
IOException
-
read
- Specified by:
read
in classReader
- Throws:
IOException
-
unread
- Throws:
IOException
-
peek
- Throws:
IOException
-
skip
- Throws:
IOException
-
unread
- Throws:
IOException
-
unread_quick
- Throws:
IOException
-
checkNext
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:
IOException
-
skip_quick
- Throws:
IOException
-
getMessages
-
setMessages
-
checkErrors
Returns true if any error were seen. Prints and clears the errors.- Parameters:
out
- where to write the error message tomax
- maximum number of messages to print (can be 0)
-
getErrors
-
seenErrors
public boolean seenErrors() -
clearErrors
public void clearErrors() -
error
-
error
-
error
-
fatal
- Throws:
SyntaxException
-
eofError
- Throws:
SyntaxException
-
eofError
- Throws:
SyntaxException
-
readOptionalExponent
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:
IOException
-
readDelimited
Scan until a given delimiter. On success, text upto the delimiter is in then tokenBuffer (with tokenBufferLength marking its length); the delimiter is not included.- Throws:
IOException
SyntaxException
-
readDigitsInBuffer
public static long readDigitsInBuffer(gnu.kawa.io.InPort port, long ival, int radix) Read digits, up to the first non-digit or the buffer limit- Parameters:
ival
- previously-seen digits or -2 if no digits seen- Returns:
- the digits seen as a non-negative long, or -1 on overflow, or -2 if no digits seen
-
readDigits
- Throws:
IOException
-
readIntDigits
- Throws:
IOException
-
getName
-
getLineNumber
public int getLineNumber()Get the current line number. The "first" line is number number 0. -
getColumnNumber
public int getColumnNumber()Return the current (zero-based) column number. -
isInteractive
public boolean isInteractive() -
setInteractive
public void setInteractive(boolean v) -
isTentative
public boolean isTentative()True if input may be incomplete or actively edited. Used for command-completion and on-the-fly error checking. -
setTentative
public void setTentative(boolean v) -
tokenBufferAppend
public void tokenBufferAppend(int ch) Append one character to tokenBuffer, resizing it if need be. -
tokenBufferString
-
mark
Start tentative parsing. Must be followed by a reset.- Throws:
IOException
-
reset
Stop tentative parsing. Return to position where we called mark.- Overrides:
reset
in classReader
- Throws:
IOException
-
readCodePoint()
.