Class Terminals
List<String>
:
Terminals terms = Terminals
.operators("?", "<", ">", ",")
.words(Scanners.IDENTIFIER)
.keywords("super", "extends")
.build();
Parser<String> typeName = Terminals.identifier();
Parser<?> wildcardWithUpperBound = terms.phrase("?", "extends");
...
parser.from(terms.tokenizer(), Scanners.WHITESPACES.optional()).parse("List<String>");
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionfinal class
BuildsTerminals
instance by defining the words and keywords recognized.static final class
Entry point for parser and tokenizers of character literal.static final class
Entry point for parser and tokenizers of decimal number literal represented asString
.static final class
Entry point for parser and tokenizers of regular identifier.static final class
Entry point for any arbitrary integer literal represented as aString
.static final class
Entry point for parser and tokenizers of integral number literal represented asLong
.static final class
Entry point for parser and tokenizers of scientific notation literal.static final class
Entry point for parser and tokenizers of string literal. -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic Terminals
caseInsensitive
(String[] ops, String[] keywords) Deprecated.static Terminals
caseInsensitive
(Parser<String> wordScanner, String[] ops, String[] keywords) Deprecated.Useoperators(ops) .words(wordScanner) .caseInsensitiveKeywords(keywords) .build()
instead.static Terminals
caseInsensitive
(Parser<String> wordScanner, String[] ops, String[] keywords, Function<String, ?> wordMap) Deprecated.Useoperators(ops) .words(wordScanner) .tokenizeWordsWith(wordMap) .caseInsensitiveKeywords(keywords) .build()
instead.static Terminals
caseSensitive
(String[] ops, String[] keywords) Deprecated.Useoperators(ops) .words(Scanners.IDENTIFIER) .keywords(keywords) .build()
instead.static Terminals
caseSensitive
(Parser<String> wordScanner, String[] ops, String[] keywords) Deprecated.Useoperators(ops) .words(wordScanner) .keywords(keywords) .build()
instead.static Terminals
caseSensitive
(Parser<String> wordScanner, String[] ops, String[] keywords, Function<String, ?> wordMap) Deprecated.Useoperators(ops) .words(wordScanner) .tokenizeWordsWith(wordMap) .keywords(keywords) .build()
instead.(package private) static void
fromFragment
(Object... tags) Returns aTokenMap
object that only recognizesTokens.Fragment
token values tagged with one oftags
.Returns aParser
that recognizes identifiers (a.k.a words, variable names etc).static Terminals
Returns aTerminals
object for lexing the operators with names specified inops
.static Terminals
operators
(Collection<String> ops) Returns aTerminals
object for lexing the operators with names specified inops
.Starts to build a newTerminals
instance that recognizes words not already recognized bythis
Terminals
instance (typically operators).
-
Field Details
-
RESERVED
Parser
that recognizes reserved word tokens. i.e.Tokens.Fragment
tokens tagged asTokens.Tag.RESERVED
.Tokens.Fragment.text()
is returned as parser result.
-
-
Constructor Details
-
Terminals
-
-
Method Details
-
caseInsensitive
Deprecated.Useoperators(ops) .words(Scanners.IDENTIFIER) .caseInsensitiveKeywords(keywords) .build()
instead.Returns aTerminals
object for lexing and parsing the operators with names specified inops
, and for lexing and parsing the keywords case insensitively. Parsers for operators and keywords can be obtained throughLexicon.token(java.lang.String...)
; parsers for identifiers throughidentifier()
.In detail, keywords and operators are lexed as
Tokens.Fragment
withTokens.Tag.RESERVED
tag. Words that are not amongkeywords
are lexed asFragment
withTokens.Tag.IDENTIFIER
tag.A word is defined as an alphanumeric string that starts with
[_a - zA - Z]
, with 0 or more[0 - 9_a - zA - Z]
following.- Parameters:
ops
- the operator names.keywords
- the keyword names.- Returns:
- the Terminals instance.
-
caseSensitive
Deprecated.Useoperators(ops) .words(Scanners.IDENTIFIER) .keywords(keywords) .build()
instead.Returns aTerminals
object for lexing and parsing the operators with names specified inops
, and for lexing and parsing the keywords case sensitively. Parsers for operators and keywords can be obtained throughLexicon.token(java.lang.String...)
; parsers for identifiers throughidentifier()
.In detail, keywords and operators are lexed as
Tokens.Fragment
withTokens.Tag.RESERVED
tag. Words that are not amongkeywords
are lexed asFragment
withTokens.Tag.IDENTIFIER
tag.A word is defined as an alphanumeric string that starts with
[_a - zA - Z]
, with 0 or more[0 - 9_a - zA - Z]
following.- Parameters:
ops
- the operator names.keywords
- the keyword names.- Returns:
- the Terminals instance.
-
caseInsensitive
@Deprecated public static Terminals caseInsensitive(Parser<String> wordScanner, String[] ops, String[] keywords) Deprecated.Useoperators(ops) .words(wordScanner) .caseInsensitiveKeywords(keywords) .build()
instead.Returns aTerminals
object for lexing and parsing the operators with names specified inops
, and for lexing and parsing the keywords case insensitively. Parsers for operators and keywords can be obtained throughLexicon.token(java.lang.String...)
; parsers for identifiers throughidentifier()
.In detail, keywords and operators are lexed as
Tokens.Fragment
withTokens.Tag.RESERVED
tag. Words that are not amongkeywords
are lexed asFragment
withTokens.Tag.IDENTIFIER
tag.- Parameters:
wordScanner
- the scanner that returns a word in the language.ops
- the operator names.keywords
- the keyword names.- Returns:
- the Terminals instance.
-
caseSensitive
@Deprecated public static Terminals caseSensitive(Parser<String> wordScanner, String[] ops, String[] keywords) Deprecated.Useoperators(ops) .words(wordScanner) .keywords(keywords) .build()
instead.Returns aTerminals
object for lexing and parsing the operators with names specified inops
, and for lexing and parsing the keywords case sensitively. Parsers for operators and keywords can be obtained throughLexicon.token(java.lang.String...)
; parsers for identifiers throughidentifier()
.In detail, keywords and operators are lexed as
Tokens.Fragment
withTokens.Tag.RESERVED
tag. Words that are not amongkeywords
are lexed asFragment
withTokens.Tag.IDENTIFIER
tag.- Parameters:
wordScanner
- the scanner that returns a word in the language.ops
- the operator names.keywords
- the keyword names.- Returns:
- the Terminals instance.
-
caseInsensitive
@Deprecated public static Terminals caseInsensitive(Parser<String> wordScanner, String[] ops, String[] keywords, Function<String, ?> wordMap) Deprecated.Useoperators(ops) .words(wordScanner) .tokenizeWordsWith(wordMap) .caseInsensitiveKeywords(keywords) .build()
instead.Returns aTerminals
object for lexing and parsing the operators with names specified inops
, and for lexing and parsing the keywords case insensitively. Parsers for operators and keywords can be obtained throughLexicon.token(java.lang.String...)
; parsers for identifiers throughidentifier()
.In detail, keywords and operators are lexed as
Tokens.Fragment
withTokens.Tag.RESERVED
tag. Words that are not amongkeywords
are lexed asFragment
withTokens.Tag.IDENTIFIER
tag.- Parameters:
wordScanner
- the scanner that returns a word in the language.ops
- the operator names.keywords
- the keyword names.wordMap
- maps the text to a token value for non-keywords recognized bywordScanner
.- Returns:
- the Terminals instance.
-
caseSensitive
@Deprecated public static Terminals caseSensitive(Parser<String> wordScanner, String[] ops, String[] keywords, Function<String, ?> wordMap) Deprecated.Useoperators(ops) .words(wordScanner) .tokenizeWordsWith(wordMap) .keywords(keywords) .build()
instead.Returns aTerminals
object for lexing and parsing the operators with names specified inops
, and for lexing and parsing the keywords case sensitively. Parsers for operators and keywords can be obtained throughLexicon.token(java.lang.String...)
; parsers for identifiers throughidentifier()
.In detail, keywords and operators are lexed as
Tokens.Fragment
withTokens.Tag.RESERVED
tag. Words that are not amongkeywords
are lexed asFragment
withTokens.Tag.IDENTIFIER
tag.- Parameters:
wordScanner
- the scanner that returns a word in the language.ops
- the operator names.keywords
- the keyword names.wordMap
- maps the text to a token value for non-keywords recognized bywordScanner
.- Returns:
- the Terminals instance.
-
operators
Returns aTerminals
object for lexing the operators with names specified inops
. Operators are lexed asTokens.Fragment
withTokens.Tag.RESERVED
tag. For example, to get the parser for operator "?", simply calltoken("?")
.If words and keywords need to be parsed, they can be configured via
words(org.jparsec.Parser<java.lang.String>)
.- Parameters:
ops
- the operator names.- Returns:
- the Terminals instance.
-
operators
Returns aTerminals
object for lexing the operators with names specified inops
. Operators are lexed asTokens.Fragment
withTokens.Tag.RESERVED
tag. For example, to get the parser for operator "?", simply calltoken("?")
.If words and keywords need to be parsed, they can be configured via
words(org.jparsec.Parser<java.lang.String>)
.- Parameters:
ops
- the operator names.- Returns:
- the Terminals instance.
- Since:
- 2.2
-
words
Starts to build a newTerminals
instance that recognizes words not already recognized bythis
Terminals
instance (typically operators).By default identifiers are recognized through
identifier()
during token-level parsing phase. UseTerminals.Builder.tokenizeWordsWith(java.util.function.Function<java.lang.String, ?>)
to tokenize differently, and choose an alternative token-level parser accordingly.- Parameters:
wordScanner
- defines words recognized by the new instance- Since:
- 2.2
-
identifier
Returns aParser
that recognizes identifiers (a.k.a words, variable names etc). Equivalent toTerminals.Identifier.PARSER
.- Since:
- 2.2
-
fragment
-
fromFragment
Returns aTokenMap
object that only recognizesTokens.Fragment
token values tagged with one oftags
. -
checkDup
-
operators(ops) .words(Scanners.IDENTIFIER) .caseInsensitiveKeywords(keywords) .build()
instead.