|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--fri.patterns.interpreter.parsergenerator.lexer.LexerImpl
This Lexer must be created using LexerBuilder. It knows token and ignored terminals. To get this Lexer working the setTerminals() call must be called at least once. When using the Lexer standalone, the client must do this, else the Parser will call that method.
This lexer can be reused, but it can not be loaded with other syntaxes after it has been built for one.
Nested Class Summary |
Nested classes inherited from class fri.patterns.interpreter.parsergenerator.Lexer |
Lexer.TokenListener |
Field Summary | |
protected Strategy |
strategy
|
Constructor Summary | |
protected |
LexerImpl()
Do-nothing constructor for subclasses (currently unused). |
|
LexerImpl(java.util.List ignoredSymbols,
java.util.Map charConsumers)
Creates a Lexer from token- and ignored symbols, and a map of character consumers (built by LexerBuilder). |
Method Summary | |
void |
addTokenListener(Lexer.TokenListener tokenListener)
Implements Lexer. |
void |
clear()
Implements Lexer: Does nothing as no states are stored. |
protected Token |
createToken(java.lang.String tokenIdentifier,
ResultTree result,
LexerSemantic lexerSemantic)
Token factory method. |
protected Token |
createToken(java.lang.String tokenIdentifier,
java.lang.String text,
Token.Range range)
Token factory method. |
void |
dump(java.io.PrintStream out)
Outputs current and previous line, with line numbers. |
int |
getColumn()
Returns the position within the current line, 0-n. |
int |
getLine()
Returns the number of the current line, 1-n. |
java.lang.String |
getLineText()
Returns the current line, as far as read. |
Token |
getNextToken(LexerSemantic lexerSemantic)
This is an optional functionality of Lexer. |
Token |
getNextToken(java.util.Map expectedTokenSymbols)
Implements Lexer: returns the next token from input, or EPSILON when no more input. |
int |
getOffset()
Returns the offset read so far from input. |
boolean |
lex(LexerSemantic lexerSemantic)
This is an optional functionality of Lexer. |
protected void |
loopResultTree(ResultTree result,
LexerSemantic lexerSemantic)
After top-down lexing this method is called to dispatch all results. |
Strategy |
newStrategy()
Implements StrategyFactoryMethod. |
void |
removeTokenListener(Lexer.TokenListener tokenListener)
Implements Lexer. |
void |
setCompeteForLongestInput(boolean competeForLongestInput)
When false, the sort order (significance) of scan items without fixed start character decide what token is returned. |
void |
setDebug(boolean debug)
Implements Lexer: Set debug on to output information about scanned tokens. |
void |
setInput(java.lang.Object text)
Implements Lexer: set the input to be scanned. |
void |
setTerminals(java.util.List terminals)
Implements Lexer: Parser call to pass all tokens symbols (all enclosed in `backquote`) and literals ("xyz"). |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
protected Strategy strategy
Constructor Detail |
public LexerImpl(java.util.List ignoredSymbols, java.util.Map charConsumers)
ignoredSymbols
- list of Strings containing ignored symbols to scan. These are NOT enclosed in `backquotes` like tokens.charConsumers
- map with key = nonterminal and value = Consumer.protected LexerImpl()
Method Detail |
public void addTokenListener(Lexer.TokenListener tokenListener)
addTokenListener
in interface Lexer
tokenListener
- the Lexer.Listener implementation to install.public void removeTokenListener(Lexer.TokenListener tokenListener)
removeTokenListener
in interface Lexer
tokenListener
- the Lexer.Listener implementation to remove.public Strategy newStrategy()
newStrategy
in interface StrategyFactoryMethod
public void setCompeteForLongestInput(boolean competeForLongestInput)
public void setInput(java.lang.Object text) throws java.io.IOException
setInput
in interface Lexer
text
- text to scan, as String, StringBuffer, File, InputStream, Reader.
java.io.IOException
public void setTerminals(java.util.List terminals)
setTerminals
in interface Lexer
terminals
- List of String containing "literals" and `lexertokens`.public void clear()
clear
in interface Lexer
public Token getNextToken(LexerSemantic lexerSemantic) throws java.io.IOException
lexerSemantic
- the LexerSemantic to be called with every evaluated Rule and its lexing ResultTree.
java.io.IOException
public Token getNextToken(java.util.Map expectedTokenSymbols) throws java.io.IOException
getNextToken
in interface Lexer
expectedTokenSymbols
- contains the expected String token symbols (in keys),
can be null when no Parser drives this Lexer.
java.io.IOException
protected Token createToken(java.lang.String tokenIdentifier, ResultTree result, LexerSemantic lexerSemantic)
protected Token createToken(java.lang.String tokenIdentifier, java.lang.String text, Token.Range range)
public boolean lex(LexerSemantic lexerSemantic) throws java.io.IOException
lexerSemantic
- the LexerSemantic to be called with every evaluated Rule and its lexing ResultTree.
java.io.IOException
protected void loopResultTree(ResultTree result, LexerSemantic lexerSemantic)
result
- lexer result, returns text on getText().
public void setDebug(boolean debug)
setDebug
in interface Lexer
public java.lang.String getLineText()
public int getLine()
public int getColumn()
public int getOffset()
public void dump(java.io.PrintStream out)
dump
in interface Lexer
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |