Abstract base class for IRule implementations.
abstract class
|
Rule
|
implements
|
IRule
|
Is this a terminal rule?
public
virtual
property
|
IsTerminal
{
get
}
|
||
type
|
bool
|
||
value
|
true
if
this
rule
is
terminal,
false
if
it
is
not. |
||
implements
|
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.
public
virtual
property
|
MatchPrefix
{
get
}
|
||
type
|
string
|
||
value
|
The
simple
match
prefix
or
null . |
||
implements
|
IRule.MatchPrefix
|
Returns the precedence of this rule.
public
abstract
property
|
Precedence
{
get
}
|
||
type
|
RulePrecedence
|
||
value
|
The rule precedence. | ||
implements
|
IRule.Precedence
|
Combines
the
given
rules
with
Add
while
ignoring
null
values.
public
static
method
|
Add
(IRule first,
IRule second)
|
||
type
|
IRule
|
||
params
|
first
|
First
rule
or
null . |
|
second
|
Second
rule
or
null . |
||
returns
|
The
resulting
rule
or
null . |
Combines
the
given
rules
with
Or
while
ignoring
null
values.
public
static
method
|
Or
(IRule first,
IRule second)
|
||
type
|
IRule
|
||
params
|
first
|
First
rule
or
null . |
|
second
|
Second
rule
or
null . |
||
returns
|
The
resulting
rule
or
null . |
Appends the given rule to this one.
[Pure]
|
||||
public
virtual
method
|
Add
(IRule rule)
|
|||
type
|
IRule
|
|||
params
|
rule
|
[not-null]
|
The rule to append. | |
returns
|
|
The resulting rule. | ||
implements
|
IRule.Add
|
Returns a rule that creates an AST node upon match.
[Pure]
|
||||
public
virtual
method
|
Ast
(string tokenType)
|
|||
type
|
IRule
|
|||
params
|
tokenType
|
[not-null]
|
The token type. | |
returns
|
|
The resulting rule. | ||
implements
|
IRule.Ast
|
Creates an AST node from this rule and the given one if this rule is matched.
[Pure]
|
||||
public
virtual
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. | ||
implements
|
IRule.AstIfLeft
|
Creates an AST node from this rule and the given one if the latter rule is matched.
[Pure]
|
||||
public
virtual
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. | ||
implements
|
IRule.AstIfRight
|
Collects all IGrammarRule s that are referenced by this rule resp. any of its descendants.
public
virtual
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 .
|
||
implements
|
IRule.CollectReferencedRules
|
Determines the number of AST nodes this rule may produce.
[Pure]
|
||||
public
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. | |||
implements
|
IRule.Count
|
Returns a rule that matches the input only iff this rule matches but the given exception rule does not.
[Pure]
|
||||
public
method
|
Except
(IRule exception)
|
|||
type
|
IRule
|
|||
params
|
exception
|
[not-null]
|
The exception rule. | |
returns
|
|
The resulting rule. | ||
implements
|
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]
|
||||
public
method
|
List
(IRule delimiter)
|
|||
type
|
IRule
|
|||
params
|
delimiter
|
[not-null]
|
The delimiter rule. | |
returns
|
|
The resulting rule. | ||
implements
|
IRule.List
|
Returns
a
rule
that
matches
this
rule
n
times,
where
n
lies
in
the
range
[minOccurs..maxOccurs]
.
[Pure]
|
||||
public
virtual
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. | ||
implements
|
IRule.Many
|
Tries to match the given character.
public
virtual
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.
|
||
implements
|
IRule.Match
|
Remarks:
This method is useful for matching single token rules.
Tries to match the given input tokens.
public
virtual
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.
|
||
implements
|
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.
public
method
|
Name
(string name,
GrammarRuleFlags flags,
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. | |
implements
|
IRule.Name
|
See also:
Grammar.GetRuleReturns a an empty grammar rule that can be used by other rules.
public
static
method
|
NameProxy
(string name,
Grammar grammar = null)
|
||
type
|
IGrammarRuleProxy
|
||
params
|
name
|
[not-empty]
|
The grammar rule name. |
grammar
|
The
grammar
object
the
rule
belongs
to
or
null , |
||
returns
|
|
The rule. |
Remarks:
At some later point, the proxy must be set by calling SetProxyTarget.
See also:
Grammar.GetRuleReturns a rule that matches all characters except the given ones.
public
static
method
|
NoneOf
(string chars)
|
||
type
|
IRule
|
||
params
|
chars
|
[not-empty]
|
The characters. |
returns
|
|
The rule. |
Returns a rule that matches all characters except the given ones.
public
static
method
|
NoneOf
(IBagConst<char> chars)
|
||
type
|
IRule
|
||
params
|
chars
|
[not-empty]
|
The characters. |
returns
|
|
The rule. |
Returns a rule that matches an when this rule does not, and vice-versa.
[Pure]
|
||||
public
virtual
method
|
Not
()
|
|||
type
|
IRule
|
|||
returns
|
|
The resulting rule. | ||
implements
|
IRule.Not
|
Returns a rule that matches one of the given characters.
public
static
method
|
OneOf
(string chars)
|
||
type
|
IRule
|
||
params
|
chars
|
[not-empty]
|
The characters. |
returns
|
|
The rule. |
Returns a rule that matches one of the given characters.
public
static
method
|
OneOf
(IBagConst<char> chars)
|
||
type
|
IRule
|
||
params
|
chars
|
[not-empty]
|
The characters. |
returns
|
|
The rule. |
Returns a rule that matches this rule one or more times.
[Pure]
|
||||
public
virtual
method
|
OneOrMore
()
|
|||
type
|
IRule
|
|||
returns
|
|
The resulting rule. | ||
implements
|
IRule.OneOrMore
|
Returns a rule that matches either this rule or the given one.
[Pure]
|
||||
public
virtual
method
|
Or
(IRule rule)
|
|||
type
|
IRule
|
|||
params
|
rule
|
[not-null]
|
The rule. | |
returns
|
|
The resulting rule. | ||
implements
|
IRule.Or
|
Returns a rule that matches one character in the given range.
public
static
method
|
Range
(char from,
char to)
|
||
type
|
IRule
|
||
params
|
from
|
First character of range, inclusive. | |
to
|
[>=from]
|
Last character of range, inclusive. | |
returns
|
|
The rule. |
Returns a set that contains all the characters found in the given string.
public
static
method
|
ToCharSet
(string s,
IBag<char> chars)
|
||
type
|
IBag<char>
|
||
params
|
s
|
The input string. | |
chars
|
The
set
to
use
or
null . |
||
returns
|
The set of characters. |
Transforms this rule into a AST grammar rule (according to GrammarAst).
[Pure]
|
||||
public
virtual
method
|
ToGrammarAst
()
|
|||
type
|
IRule
|
|||
returns
|
The
AST
grammar
rule
or
null
if
this
rule
does
not
generate
any
AST
nodes.
|
|||
implements
|
IRule.ToGrammarAst
|
Returns a rule that matches the given character token.
public
static
method
|
Token
(char token)
|
||
type
|
IRule
|
||
params
|
token
|
The character token. | |
returns
|
|
The rule. |
Returns a rule that matches the given string token.
public
static
method
|
Token
(string token,
bool caseSensitive = true)
|
||
type
|
IRule
|
||
params
|
token
|
[not-empty]
|
The string token. |
caseSensitive
|
Perform
case-sensitive
match
for
the
token?
Defaults
to
true .
|
||
returns
|
|
The rule. |
Returns the string representation of this rule.
[Pure]
|
||||
public
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. | ||
implements
|
IRule.ToSource
|
Remarks:
The string representation will be wrapped in braces if necessary regarding to the outer rule precedence.
[Pure]
|
||||
public
override
method
|
ToString
()
|
|||
type
|
string
|
Returns a rule that skips all whitespaces before and after matching this rule.
[Pure]
|
||||
public
virtual
method
|
Trim
()
|
|||
type
|
IRule
|
|||
returns
|
|
The resulting rule. | ||
implements
|
IRule.Trim
|
Returns a rule that skips all whitespaces before matching this rule.
[Pure]
|
||||
public
virtual
method
|
TrimLeft
()
|
|||
type
|
IRule
|
|||
returns
|
|
The resulting rule. | ||
implements
|
IRule.TrimLeft
|
Returns a rule that skips all whitespaces after matching this rule.
[Pure]
|
||||
public
virtual
method
|
TrimRight
()
|
|||
type
|
IRule
|
|||
returns
|
|
The resulting rule. | ||
implements
|
IRule.TrimRight
|
Wraps the given rule in the specified start and end tags.
public
static
method
|
Wrap
(IRule rule,
char startEnd)
|
||
type
|
IRule
|
||
params
|
rule
|
[not-null]
|
The rule to wrap. |
startEnd
|
The start/end tag. | ||
returns
|
|
The rule. |
Wraps the given rule in the specified start and end tags.
public
static
method
|
Wrap
(IRule rule,
string startEnd)
|
||
type
|
IRule
|
||
params
|
rule
|
[not-null]
|
The rule to wrap. |
startEnd
|
[not-empty]
|
The start/end tag. | |
returns
|
|
The rule. |
Wraps the given rule in the specified start and end tags.
public
static
method
|
Wrap
(IRule rule,
IRule startEnd)
|
||
type
|
IRule
|
||
params
|
rule
|
[not-null]
|
The rule to wrap. |
startEnd
|
[not-null]
|
The start/end tag. | |
returns
|
|
The rule. |
Wraps the given rule in the specified start and end tags.
public
static
method
|
Wrap
(IRule rule,
char start,
char end)
|
||
type
|
IRule
|
||
params
|
rule
|
[not-null]
|
The rule to wrap. |
start
|
The start tag. | ||
end
|
The end tag. | ||
returns
|
|
The rule. |
Wraps the given rule in the specified start and end tags.
public
static
method
|
Wrap
(IRule rule,
string start,
string end)
|
||
type
|
IRule
|
||
params
|
rule
|
[not-null]
|
The rule to wrap. |
start
|
[not-empty]
|
The start tag. | |
end
|
[not-empty]
|
The end tag. | |
returns
|
|
The rule. |
Wraps the given rule in the specified start and end tags.
public
static
method
|
Wrap
(IRule rule,
IRule start,
IRule end)
|
||
type
|
IRule
|
||
params
|
rule
|
[not-null]
|
The rule to wrap. |
start
|
[not-null]
|
The start tag. | |
end
|
[not-null]
|
The end tag. | |
returns
|
|
The rule. |
Returns a rule that matches this rule zero or more times.
[Pure]
|
||||
public
virtual
method
|
ZeroOrMore
()
|
|||
type
|
IRule
|
|||
returns
|
|
The resulting rule. | ||
implements
|
IRule.ZeroOrMore
|
Returns a rule that matches this rule zero times or one time.
[Pure]
|
||||
public
virtual
method
|
ZeroOrOne
()
|
|||
type
|
IRule
|
|||
returns
|
|
The resulting rule. | ||
implements
|
IRule.ZeroOrOne
|
protected
constructor
|
Rule
()
|
protected
abstract
method
|
BeginMatch
(ParserContext context)
|
||
type
|
bool
|
||
params
|
context
|
protected
virtual
method
|
DoCount
(IBag<IRule> rules)
|
||
type
|
AstCount
|
||
params
|
rules
|
protected
virtual
method
|
EndMatch
(ParserContext context)
|
||
params
|
context
|
protected
abstract
method
|
ToSourceInternal
(StringBuilder sb,
RuleToSourceFlags flags,
RulePrecedence outer = RulePrecedence.Lowest)
|
||
params
|
sb
|
||
flags
|
|||
outer
|