interface
|
IGrammarRule
|
extends
|
IRule
|
||
base of
|
IGrammarRuleProxy
|
The grammar rule flags.
property
|
Flags
{
get
}
|
||
type
|
GrammarRuleFlags
|
||
value
|
The rule flags. |
The Grammar object that has defined this rule.
property
|
Grammar
{
get
}
|
||
type
|
Grammar
|
||
value
|
|
The grammar. |
Is this a terminal rule?
property
|
IsTerminal
{
get
}
|
||
type
|
bool
|
||
value
|
true
if
this
rule
is
terminal,
false
if
it
is
not. |
||
inherited
|
IRule.IsTerminal
|
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 . |
||
inherited
|
IRule.MatchPrefix
|
Returns the precedence of this rule.
property
|
Precedence
{
get
}
|
||
type
|
RulePrecedence
|
||
value
|
The rule precedence. | ||
inherited
|
IRule.Precedence
|
The body of this grammar rule.
property
|
Rule
{
get
}
|
||
type
|
IRule
|
||
value
|
The body rule. |
The name of this rule.
property
|
RuleName
{
get
}
|
||
type
|
string
|
||
value
|
|
The rule name. |
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. | ||
inherited
|
IRule.Add
|
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. | ||
inherited
|
IRule.Ast
|
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. | ||
inherited
|
IRule.AstIfLeft
|
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. | ||
inherited
|
IRule.AstIfRight
|
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 .
|
||
inherited
|
IRule.CollectReferencedRules
|
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. | |||
inherited
|
IRule.Count
|
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. | ||
inherited
|
IRule.Except
|
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. | ||
inherited
|
IRule.List
|
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. | ||
inherited
|
IRule.Many
|
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.
|
||
inherited
|
IRule.Match
|
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.
|
||
inherited
|
IRule.Match
|
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. | |
inherited
|
IRule.Name
|
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. | ||
inherited
|
IRule.Not
|
Returns a rule that matches this rule one or more times.
[Pure]
|
||||
method
|
OneOrMore
()
|
|||
type
|
IRule
|
|||
returns
|
|
The resulting rule. | ||
inherited
|
IRule.OneOrMore
|
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. | ||
inherited
|
IRule.Or
|
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.
|
|||
inherited
|
IRule.ToGrammarAst
|
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. | ||
inherited
|
IRule.ToSource
|
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. | ||
inherited
|
IRule.Trim
|
Returns a rule that skips all whitespaces before matching this rule.
[Pure]
|
||||
method
|
TrimLeft
()
|
|||
type
|
IRule
|
|||
returns
|
|
The resulting rule. | ||
inherited
|
IRule.TrimLeft
|
Returns a rule that skips all whitespaces after matching this rule.
[Pure]
|
||||
method
|
TrimRight
()
|
|||
type
|
IRule
|
|||
returns
|
|
The resulting rule. | ||
inherited
|
IRule.TrimRight
|
Returns a rule that matches this rule zero or more times.
[Pure]
|
||||
method
|
ZeroOrMore
()
|
|||
type
|
IRule
|
|||
returns
|
|
The resulting rule. | ||
inherited
|
IRule.ZeroOrMore
|
Returns a rule that matches this rule zero times or one time.
[Pure]
|
||||
method
|
ZeroOrOne
()
|
|||
type
|
IRule
|
|||
returns
|
|
The resulting rule. | ||
inherited
|
IRule.ZeroOrOne
|
Is this grammar rule redundant, i.e. it only refers to another grammar rule?
method
|
IsRedundant
()
|
||
type
|
bool
|
||
returns
|
true
if
this
grammar
rule
is
redundant
(in
this
case,
Rule
will
always
be
an
IGrammarRule),
false
if
it
is
not.
|
Parses the given input data with this rule.
method
|
Parse
(ICodeInput input)
|
||
type
|
ParseResult
|
||
params
|
input
|
[not-null]
|
The input data. |
returns
|
|
The parser result object. |
Parses the given input data with this rule and returns the resulting abstract syntax tree.
method
|
ParseAst
(ICodeInput input)
|
||
type
|
AstNode
|
||
params
|
input
|
[not-null]
|
The input data. |
returns
|
|
The parsed AST node. |