Package org.jparsec
Class Terminals.Builder
java.lang.Object
org.jparsec.Terminals.Builder
- Enclosing class:
Terminals
Builds
Terminals
instance by defining the words and keywords recognized.
The following example implements a calculator with logical operators:
Terminals terms = Terminals
.operators("<", ">", "=", ">=", "<=")
.words(Scanners.IDENTIFIER)
.caseInsensitiveKeywords("and", "or")
.build();
Parser<String> var = Terminals.identifier();
Parser<Integer> integer = Terminals.IntegerLiteral.PARSER.map(...);
Parser<?> and = terms.token("and");
Parser<?> lessThan = terms.token("<");
...
Parser<?> parser = grammar.from(
terms.tokenizer().or(IntegerLiteral.TOKENIZER), Scanners.WHITSPACES.optional());
- Since:
- 2.2
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbuild()
Builds a newTerminals
instance that recognizes words defined in this builder.caseInsensitiveKeywords
(String... keywords) Defines case insensitive keywords.caseInsensitiveKeywords
(Collection<String> keywords) Defines case insensitive keywords.Defines keywords.keywords
(Collection<String> keywords) Defines keywords.tokenizeWordsWith
(Function<String, ?> wordMap) Configures alternative tokenization strategy for words (except keywords).
-
Field Details
-
wordScanner
-
keywords
-
stringCase
-
wordTokenMap
-
-
Constructor Details
-
Builder
-
-
Method Details
-
keywords
Defines keywords. Keywords are special words with their own grammar rules. To get the parser for a keyword, calltoken(keyword)
.Note that if you call
keywords
orcaseInsensitiveKeywords(java.lang.String...)
multiple times on the sameTerminals.Builder
instance, the last call overwrites previous calls. -
keywords
Defines keywords. Keywords are special words with their own grammar rules. To get the parser for a keyword, calltoken(keyword)
.Note that if you call
keywords
orcaseInsensitiveKeywords(java.lang.String...)
multiple times on the sameTerminals.Builder
instance, the last call overwrites previous calls. -
caseInsensitiveKeywords
Defines case insensitive keywords. Keywords are special words with their own grammar rules. To get the parser for a keyword, calltoken(keyword)
.Note that if you call
keywords
orcaseInsensitiveKeywords(java.lang.String...)
multiple times on the sameTerminals.Builder
instance, the last call overwrites previous calls. -
caseInsensitiveKeywords
Defines case insensitive keywords. Keywords are special words with their own grammar rules. To get the parser for a keyword, calltoken(keyword)
.Note that if you call
keywords
orcaseInsensitiveKeywords(java.lang.String...)
multiple times on the sameTerminals.Builder
instance, the last call overwrites previous calls. -
tokenizeWordsWith
Configures alternative tokenization strategy for words (except keywords). -
build
Builds a newTerminals
instance that recognizes words defined in this builder.
-