| java.lang.Object fri.patterns.interpreter.parsergenerator.lexer.Strategy
Strategy | public class Strategy implements Serializable(Code) | | Strategy is the way how alternative concurrent character consumers are applied to input.
It is used by LexerImpl and ConsumerAlternatives.
There are consumers that have a fixed start character and others that have not.
Consumers have different length of fixed start sequences.
Some consumers have a fixed length to scan, others (with repeatable rules) have not.
Consumers differ in their character sets, some having many possible characters,
others lesser, some sets might overlap those of other consumers.
Last but not least the Parser gives hints about currently expected tokens.
Following is the strategy implemented here:
- Divide consumers in two groups: those with fixed start character and those without.
- Sort both consumers groups by
- by the variance of their start character (which may be a set), the less the better
- their start sequence length (ends before first repeatable character), the longer the better
- by their fixed start length (ends before first character set), the longer the better.
Sorting is done by Consumer implements Comparable
- The lookahead character chooses consumers with fixed start character.
- If one matches, overlapping consumers without fixed start character are tried, when one scans longer, it wins.
- If none matches, consumers without fixed start character are tried, by sort order.
- If one matches, overlapping consumers without fixed start character are tried, when one scans longer, it wins.
author: Fritz Ritzberger |
Method Summary | |
public void | addIgnoringConsumer(String symbol, Consumer cc) Adds a Consumer to list of possible consumers. | public void | addTokenConsumer(String symbol, Consumer cc) Adds a Consumer to list of possible consumers producing valid tokens. | public Item | consume(InputText input, int lookahead, Map expectedTokenSymbols) Liefert null wenn kein consumer den input lesen kann, sonst den laengstmoeglichen gescannten Text. | public boolean | hasTerminal(String terminal) Returns true if the passed terminal is already in list. | public void | setCompeteForLongestInput(boolean competeForLongestInput) | public String | toString() Returns a human readable representation of the lists and maps within this strategy. |
addIgnoringConsumer | public void addIgnoringConsumer(String symbol, Consumer cc)(Code) | | Adds a Consumer to list of possible consumers. This consumer will read input to be ignored by the parser.
|
addTokenConsumer | public void addTokenConsumer(String symbol, Consumer cc)(Code) | | Adds a Consumer to list of possible consumers producing valid tokens.
|
consume | public Item consume(InputText input, int lookahead, Map expectedTokenSymbols) throws IOException(Code) | | Liefert null wenn kein consumer den input lesen kann, sonst den laengstmoeglichen gescannten Text.
Parameters: input - the input to read from Parameters: lookahead - the first byte or character from input Parameters: expectedTokenSymbols - expected token symbols (in key enumeration), can be null |
hasTerminal | public boolean hasTerminal(String terminal)(Code) | | Returns true if the passed terminal is already in list.
|
setCompeteForLongestInput | public void setCompeteForLongestInput(boolean competeForLongestInput)(Code) | | |
toString | public String toString()(Code) | | Returns a human readable representation of the lists and maps within this strategy.
|
|
|