Skip to content

Ordered

xtay2 edited this page Mar 15, 2023 · 3 revisions

Introduction

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.

Constructors

  • 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.

Methods

  • 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.

Examples

new Ordered(new Literal("abc"), new Word('0', '9');

Matches

"abc 123"
"abc0"

Fails

"abc"
"012 abc"
Clone this wiki locally