| java.lang.Object fri.patterns.interpreter.parsergenerator.lexer.Consumer
All known Subclasses: fri.patterns.interpreter.parsergenerator.lexer.ConsumerAlternatives,
Consumer | class Consumer implements Comparable,Serializable(Code) | | Consuming characters (or bytes) means reading from an input stream as long
as the read characters match the pattern the consumer was built for.
A consumer can be built with a fixed string, a character set, other
character consumers, or a mixed sequence of those. It can be a list of
alternating (parallel) consumers. It can be set repeatable and nullable.
A character consumer succeeds when he could apply all consumers or
patterns/sets stored in its sequence when reading input. It fails and
unreads all characters when one non-nullable consumer in its sequence fails.
author: (c) 2002, Fritz Ritzberger |
Inner Class :public static class Reference | |
Constructor Summary | |
| Consumer(Rule rule) Empty consumer knowing its rule. | | Consumer(String charOrString) Consumer with some start character or fixed string, without rule. | protected | Consumer() Internal constructor needed in LexerBuilder. |
Method Summary | |
public void | append(String charOrString) Append a String or character to sequence. | public void | append(Reference subConsumer) Add a character consumer reference. | public void | append(Consumer subConsumer) Add a character consumer. | public void | appendSet(String high) Add a character set by its high character. | public int | compareTo(Object o) Implements Comparable: Sort alternatives by precedence: - getStartVariance(), + getStartLength(), + getFixedLength(). | public ResultTree | consume(InputText input) Reads from input. | protected ResultTree | consumeInternal(InputText input) Consumes characters from Input and stores it into returned result tree. | public List | getAlternatives() Always returns null as this consumer holds no alternatives. | public int | getFixedLength() The fixed length ends before the first found character set (like "0..9") or repeatable or nullable consumer. | protected int | getSomeLength(boolean exploreStartLength, List breakIndicator) | public Character | getStartCharacter() Returns the first character of this consumer, or null if starting with a set. | public int | getStartLength() The start length ends before the first found repeatable or nullable consumer (like "chars*"), but not before a character set. | public int | getStartVariance() Returns the count of possible start characters. | public boolean | isNullable() | public boolean | isRepeatable() | protected void | listToString(List list, StringBuffer sb, String separator, boolean separatorAtFirst) Converts a list into String, for toString() method. | boolean | matchesRepeatableRule(Rule rule) Returns true if the rule of this consumer matches the passed left recursive rule.
E.g. | Consumer | optimize() Return contained consumer when having only one and no constraints. | public boolean | overlaps(Consumer cc) Returns true if the passed consumer could be concurrent with this. | public void | resolveConsumerReferences(Map charConsumers, Map doneList) Resolve all references to real consumers after build. | public void | setNullable() | public void | setRepeatable() | public void | setStrategyFactoryMethod(StrategyFactoryMethod strategyFactoryMethod) Passes the factory for Strategy objects to all contained ConsumerAlternatives. | public void | subtract(Consumer constraint) Passed Consumer will constrain every character of this consumer. | public void | subtract(Reference constraint) Passed reference will constrain every character of this consumer. | public String | toString() String representation of consumer: hashcode, sequence and constraints. | protected String | toStringBase() Returns the base string for toString() method. |
fixedLengthstartLengthvariance | protected int fixedLengthstartLengthvariance(Code) | | |
Consumer | Consumer(Rule rule)(Code) | | Empty consumer knowing its rule. This could become a Lexer toplevel consumer.
|
Consumer | Consumer(String charOrString)(Code) | | Consumer with some start character or fixed string, without rule.
|
Consumer | protected Consumer()(Code) | | Internal constructor needed in LexerBuilder.
|
append | public void append(String charOrString)(Code) | | Append a String or character to sequence.
|
append | public void append(Reference subConsumer)(Code) | | Add a character consumer reference.
|
append | public void append(Consumer subConsumer)(Code) | | Add a character consumer.
|
appendSet | public void appendSet(String high) throws LexerException(Code) | | Add a character set by its high character. Low character is previously appended one.
|
compareTo | public int compareTo(Object o)(Code) | | Implements Comparable: Sort alternatives by precedence: - getStartVariance(), + getStartLength(), + getFixedLength().
|
consume | public ResultTree consume(InputText input) throws IOException(Code) | | Reads from input. Returns null if input did not match, else a result tree containing the text.
Ensures that a nullable consumer never returns null and a repeatable consumer repeats.
Parameters: input - Input object where to read from. null if no match, else scanned input as a result tree. |
consumeInternal | protected ResultTree consumeInternal(InputText input) throws IOException(Code) | | Consumes characters from Input and stores it into returned result tree.
Returns null if nothing has been consumed.
|
getAlternatives | public List getAlternatives()(Code) | | Always returns null as this consumer holds no alternatives.
|
getFixedLength | public int getFixedLength()(Code) | | The fixed length ends before the first found character set (like "0..9") or repeatable or nullable consumer.
|
getSomeLength | protected int getSomeLength(boolean exploreStartLength, List breakIndicator)(Code) | | |
getStartCharacter | public Character getStartCharacter()(Code) | | Returns the first character of this consumer, or null if starting with a set.
|
getStartLength | public int getStartLength()(Code) | | The start length ends before the first found repeatable or nullable consumer (like "chars*"), but not before a character set.
|
getStartVariance | public int getStartVariance()(Code) | | Returns the count of possible start characters. For fixed start character this is 1.
|
isNullable | public boolean isNullable()(Code) | | |
isRepeatable | public boolean isRepeatable()(Code) | | |
listToString | protected void listToString(List list, StringBuffer sb, String separator, boolean separatorAtFirst)(Code) | | Converts a list into String, for toString() method.
|
matchesRepeatableRule | boolean matchesRepeatableRule(Rule rule)(Code) | | Returns true if the rule of this consumer matches the passed left recursive rule.
E.g. passing "nonterm ::= nonterm something" would match "nonterm ::= something".
|
optimize | Consumer optimize()(Code) | | Return contained consumer when having only one and no constraints. This is called immediately after construction.
|
overlaps | public boolean overlaps(Consumer cc)(Code) | | Returns true if the passed consumer could be concurrent with this.
This method does not consider constraints, as these could be complex.
|
resolveConsumerReferences | public void resolveConsumerReferences(Map charConsumers, Map doneList) throws LexerException(Code) | | Resolve all references to real consumers after build.
|
setNullable | public void setNullable()(Code) | | |
setRepeatable | public void setRepeatable()(Code) | | |
setStrategyFactoryMethod | public void setStrategyFactoryMethod(StrategyFactoryMethod strategyFactoryMethod)(Code) | | Passes the factory for Strategy objects to all contained ConsumerAlternatives.
|
subtract | public void subtract(Consumer constraint)(Code) | | Passed Consumer will constrain every character of this consumer.
|
subtract | public void subtract(Reference constraint)(Code) | | Passed reference will constrain every character of this consumer.
|
toString | public String toString()(Code) | | String representation of consumer: hashcode, sequence and constraints.
|
toStringBase | protected String toStringBase()(Code) | | Returns the base string for toString() method.
|
|
|