V - the type of the parser values@ParametersAreNonnullByDefault public abstract class BaseParser<V> extends BaseActions<V>
| Modifier and Type | Field and Description |
|---|---|
protected static Rule |
ANY
Matches any character except
Chars.EOI. |
protected static Rule |
EMPTY
Matches nothing and always succeeds.
|
protected static Rule |
EOI
End of input rule
|
protected static Rule |
NOTHING
Matches nothing and always fails.
|
| Constructor and Description |
|---|
BaseParser() |
| Modifier and Type | Method and Description |
|---|---|
static <T> Action<T> |
ACTION(boolean expression)
Explicitly marks the wrapped expression as an action expression.
|
Rule |
alpha()
ALPHA as defined by RFC 5234, appendix B, section 1: ASCII letters
|
Rule |
anyOf(char[] characters)
Match any character in the given
char array |
Rule |
anyOf(Characters characters)
Match any given character among a set of characters
|
Rule |
anyOf(String characters)
Match any of the characters in the given string
|
Rule |
asciiChars()
CHAR as defined by RFC 5234, appendix B, section 1: ASCII, except NUL
|
Rule |
bit()
BIT as defined by RFC 5234, appendix B, section 1:
0 or 1 |
Rule |
ch(char c)
Match one given character
|
Rule |
charRange(char cLow,
char cHigh)
Match an inclusive range of
chars |
Rule |
cr()
CR as defined by RFC 5234, appendix B, section 1 (
\r) |
Rule |
crlf()
CRLF as defined by RFC 5234, appendix B, section 1 (
\r\n |
Rule |
ctl()
CTL as defined by RFC 5234, appendix B, section 1: control characters
|
Rule |
digit()
DIGIT as defined by RFC 5234, appendix B, section 1 (0 to 9)
|
Rule |
dquote()
DQUOTE as defined by RFC 5234, appendix B, section 1
" |
Rule |
eof()
Match only at the end of input
|
Rule |
firstOf(Object[] rules)
Match the first rule of a series of rules
|
Rule |
firstOf(Object rule,
Object rule2,
Object... moreRules)
Match the first rule of a series of rules
|
protected Rule |
fromCharArray(char[] array)
Used internally to convert the given char array to a parser rule.
|
protected Rule |
fromCharLiteral(char c)
Used internally to convert the given character literal to a parser rule.
|
protected Rule |
fromStringLiteral(String string)
Used internally to convert the given string literal to a parser rule.
|
Rule |
hexDigit()
Hexadecimal digits, case insensitive
|
Rule |
hexDigitLowerCase()
Hexadecimal digits, lowercase
|
Rule |
hexDigitUpperCase()
Hexadecimal digits, uppercase
|
Rule |
hTab()
HTAB as defined by RFC 5234, appendix B, section 1 (
\t) |
Rule |
ignoreCase(char... characters)
Match a sequence of characters as a string literal (case insensitive)
|
Rule |
ignoreCase(char c)
Match a given character in a case-insensitive manner
|
Rule |
ignoreCase(String string)
Match a string literal in a case insensitive manner
|
JoinMatcherBootstrap<V,BaseParser<V>> |
join(Object rule)
Kickstart a
join rule |
Rule |
lf()
LF as defined by RFC 5234, appendix B, section 1 (
\n) |
Rule |
noneOf(char[] characters)
Match all characters except the ones in the
char array
given as an argument |
Rule |
noneOf(String characters)
Match any characters except the ones contained in the strings
|
Rule |
nTimes(int repetitions,
Object rule)
Match a rule a fixed number of times
|
Rule |
octet()
OCTET as defined by RFC 5234, appendix B, section 1 (0x00 to 0xff)
|
Rule |
oneOrMore(Object rule)
Try and match a rule repeatedly, at least once
|
Rule |
oneOrMore(Object rule,
Object rule2,
Object... moreRules)
Try and repeatedly match a set of rules, at least once
|
Rule |
optional(Object rule)
Try and match a rule zero or one time
|
Rule |
optional(Object rule,
Object rule2,
Object... moreRules)
Try and match a given set of rules once
|
Rule |
sequence(Object[] rules)
Match a given set of rules, exactly once
|
Rule |
sequence(Object rule,
Object rule2,
Object... moreRules)
Match a given set of rules, exactly once
|
Rule |
sp()
SP as defined by RFC 5234, appendix B, section 1 (one space, 0x20)
|
Rule |
string(char... characters)
Match a given set of characters as a string literal
|
Rule |
string(String string)
Match a string literal
|
Rule |
test(Object rule)
Test a rule, but do not consume any input (predicate)
|
Rule |
test(Object rule,
Object rule2,
Object... moreRules)
Test a set of rules, but do not consume any input
|
Rule |
testNot(Object rule)
Test, without consuming an input, that a rule does not match
|
Rule |
testNot(Object rule,
Object rule2,
Object... moreRules)
Test that a set of rules do not apply at this position
|
Rule |
toRule(Object obj)
Converts the given object to a rule.
|
Rule[] |
toRules(Object... objects)
Converts the given object array to an array of rules.
|
Rule |
trie(Collection<String> strings)
Match one string among many using a trie
|
Rule |
trie(String first,
String second,
String... others)
Match one string among many using a trie
|
Rule |
unicodeChar(int codePoint)
Match one Unicode character
|
Rule |
unicodeRange(int low,
int high)
Match a Unicode character range
|
Rule |
vchar()
VCHAR as defined by RFC 5234, appendix B, section 1: ASCII "visible"
|
Rule |
wsp()
WSP as defined by RFC 5234, appendix B, section 1: space or tab
|
Rule |
zeroOrMore(Object rule)
Try and match a rule zero or more times
|
Rule |
zeroOrMore(Object rule,
Object rule2,
Object... moreRules)
Try and match a set of rules zero or more times
|
currentChar, currentIndex, drop, drop, dup, getContext, hasError, inPredicate, match, matchedChar, matchEnd, matchLength, matchOrDefault, matchRange, matchStart, peek, peek, poke, poke, pop, pop, position, push, push, setContext, swap, swapprotected static final Rule EOI
Please don't use this directly; use eof() instead.
protected static final Rule EMPTY
protected static final Rule NOTHING
public Rule eof()
@Cached @DontLabel public Rule ch(char c)
c - the character to match@Cached @DontLabel public Rule ignoreCase(char c)
c - the character to match@Cached @DontLabel public Rule unicodeChar(int codePoint)
codePoint - the code point@Cached @DontLabel public Rule unicodeRange(int low, int high)
Note that this method will delegate to "regular" character matchers if part of, or all of, the specified range is into the basic multilingual plane.
low - the lower code point (inclusive)high - the upper code point (inclusive)@Cached @DontLabel public Rule charRange(char cLow, char cHigh)
charscLow - the start char of the range (inclusively)cHigh - the end char of the range (inclusively)@DontLabel public Rule anyOf(String characters)
This method delegates to anyOf(Characters).
characters - the charactersanyOf(Characters)@DontLabel public Rule anyOf(char[] characters)
char array
This method delegates to anyOf(Characters).
characters - the charactersanyOf(Characters)@Cached @DontLabel public Rule anyOf(Characters characters)
Both anyOf(char[]) and anyOf(String) ultimately
delegate to this method, which caches its resuls.
characters - the characters@DontLabel public Rule noneOf(String characters)
characters - the characters@DontLabel public Rule noneOf(char[] characters)
char array
given as an argumentcharacters - the characters@DontLabel public Rule string(String string)
string - the string to match@Cached @DontLabel public Rule string(char... characters)
characters - the characters of the string to match@DontLabel public Rule ignoreCase(String string)
string - the string to match@Cached @DontLabel public Rule ignoreCase(char... characters)
characters - the characters of the string to match@Cached public Rule trie(Collection<String> strings)
Duplicate elements will be silently eliminated.
Note that order of elements does not matter, and that this rule will always trie (err, try) and match the longest possible sequence. That is, if you build a rule with inputs "do" and "double" in this order and the input text is "doubles", then "double" will be matched. However, if the input text is "doubling" then "do" is matched instead.
Note also that the minimum length of strings in a trie is 2.
strings - the list of strings for this trieTrieMatcher,
TrieNodepublic Rule trie(String first, String second, String... others)
This method delegates to trie(Collection).
first - the first stringsecond - the second stringothers - other stringsTrieMatcher,
TrieNode@DontLabel public Rule firstOf(Object rule, Object rule2, Object... moreRules)
When one rule matches, all others are ignored.
Note: if you are considering matching one string among many, consider
using trie(Collection)/trie(String, String, String...)
instead.
rule - the first subrulerule2 - the second subrulemoreRules - the other subrules@Cached @DontLabel public Rule firstOf(Object[] rules)
When one rule matches, all others are ignored.
rules - the subrules@Cached @DontLabel public Rule oneOrMore(Object rule)
rule - the subrule@DontLabel public Rule oneOrMore(Object rule, Object rule2, Object... moreRules)
rule - the first subrulerule2 - the second subrulemoreRules - the other subrules@Cached @DontLabel public Rule optional(Object rule)
This rule therefore always succeeds.
rule - the subrule@DontLabel public Rule optional(Object rule, Object rule2, Object... moreRules)
This rule will therefore never fail.
rule - the first subrulerule2 - the second subrulemoreRules - the other subrules@DontLabel public Rule sequence(Object rule, Object rule2, Object... moreRules)
rule - the first subrulerule2 - the second subrulemoreRules - the other subrules@Cached @DontLabel public Rule sequence(Object[] rules)
rules - the rulespublic final JoinMatcherBootstrap<V,BaseParser<V>> join(Object rule)
join rule
Usages:
return join(rule()).using(otherRule()).times(n);
return join(rule()).using(otherRule()).min(n);
etc. See JoinMatcherBuilder for more possible constructs.
rule - the joined rule (must not match an empty sequence!)JoinMatcherBootstrapJoinMatcherBootstrap.using(Object)@Cached @DontLabel public Rule test(Object rule)
Its success conditions are the same as the rule. Note that this rule will never consume any input, nor will it create a parse tree node.
Note that the embedded rule can be arbitrarily complex, and this
includes potential Actions which can act on the stack for
instance; these will be executed here, unless you have chosen to
annotate your rule, or parser class, with SkipActionsInPredicates.
rule - the subrule@DontLabel public Rule test(Object rule, Object rule2, Object... moreRules)
rule - the first subrulerule2 - the second subrulemoreRules - the other subrulestest(Object)@Cached @DontLabel public Rule testNot(Object rule)
The same warnings given in the description of test(Object)
apply here.
rule - the subrule@DontLabel public Rule testNot(Object rule, Object rule2, Object... moreRules)
rule - the first subrulerule2 - the second subrulemoreRules - the other subrulestest(Object),
testNot(Object)@Cached @DontLabel public Rule zeroOrMore(Object rule)
The rule will therefore always succeed.
rule - the subrule@DontLabel public Rule zeroOrMore(Object rule, Object rule2, Object... moreRules)
rule - the first subrulerule2 - the second subrulemoreRules - the other subrules@Cached @DontLabel public Rule nTimes(int repetitions, Object rule)
repetitions - The number of repetitions to match. Must be >= 0.rule - the sub rule to match repeatedly.public Rule alpha()
Therefore a-z, A-Z.
public Rule bit()
0 or 1public Rule asciiChars()
That is, 0x01 to 0x7f.
public Rule cr()
\r)public Rule crlf()
\r\npublic Rule ctl()
0x00-0x1f, plus 0x7f.
public Rule digit()
public Rule dquote()
"public Rule hexDigit()
Note: RFC 5234 only defines HEXDIG for uppercase
letters (A to F). Use hexDigitUpperCase() for
this definition. Use hexDigitLowerCase() for lowercase letters
only.
public Rule hexDigitUpperCase()
hexDigit()public Rule hexDigitLowerCase()
hexDigit()public Rule hTab()
\t)public Rule lf()
\n)public Rule octet()
public Rule sp()
public Rule vchar()
Letters, @, etc etc. Note that this excludes
whitespace characters!
public Rule wsp()
public static <T> Action<T> ACTION(boolean expression)
Action instance during parser construction.expression - the expression to turn into an Action@DontExtend protected Rule fromCharLiteral(char c)
c - the character@DontExtend protected Rule fromStringLiteral(String string)
string - the string@DontExtend protected Rule fromCharArray(char[] array)
array - the char array@DontExtend public Rule[] toRules(Object... objects)
objects - the objects to convert@DontExtend public Rule toRule(Object obj)
obj - the object to convert