-
Notifications
You must be signed in to change notification settings - Fork 0
Ordered
xtay2 edited this page Mar 15, 2023
·
3 revisions
Ordered
is a non-terminal that represents a sequence of tokens that should match the specified rules in the same order as passed in the constructor.
-
Ordered(Rule... rules)
: Takes at least 2 rules. -
Ordered(Function<Token[], TokenArray> tokenFactory, Rule... rules)
: Like the default constructor but takes an additional factory-method to produce a token-array instance.
-
tokenize(String input): TokenArray
: tokenizes the input string according to the ordered sequence of rules. -
matches(String input): boolean
: returns true if the input string matches the ordered sequence of rules. -
maxMatchLength(String input): int
: returns the length of the longest substring of the input string that matches the ordered sequence of rules. -
firstMatch(String input): int
: returns the index of the first occurrence of a character within the ordered sequence of rules in the input string.
new Ordered(new Literal("abc"), new Word('0', '9');
Matches
"abc 123"
"abc0"
Fails
"abc"
"012 abc"