Skip to content

Pattern

xtay2 edited this page Mar 15, 2023 · 2 revisions

Introduction

The Pattern is a terminal that matches any pre-specified regex. It gets used primarily for identifiers.

Constructors

  1. Section(String regex):
    • Converts the regex to a java.util.regex.Pattern
    • Calls constructor 2
  2. Section(java.util.regex.Pattern pattern):
    • Matches the whole pattern
    • tokenize() Produces a TerminalToken when matched
  3. Section(Function<String, TerminalToken> tokenFactory, String regex):
    • Converts the regex to a java.util.regex.Pattern
    • Calls constructor 4
  4. Section(Function<String, TerminalToken> tokenFactory, java.util.regex.Pattern pattern):
    • Matches the whole pattern
    • tokenize() calls the tokenFactory when matched

Examples

new Pattern("[a-zA-Z_]+");

Matches

"hello_world"
"HelloWorld"
"HELLO_WORLD"
"___"

Fails

""
"Hello-World"
Clone this wiki locally