|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectlp.parse.LpLexer
lp.parse.LpLookaheadLexer
public class LpLookaheadLexer
This class provides the same functionality as LpLexer
and it offers the
possibility to take a look at future tokens and not loose the current
position in the input.
LpLexer
Field Summary | |
---|---|
private LinkedList<LpToken> |
buffer
A LpToken buffer used to implement the lookahead. |
private static String |
NEGATIVE_STEPS_MESSAGE
A string with an exception message used multiple times in the implementation. |
Constructor Summary | |
---|---|
LpLookaheadLexer()
|
Method Summary | |
---|---|
void |
close()
Closes the underlying reader. |
String |
getLexem()
Returns the lexem corresponding to the last token read. |
String |
getLexem(int n)
Returns the lexem corresponding the token n steps further in the
input. |
int |
getLineNumber()
Returns the number of line of input on which the last token occured. |
int |
getLineNumber(int n)
Returns the number of line of input on which the token n steps
further in the input occurs. |
int |
getPosition()
Returns the position of the last token's beginning within the line of input it's on. |
int |
getPosition(int n)
Returns the position of the token n steps further in the input. |
LpToken |
getToken()
Returns a LpToken instance containing information about the last
token read. |
LpToken |
getToken(int n)
Returns a LpToken instance containing information about the token
n steps further in the input. |
LpTokenType |
getTokenType()
Returns the type of the last token read. |
LpTokenType |
getTokenType(int n)
Returns the type of the token n steps further in the input. |
protected void |
initialize()
Reinitializes members and reads the first lookahead character. |
private void |
load(int count)
Reads count tokens and stores them in the buffer. |
void |
nextToken()
Reads the next token occuring on the input. |
Methods inherited from class lp.parse.LpLexer |
---|
setInput, setInput, setInput |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private static final String NEGATIVE_STEPS_MESSAGE
private final LinkedList<LpToken> buffer
LpToken
buffer used to implement the lookahead.
Constructor Detail |
---|
public LpLookaheadLexer()
Method Detail |
---|
public void close()
LpLexer.setInput(CharSequence)
or
LpLexer.setInput(File)
was used to set the current character source,
this method should be called when no more tokens are required from the
source. In other cases it is up to the programmer whether she will close
the Reader
given to LpLexer.setInput(Reader)
herself or call
this method.
close
in interface Closeable
close
in class LpLexer
protected void initialize()
initialize
in class LpLexer
public void nextToken()
nextToken
in class LpLexer
public LpTokenType getTokenType()
LpLexer.nextToken()
is called at least once after the last
setInput()
call. But if such a situation occurs, null
is
returned. Similarily, if LpLexer.close()
has already been called,
null
is returned.
getTokenType
in class LpLexer
public String getLexem()
LpTokenType.EOF
token, empty string is returned. This method is
not meant to be called before LpLexer.nextToken()
is called at least
once after the last setInput()
call. But if such a situation
occurs, null
is returned. Similarily, if LpLexer.close()
has
already been called, null
is returned.
getLexem
in class LpLexer
public int getLineNumber()
LpLexer.nextToken()
is
called at least once after the last setInput()
call. But if such
a situation occurs, -1 is returned. Similarily, if LpLexer.close()
has
already been called, -1 is returned.
getLineNumber
in class LpLexer
public int getPosition()
LpLexer.nextToken()
is
called at least once after the last setInput()
call. But if such
a situation occurs, -1 is returned. Similarily, if LpLexer.close()
has
already been called, -1 is returned.
getPosition
in class LpLexer
public LpToken getToken()
LpToken
instance containing information about the last
token read. The information is read using the LpLexer.getTokenType()
,
LpLexer.getLexem()
, LpLexer.getPosition()
and LpLexer.getLineNumber()
methods.
getToken
in class LpLexer
LpToken
instance containing information about the last
token readpublic LpTokenType getTokenType(int n)
n
steps further in the input. The
same result will be returned if getTokenType()
is called after
n
times calling nextToken()
. The difference is that the
current token doesn't change by calling this method—new tokens are
read but the old ones are stored in a buffer.
This method is not meant to be called before nextToken()
is
called at least once. But if such a situation occurs, null
is
returned. Similarily, if close()
has already been called,
null
is returned.
n
- number of steps further in the input to look at
n
steps further in the input
IOException
- (wrapped in an ExceptionAdapter
)
in case an I/O exception occurs while reading the input
IllegalArgumentException
- if n
is negativepublic String getLexem(int n)
n
steps further in the
input. In case it is a LpTokenType.EOF
token, empty string is
returned. The same result will be returned if getLexem()
is
called after n
times calling nextToken()
. The difference
is that the current token doesn't change by calling this method—new
tokens are read but the old ones are stored in a buffer.
This method is not meant to be called before nextToken()
is
called at least once. But if such a situation occurs, null
is
returned. Similarily, if close()
has already been called,
null
is returned.
n
- number of steps further in the input to look at
n
steps further in
the input
IOException
- (wrapped in an ExceptionAdapter
) in
case an I/O exception occurs while reading the input
IllegalArgumentException
- if n
is negativepublic int getLineNumber(int n)
n
steps
further in the input occurs. Lines are numbered from 1. A newline starts
when either a '\n' or a '\r' character is detected. There is one
exception: a '\n' character occuring right after a '\r' character is
ignored, i.e. not considered to be another line delimiter.
The same result will be returned if getLineNumber()
is
called after n
times calling nextToken()
. The difference
is that the current token doesn't change by calling this method—new
tokens are read but the old ones are stored in a buffer.
This method is not meant to be called before nextToken()
is
called at least once. But if such a situation occurs, -1 is
returned. Similarily, if close()
has already been called,
-1 is returned.
n
- number of steps further in the input to look at
n
steps further in the
input occurs
IOException
- (wrapped in an ExceptionAdapter
) in
case an I/O exception occurs while reading the input
IllegalArgumentException
- if n
is negativepublic int getPosition(int n)
n
steps further in the input.
The characters on the line are numbered from 1. The same result will be
returned if getPosition()
is called after n
times
calling nextToken()
. The difference is that the current token
doesn't change by calling this method—new tokens are read but the
old ones are stored in a buffer.
This method is not meant to be called before nextToken()
is
called at least once. But if such a situation occurs, -1 is
returned. Similarily, if close()
has already been called,
-1 is returned.
n
- number of steps further in the input to look at
IOException
- (wrapped in an ExceptionAdapter
) in
case an I/O exception occurs while reading the input
IllegalArgumentException
- if n
is negativepublic LpToken getToken(int n)
LpToken
instance containing information about the token
n
steps further in the input. The same result will be returned if
getToken()
is called after n
times calling
nextToken()
. The difference is that the current token doesn't
change by calling this method—new tokens are read but the old ones
are stored in a buffer.
This method is not meant to be called before nextToken()
is
called at least once. But if such a situation occurs, null
is
returned. Similarily, if close()
has already been called,
null
is returned.
n
- number of steps further in the input to look at
LpToken
instance containing information about the token
n
steps further in the input
IOException
- (wrapped in an ExceptionAdapter
) in
case an I/O exception occurs while reading the input
IllegalArgumentException
- if n
is negativeprivate void load(int count)
count
tokens and stores them in the buffer.
IOException
- (wrapped in an ExceptionAdapter
) in
case an I/O exception occurs while reading the input
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |