oracle.javatools.parser
Class AbstractLexer
java.lang.Object
oracle.javatools.parser.AbstractLexer
- All Implemented Interfaces:
- Lexer
- Direct Known Subclasses:
- GenericLexer
- public abstract class AbstractLexer
- extends java.lang.Object
- implements Lexer
The AbstractLexer
is a basic abstract implementation which takes care of common functionality across all Lexers, such as the buffer and offset issues, and for providing a basic LexerToken
object which just stores token and offset information.
- See Also:
Lexer
, AbstractLexer.DefaultLexerToken
Nested Class Summary |
protected static class |
AbstractLexer.DefaultLexerToken
The DefaultLexerToken just implements a basic LexerToken which stores a token and start/end offsets. |
Field Summary |
protected int |
currentPos
The current position in the buffer where the next lex operation will occur (assuming that backup() has not been called.) |
protected ReadTextBuffer |
textBuffer
The underlying text buffer we are lexing. |
Method Summary |
abstract void |
backup()
Unlexes the last found token. |
LexerToken |
createLexerToken()
Creates an empty LexerToken for a specific Lexer implementation to be passed in to the lex() call to be filled in. |
ReadTextBuffer |
getTextBuffer()
Gets the text buffer that is being used by this Lexer. |
abstract int |
lex(LexerToken lexedToken)
Scans the text buffer at the current position and returns the token that was found. |
void |
setPosition(int offset)
Sets the current lex (read) position to the given offset in the buffer. |
void |
setTextBuffer(ReadTextBuffer buffer)
Sets the text buffer that is to be used by this Lexer. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
textBuffer
protected ReadTextBuffer textBuffer
- The underlying text buffer we are lexing.
currentPos
protected int currentPos
- The current position in the buffer where the next lex operation will occur (assuming that
backup()
has not been called.)
AbstractLexer
public AbstractLexer()
setTextBuffer
public void setTextBuffer(ReadTextBuffer buffer)
- Sets the text buffer that is to be used by this Lexer.
-
- Specified by:
setTextBuffer
in interface Lexer
-
- Parameters:
buffer
- the text buffer to use
getTextBuffer
public ReadTextBuffer getTextBuffer()
- Gets the text buffer that is being used by this Lexer.
-
- Specified by:
getTextBuffer
in interface Lexer
-
- Returns:
- the text buffer being used
setPosition
public void setPosition(int offset)
- Sets the current lex (read) position to the given offset in the buffer. It is the clients responsibility to ensure that this offset corresponds to the start of a token, otherwise unexpected (and incorrect) results may occur.
-
- Specified by:
setPosition
in interface Lexer
-
- Parameters:
offset
- the offset for the next lex()
operation.
createLexerToken
public LexerToken createLexerToken()
- Creates an empty
LexerToken
for a specific Lexer
implementation to be passed in to the lex()
call to be filled in.
-
- Specified by:
createLexerToken
in interface Lexer
-
- Returns:
- a newly created LexerToken
lex
public abstract int lex(LexerToken lexedToken)
- Scans the text buffer at the current position and returns the token that was found. The token and offset information is also stored in the
lexedToken
instance passed in to the call.
-
- Specified by:
lex
in interface Lexer
-
- Parameters:
lexedToken
- the instance passed in where token info is stored
- Returns:
- the token that was found, same as calling
lexedToken.getToken()
(for convenience)
backup
public abstract void backup()
- Unlexes the last found token. The next call to
lex()
will return the last token and offset information found.
-
- Specified by:
backup
in interface Lexer
Copyright © 1997, 2004, Oracle. All rights reserved.