PerCederberg.Grammatica.Runtime
Class TokenNFA
System.Object
|
+--TokenNFA
in TokenNFA.cs
- internal class TokenNFA
- extends System.Object
A non-deterministic finite state automaton (NFA) for matching
tokens. It supports both fixed strings and simple regular
expressions, but should perform similar to a DFA due to highly
optimized data structures and tuning. The memory footprint during
matching should be near zero, since no heap memory is allocated
unless the pre-allocated queues need to be enlarged. The NFA also
does not use recursion, but iterates in a loop instead.
- Since:
- 1.5
AddRegExpMatch
public void AddRegExpMatch( string pattern, bool ignoreCase, TokenPattern value );
- Adds a regular expression match to this automaton. New states
and transitions will be added to extend this automaton to
support the specified string. Note that this method only
supports a subset of the full regular expression syntax, so
a more complete regular expression library must also be
provided.
- Parameters:
pattern - the regular expression string
ignoreCase - the case-insensitive match flag
value - the match value
- Throws:
RegExpException - if the regular expression parsing
failed
AddTextMatch
public void AddTextMatch( string str, bool ignoreCase, TokenPattern value );
- Adds a string match to this automaton. New states and
transitions will be added to extend this automaton to support
the specified string.
- Parameters:
str - the string to match
ignoreCase - the case-insensitive match flag
value - the match value
Match
public int Match( ReaderBuffer buffer, TokenMatch match );
- Checks if this NFA matches the specified input text. The
matching will be performed from position zero (0) in the
buffer. This method will not read any characters from the
stream, just peek ahead.
- Parameters:
buffer - the input buffer to check
match - the token match to update
- Returns:
- the number of characters matched, or
zero (0) if no match was found
- Throws:
IOException - if an I/O error occurred