IRule

Description

[ShutdownSurvive]
interface Tinman.Core.Parsing.IRule

Derived from

IEquatable<IRule>

Extended by

IGrammarRule
Rule abstract

Base interface for classes that represent parser rules that match zero or more input tokens.

Public / Methods

Add


[Pure]
public method Add → (2)

rule in : IRule

[not-null]
The rule to append.

reverse opt : bool = false

true to match rule in first and then this,
false to match this first and then rule in.

returns → IRule

The resulting rule.

Appends the given rule to this one.

Ast


[Pure]
public method Ast → (1)

tokenType in : string

[not-null]
The token type.

returns → IRule

The resulting rule.

Returns a rule that creates an AST node upon match.

Ast​If​Left


[Pure]
public method AstIfLeft → (2)

rule in : IRule

[not-null]
The other rule.

tokenType in : string

[not-empty]
The token type.

returns → IRule

The resulting rule.

Creates an AST node from this rule and the given one if this rule is matched.

Ast​If​Right


[Pure]
public method AstIfRight → (2)

rule in : IRule

[not-null]
The other rule.

tokenType in : string

[not-empty]
The token type.

returns → IRule

The resulting rule.

Creates an AST node from this rule and the given one if the latter rule is matched.

Can​Match


public method CanMatch → (2)

rule in : IGrammarRule

[not-null]
The grammar rule to check.

rules in : IBag<IGrammarRule>

[not-null]
Set of rules being processed. Used to avoid endless recursion.

returns → bool

true if rule in may be matched at the current parse position,
false if rule in will never be matched.

Checks if it is possible that this rule will try to match the given rule in at the current parse position.

Collect​Ast​Ids


public method CollectAstIds → (2)

rules in : IdGenerator<IRule>

[not-null]
The collected AST rules.

tokens in : IdGenerator<string>

[not-null]
The collected AST token types.

Collects AST rules and token types.

Collect​Referenced​Rules


public method CollectReferencedRules → (2)

rules in : ICollector<IGrammarRule>

[not-null]
The collector for referenced grammar rules.

collectThis opt : bool = true

true to collect this rule if it is a grammar rule, false to collect only descendant grammar rules.

Collects all IGrammarRules that are referenced by this rule or any of its descendants.

Count


[Pure]
public method Count → (1)

rules in : IBag<IRule>

[not-null]
Set of rules being processed. Used to avoid endless recursion.

returns → AstCount

The AST node count flags.

Determines the number of AST nodes this rule may produce.

Except


[Pure]
public method Except → (1)

exception in : IRule

[not-null]
The exception rule.

returns → IRule

The resulting rule.

Returns a rule that matches the input only if this rule matches but the given exception rule does not.

List


[Pure]
public method List → (1)

delimiter in : IRule

[not-null]
The delimiter rule.

returns → IRule

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.

Many


[Pure]
public method Many → (2)

minOccurs in : int32

[>=0]
Minimum number of allowed occurrences.

maxOccurs in : int32

[>=minOccurs]
Maximum number of allowed occurrences.

returns → IRule

The resulting rule.

Returns a rule that matches this rule n times, where n lies in the range [minOccurs..maxOccurs].

Match

2 overloads


public method Match1 → (2)

context in : ParserContext

[not-null]
The parser context object to use.

allowEmpty opt : bool = true

Allow the rule to match zero tokens?

returns → bool

true if the rule has successfully matched all input tokens, false if the rule could not be matched.

Tries to match the given input tokens.

When this method returns false, the state of the given parser context will have remained unchanged.


public method Match2 → (1)

in : char

The character token to match.

returns → bool

true if the rule has successfully matched the input token, false if the rule could not be matched.

Tries to match the given character.

This method is useful for matching single token rules.

Name


public method Name → (3)

name in : string

[not-empty]
The rule name.

flags opt : GrammarRuleFlags = GrammarRuleFlags.None

The grammar rule flags.

grammar opt : Grammar = null

The grammar object the rule belongs to or null,

returns → IGrammarRule

The resulting rule.

Creates a named grammar rule from this rule.

See also

Grammar.GetRule2

Not


[Pure]
public method Not → ()

returns → IRule

The resulting rule.

Returns a rule that matches an when this rule does not, and vice versa.

One​Or​More


[Pure]
public method OneOrMore → ()

returns → IRule

The resulting rule.

Returns a rule that matches this rule one or more times.

Or


[Pure]
public method Or → (2)

rule in : IRule

[not-null]
The rule.

reverse opt : bool = false

true to match rule in first and then this,
false to match this first and then rule in.

returns → IRule

The resulting rule.

Returns a rule that matches either this rule or the given one.

Peek


[Pure]
public method Peek → (1)

match in : bool

true to check if this rule does match the subsequent input,
false to check if this rule does not match the subsequent input.

returns → IRule

The resulting rule.

Returns a rule that check if this rule matches the subsequent input, without updating the parser context.

To​Grammar​Ast


[Pure]
public method ToGrammarAst → ()

returns → IRule

The AST grammar rule or null if this rule does not generate any AST nodes.

Transforms this rule into a AST grammar rule (according to RuleToSourceFlags.GrammarAst).

To​Source


public method ToSource → (3)

sb in : StringBuilder

[not-null]
The string builder to use.

flags in : RuleToSourceFlags

The format flags to use.

outer opt : RulePrecedence = ParsingUtil.PrecedenceMin

The outer rule precedence.

Returns the string representation of this rule.

The string representation will be wrapped in braces if necessary regarding to the outer rule precedence.

Trim


[Pure]
public method Trim → ()

returns → IRule

The resulting rule.

Returns a rule that skips all whitespaces before and after matching this rule.

Trim​Left


[Pure]
public method TrimLeft → ()

returns → IRule

The resulting rule.

Returns a rule that skips all whitespaces before matching this rule.

Trim​Right


[Pure]
public method TrimRight → ()

returns → IRule

The resulting rule.

Returns a rule that skips all whitespaces after matching this rule.

Zero​Or​More


[Pure]
public method ZeroOrMore → ()

returns → IRule

The resulting rule.

Returns a rule that matches this rule zero or more times.

Zero​Or​One


[Pure]
public method ZeroOrOne → ()

returns → IRule

The resulting rule.

Returns a rule that matches this rule zero times or one time.

Public / Attributes

Can​Match​Empty


public attribute CanMatchEmpty → (get)

value : bool

true if this rule can match empty input (see remarks),
false if this rule will never match empty input.

Can this rule match empty input?

This property will return true iff this rule may return true from Match1, without having incremented the current parse position (see ParserContext.Position), while not being at the end of input (see ParserContext.IsEof).

Is​Terminal


public attribute IsTerminal → (get)

value : bool

true if this rule is terminal, false if it is not.

Is this a terminal rule?

A terminal rule performs flat matching of the input characters, without any further rule recursion. This is not to be confused with RulePrecedence.Terminal, which indicates the precedence of rules in their grammar.

Precedence


public attribute Precedence → (get)

value : RulePrecedence

The rule precedence.

Returns the precedence of this rule.

Extensions

Replace​Unmatched​Chars


public static method ReplaceUnmatchedChars → (3)

value in : string

The string value.

replacement opt : char = '_'

The replacement character.

trim opt : bool = true

Trim leading and trailing replacement characters?

returns → string

The resulting string.

Replaces all sequences of unmatched characters in the given string value with the specified replacement character.

Each character of value in is matched individually using IRule.Match2.