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
char s |
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 |
empty()
Match an empty string
|
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 |
JoinMatcherBootstrap<V,BaseParser<V>> |
join(Object rule,
Object rule2,
Object... moreRules)
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)
Deprecated.
use
repeat(Object) instead |
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 |
regex(String regex)
Match the input text using a Java regular expression
|
RepeatMatcherBuilder<V> |
repeat(Object rule)
Kickstart a repeat rule
|
RepeatMatcherBuilder<V> |
repeat(Object rule,
Object rule2,
Object... moreRules)
Kickstart a repeat rule
|
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 |
trieIgnoreCase(Collection<String> strings)
Match one string among many using a trie, case
insensitive version
|
Rule |
trieIgnoreCase(String first,
String second,
String... others)
Match one string among many using a trie, case
insensitive
|
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, peekAs, peekAs, poke, poke, pop, pop, popAs, popAs, position, push, push, setContext, swap, swap
protected static final Rule EOI
Please don't use this directly; use eof()
instead.
protected static final Rule EMPTY
protected static final Rule NOTHING
@DontExtend public Rule empty()
@DontExtend 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)
char
scLow
- 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 @DontLabel public Rule regex(String regex)
A few important considerations:
Matcher.lookingAt()
; it
means that the match will always be attempted at the current index in
the input;Pattern.compile(String)
, therefore
if you want case insensitive matches etc, you have to use the
appropriate regex modifiers in the regex itself (for instance, (?i)
for case insensitivity).regex
- the regexPattern
,
Matcher.lookingAt()
,
Matcher.end()
@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
,
TrieNode
public Rule trie(String first, String second, String... others)
This method delegates to trie(Collection)
.
first
- the first stringsecond
- the second stringothers
- other stringsTrieMatcher
,
TrieNode
@Cached public Rule trieIgnoreCase(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 trieCaseInsensitiveTrieMatcher
public Rule trieIgnoreCase(String first, String second, String... others)
This method delegates to trieIgnoreCase(Collection)
.
first
- the first stringsecond
- the second stringothers
- other stringsCaseInsensitiveTrieMatcher
@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@DontLabel public Rule oneOrMore(Object rule)
This is in fact an alias for repeat(rule).min(1)
.
rule
- the subrulerepeat(Object)
@DontLabel public Rule oneOrMore(Object rule, Object rule2, Object... moreRules)
This is in fact an alias for repeat(rule, rule2, ...).min(1)
.
rule
- the first subrulerule2
- the second subrulemoreRules
- the other subrulesrepeat(Object, Object, Object...)
@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 rules@DontLabel public 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!)JoinMatcherBootstrap
JoinMatcherBootstrap.using(Object)
@DontLabel public final JoinMatcherBootstrap<V,BaseParser<V>> join(Object rule, Object rule2, Object... moreRules)
join
rule
Like join(Object)
, except that several rules are accepted as
arguments.
rule
- first rulerule2
- second rulemoreRules
- other rulesJoinMatcherBootstrap
sequence(Object, Object, Object...)
@DontLabel public final RepeatMatcherBuilder<V> repeat(Object rule)
Usages:
return repeat("Yes we can!").times(3); return repeat(someRule).min(2); // etc
rule
- the rule to be repeated@DontLabel public final RepeatMatcherBuilder<V> repeat(Object rule, Object rule2, Object... moreRules)
Like repeat(Object)
, except several rules are accepted as
arguments.
rule
- first rulerule2
- second rulemoreRules
- other rulessequence(Object, Object, 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 Action
s 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)
@DontLabel public Rule zeroOrMore(Object rule)
This is an alias for repeat(rule).min(0)
.
rule
- the subrulerepeat(Object)
@DontLabel public Rule zeroOrMore(Object rule, Object rule2, Object... moreRules)
This is an alias for repeat(rule, rule2, ...).min(0)
.
rule
- the first subrulerule2
- the second subrulemoreRules
- the other subrules@Cached @DontLabel @Deprecated public Rule nTimes(int repetitions, Object rule)
repeat(Object)
insteadrepetitions
- 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 1
public Rule asciiChars()
That is, 0x01 to 0x7f.
public Rule cr()
\r
)public Rule crlf()
\r\n
public 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