fri.patterns.interpreter.parsergenerator.lexer
Class Strategy

java.lang.Object
  |
  +--fri.patterns.interpreter.parsergenerator.lexer.Strategy
All Implemented Interfaces:
java.io.Serializable

public class Strategy
extends java.lang.Object
implements java.io.Serializable

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:

Author:
Fritz Ritzberger
See Also:
Serialized Form

Nested Class Summary
static class Strategy.Item
          The List item wrapper for toplevel consumers.
 
Constructor Summary
Strategy()
           
 
Method Summary
 void addIgnoringConsumer(java.lang.String symbol, fri.patterns.interpreter.parsergenerator.lexer.Consumer cc)
          Adds a Consumer to list of possible consumers.
 void addTokenConsumer(java.lang.String symbol, fri.patterns.interpreter.parsergenerator.lexer.Consumer cc)
          Adds a Consumer to list of possible consumers producing valid tokens.
 Strategy.Item consume(fri.patterns.interpreter.parsergenerator.lexer.InputText input, int lookahead, java.util.Map expectedTokenSymbols)
          Liefert null wenn kein consumer den input lesen kann, sonst den laengstmoeglichen gescannten Text.
 boolean hasTerminal(java.lang.String terminal)
          Returns true if the passed terminal is already in list.
 void setCompeteForLongestInput(boolean competeForLongestInput)
           
 java.lang.String toString()
          Returns a human readable representation of the lists and maps within this strategy.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Strategy

public Strategy()
Method Detail

setCompeteForLongestInput

public void setCompeteForLongestInput(boolean competeForLongestInput)

addIgnoringConsumer

public void addIgnoringConsumer(java.lang.String symbol,
                                fri.patterns.interpreter.parsergenerator.lexer.Consumer cc)
Adds a Consumer to list of possible consumers. This consumer will read input to be ignored by the parser.


addTokenConsumer

public void addTokenConsumer(java.lang.String symbol,
                             fri.patterns.interpreter.parsergenerator.lexer.Consumer cc)
Adds a Consumer to list of possible consumers producing valid tokens.


hasTerminal

public boolean hasTerminal(java.lang.String terminal)
Returns true if the passed terminal is already in list.


consume

public Strategy.Item consume(fri.patterns.interpreter.parsergenerator.lexer.InputText input,
                             int lookahead,
                             java.util.Map expectedTokenSymbols)
                      throws java.io.IOException
Liefert null wenn kein consumer den input lesen kann, sonst den laengstmoeglichen gescannten Text.

Parameters:
input - the input to read from
lookahead - the first byte or character from input
expectedTokenSymbols - expected token symbols (in key enumeration), can be null
java.io.IOException

toString

public java.lang.String toString()
Returns a human readable representation of the lists and maps within this strategy.

Overrides:
toString in class java.lang.Object