Base interface for classes that represent parser rules that match zero or more input tokens.
interface
|
IRule
|
base of
|
IGrammarRule
|
||
Rule
|
Is this a terminal rule?
property
|
IsTerminal
{
get
}
|
||
type
|
bool
|
||
value
|
true
if
this
rule
is
terminal,
false
if
it
is
not. |
Remarks:
A terminal rule performs flat matching of the input characters, without any further rule recursion.
Returns the common prefix string that this rule always matches.
property
|
MatchPrefix
{
get
}
|
||
type
|
string
|
||
value
|
The
simple
match
prefix
or
null . |
Returns the precedence of this rule.
property
|
Precedence
{
get
}
|
||
type
|
RulePrecedence
|
||
value
|
The rule precedence. |
Appends the given rule to this one.
[Pure]
|
||||
method
|
Add
(IRule rule)
|
|||
type
|
IRule
|
|||
params
|
rule
|
[not-null]
|
The rule to append. | |
returns
|
|
The resulting rule. |
Returns a rule that creates an AST node upon match.
[Pure]
|
||||
method
|
Ast
(string tokenType)
|
|||
type
|
IRule
|
|||
params
|
tokenType
|
[not-null]
|
The token type. | |
returns
|
|
The resulting rule. |
Creates an AST node from this rule and the given one if this rule is matched.
[Pure]
|
||||
method
|
AstIfLeft
(IRule rule,
string tokenType)
|
|||
type
|
IRule
|
|||
params
|
rule
|
[not-null]
|
The other rule. | |
tokenType
|
[not-empty]
|
The token type. | ||
returns
|
|
The resulting rule. |
Creates an AST node from this rule and the given one if the latter rule is matched.
[Pure]
|
||||
method
|
AstIfRight
(IRule rule,
string tokenType)
|
|||
type
|
IRule
|
|||
params
|
rule
|
[not-null]
|
The other rule. | |
tokenType
|
[not-empty]
|
The token type. | ||
returns
|
|
The resulting rule. |
Collects all IGrammarRule s that are referenced by this rule resp. any of its descendants.
method
|
CollectReferencedRules
(ICollector<IRule> rules,
bool collectThis = true)
|
||
params
|
rules
|
[not-null]
|
The collector for referenced grammar rules. |
collectThis
|
true
to
collect
this
rule
if
it
is
a
grammar
rule,
false
to
collect
only
descendant
grammar
rules.
Defaults
to
true .
|
Determines the number of AST nodes this rule may produce.
[Pure]
|
||||
method
|
Count
(IBag<IRule> rules)
|
|||
type
|
AstCount
|
|||
params
|
rules
|
[not-null]
|
Set of rules being processed. Used to avoid left recursion. | |
returns
|
The AST node count flags. |
Returns a rule that matches the input only iff this rule matches but the given exception rule does not.
[Pure]
|
||||
method
|
Except
(IRule exception)
|
|||
type
|
IRule
|
|||
params
|
exception
|
[not-null]
|
The exception rule. | |
returns
|
|
The resulting rule. |
Returns a rule that matches a non-empty list of elements (matched by this rule) that are delimited by the given rule.
[Pure]
|
||||
method
|
List
(IRule delimiter)
|
|||
type
|
IRule
|
|||
params
|
delimiter
|
[not-null]
|
The delimiter rule. | |
returns
|
|
The resulting rule. |
Returns
a
rule
that
matches
this
rule
n
times,
where
n
lies
in
the
range
[minOccurs..maxOccurs]
.
[Pure]
|
||||
method
|
Many
(int32 minOccurs,
int32 maxOccurs)
|
|||
type
|
IRule
|
|||
params
|
minOccurs
|
[>=0]
|
Minimum number of allowed occurrences. | |
maxOccurs
|
[>=minOccurs]
|
Maximum number of allowed occurrences. | ||
returns
|
|
The resulting rule. |
Tries to match the given character.
method
|
Match
(char c)
|
||
type
|
bool
|
||
params
|
c
|
The character token to match. | |
returns
|
true
if
the
rule
has
successfully
matched
the
input
token,
false
if
the
rule
could
not
be
matched.
|
Remarks:
This method is useful for matching single token rules.
Tries to match the given input tokens.
method
|
Match
(ParserContext context,
bool allowEmpty = true)
|
||
type
|
bool
|
||
params
|
context
|
[not-null]
|
The parser context object to use. |
allowEmpty
|
Allow
the
rule
to
match
zero
tokens?
Defaults
to
true .
|
||
returns
|
true
if
the
rule
has
successfully
matched
all
input
tokens,
false
if
the
rule
could
not
be
matched.
|
Remarks:
When
this
method
returns
false
,
the
state
of
the
given
parser
context
will
have
remained
unchanged.
Creates a named grammar rule from this rule.
method
|
Name
(string name,
GrammarRuleFlags flags = GrammarRuleFlags.None,
Grammar grammar = null)
|
||
type
|
IGrammarRule
|
||
params
|
name
|
[not-empty]
|
The rule name. |
flags
|
The grammar rule flags. Defaults to None. | ||
grammar
|
The
grammar
object
the
rule
belongs
to
or
null , |
||
returns
|
|
The resulting rule. |
See also:
Grammar.GetRuleReturns a rule that matches an when this rule does not, and vice-versa.
[Pure]
|
||||
method
|
Not
()
|
|||
type
|
IRule
|
|||
returns
|
|
The resulting rule. |
Returns a rule that matches this rule one or more times.
[Pure]
|
||||
method
|
OneOrMore
()
|
|||
type
|
IRule
|
|||
returns
|
|
The resulting rule. |
Returns a rule that matches either this rule or the given one.
[Pure]
|
||||
method
|
Or
(IRule rule)
|
|||
type
|
IRule
|
|||
params
|
rule
|
[not-null]
|
The rule. | |
returns
|
|
The resulting rule. |
Transforms this rule into a AST grammar rule (according to GrammarAst).
[Pure]
|
||||
method
|
ToGrammarAst
()
|
|||
type
|
IRule
|
|||
returns
|
The
AST
grammar
rule
or
null
if
this
rule
does
not
generate
any
AST
nodes.
|
Returns the string representation of this rule.
[Pure]
|
||||
method
|
ToSource
(StringBuilder sb,
RuleToSourceFlags flags,
RulePrecedence outer = RulePrecedence.Lowest)
|
|||
params
|
sb
|
[not-null]
|
The string builder to use. | |
flags
|
The format flags to use. | |||
outer
|
The outer rule precedence. | |||
returns
|
|
The string representation. |
Remarks:
The string representation will be wrapped in braces if necessary regarding to the outer rule precedence.
Returns a rule that skips all whitespaces before and after matching this rule.
[Pure]
|
||||
method
|
Trim
()
|
|||
type
|
IRule
|
|||
returns
|
|
The resulting rule. |
Returns a rule that skips all whitespaces before matching this rule.
[Pure]
|
||||
method
|
TrimLeft
()
|
|||
type
|
IRule
|
|||
returns
|
|
The resulting rule. |
Returns a rule that skips all whitespaces after matching this rule.
[Pure]
|
||||
method
|
TrimRight
()
|
|||
type
|
IRule
|
|||
returns
|
|
The resulting rule. |
Returns a rule that matches this rule zero or more times.
[Pure]
|
||||
method
|
ZeroOrMore
()
|
|||
type
|
IRule
|
|||
returns
|
|
The resulting rule. |
Returns a rule that matches this rule zero times or one time.
[Pure]
|
||||
method
|
ZeroOrOne
()
|
|||
type
|
IRule
|
|||
returns
|
|
The resulting rule. |
Replaces all sequences of unmatched characters in the given string value with the specified replacement character.
method
|
ReplaceUmatchedChars
(string value,
char replacement = ''_'',
bool trim = true)
|
||
type
|
string
|
||
params
|
value
|
The string value. | |
replacement
|
The
replacement
character.
Defaults
to
'_' . |
||
trim
|
Trim leading and trailing replacement characters? | ||
returns
|
|
The resulting string. |
Remarks:
Each character of value is matched individually using Match.