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 classBuildsTerminalsinstance by defining the words and keywords recognized.static final classEntry point for parser and tokenizers of character literal.static final classEntry point for parser and tokenizers of decimal number literal represented asString.static final classEntry point for parser and tokenizers of regular identifier.static final classEntry point for any arbitrary integer literal represented as aString.static final classEntry point for parser and tokenizers of integral number literal represented asLong.static final classEntry point for parser and tokenizers of scientific notation literal.static final classEntry point for parser and tokenizers of string literal. -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic TerminalscaseInsensitive(String[] ops, String[] keywords) Deprecated.static TerminalscaseInsensitive(Parser<String> wordScanner, String[] ops, String[] keywords) Deprecated.Useoperators(ops) .words(wordScanner) .caseInsensitiveKeywords(keywords) .build()instead.static TerminalscaseInsensitive(Parser<String> wordScanner, String[] ops, String[] keywords, Function<String, ?> wordMap) Deprecated.Useoperators(ops) .words(wordScanner) .tokenizeWordsWith(wordMap) .caseInsensitiveKeywords(keywords) .build()instead.static TerminalscaseSensitive(String[] ops, String[] keywords) Deprecated.Useoperators(ops) .words(Scanners.IDENTIFIER) .keywords(keywords) .build()instead.static TerminalscaseSensitive(Parser<String> wordScanner, String[] ops, String[] keywords) Deprecated.Useoperators(ops) .words(wordScanner) .keywords(keywords) .build()instead.static TerminalscaseSensitive(Parser<String> wordScanner, String[] ops, String[] keywords, Function<String, ?> wordMap) Deprecated.Useoperators(ops) .words(wordScanner) .tokenizeWordsWith(wordMap) .keywords(keywords) .build()instead.(package private) static voidfromFragment(Object... tags) Returns aTokenMapobject that only recognizesTokens.Fragmenttoken values tagged with one oftags.Returns aParserthat recognizes identifiers (a.k.a words, variable names etc).static TerminalsReturns aTerminalsobject for lexing the operators with names specified inops.static Terminalsoperators(Collection<String> ops) Returns aTerminalsobject for lexing the operators with names specified inops.Starts to build a newTerminalsinstance that recognizes words not already recognized bythisTerminalsinstance (typically operators).
-
Field Details
-
RESERVED
Parserthat recognizes reserved word tokens. i.e.Tokens.Fragmenttokens 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 aTerminalsobject 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.FragmentwithTokens.Tag.RESERVEDtag. Words that are not amongkeywordsare lexed asFragmentwithTokens.Tag.IDENTIFIERtag.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 aTerminalsobject 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.FragmentwithTokens.Tag.RESERVEDtag. Words that are not amongkeywordsare lexed asFragmentwithTokens.Tag.IDENTIFIERtag.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 aTerminalsobject 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.FragmentwithTokens.Tag.RESERVEDtag. Words that are not amongkeywordsare lexed asFragmentwithTokens.Tag.IDENTIFIERtag.- 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 aTerminalsobject 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.FragmentwithTokens.Tag.RESERVEDtag. Words that are not amongkeywordsare lexed asFragmentwithTokens.Tag.IDENTIFIERtag.- 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 aTerminalsobject 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.FragmentwithTokens.Tag.RESERVEDtag. Words that are not amongkeywordsare lexed asFragmentwithTokens.Tag.IDENTIFIERtag.- 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 aTerminalsobject 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.FragmentwithTokens.Tag.RESERVEDtag. Words that are not amongkeywordsare lexed asFragmentwithTokens.Tag.IDENTIFIERtag.- 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 aTerminalsobject for lexing the operators with names specified inops. Operators are lexed asTokens.FragmentwithTokens.Tag.RESERVEDtag. 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 aTerminalsobject for lexing the operators with names specified inops. Operators are lexed asTokens.FragmentwithTokens.Tag.RESERVEDtag. 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 newTerminalsinstance that recognizes words not already recognized bythisTerminalsinstance (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 aParserthat recognizes identifiers (a.k.a words, variable names etc). Equivalent toTerminals.Identifier.PARSER.- Since:
- 2.2
-
fragment
-
fromFragment
Returns aTokenMapobject that only recognizesTokens.Fragmenttoken values tagged with one oftags. -
checkDup
-
operators(ops) .words(Scanners.IDENTIFIER) .caseInsensitiveKeywords(keywords) .build()instead.