-
Notifications
You must be signed in to change notification settings - Fork 0
Pattern
xtay2 edited this page Mar 15, 2023
·
2 revisions
The Pattern
is a terminal that matches any pre-specified regex. It gets used primarily for identifiers.
-
Section(String regex)
:- Converts the regex to a java.util.regex.Pattern
- Calls constructor 2
-
Section(java.util.regex.Pattern pattern)
:- Matches the whole pattern
- tokenize() Produces a TerminalToken when matched
-
Section(Function<String, TerminalToken> tokenFactory, String regex)
:- Converts the regex to a java.util.regex.Pattern
- Calls constructor 4
-
Section(Function<String, TerminalToken> tokenFactory, java.util.regex.Pattern pattern)
:- Matches the whole pattern
- tokenize() calls the tokenFactory when matched
new Pattern("[a-zA-Z_]+");
Matches
"hello_world"
"HelloWorld"
"HELLO_WORLD"
"___"
Fails
""
"Hello-World"