TINMAN 3D / REALTIME TERRAIN
Software Development Kit - User Manual

class Rule in Tinman.Core.Parsing

Abstract base class for IRule implementations.

abstract class Rule implements IRule

Public / Attributes

IsTerminal

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.

MatchPrefix

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

Precedence

Returns the precedence of this rule.

public abstract property Precedence { get }
type RulePrecedence
value The rule precedence.
implements IRule.Precedence

Public / Constructors

Add

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.

Or

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.

Public / Methods

Add

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 [not-null] The resulting rule.
implements IRule.Add

Ast

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 [not-null] The resulting rule.
implements IRule.Ast

AstIfLeft

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 [not-null] The resulting rule.
implements IRule.AstIfLeft

AstIfRight

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 [not-null] The resulting rule.
implements IRule.AstIfRight

CollectReferencedRules

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

Count

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

Except

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 [not-null] The resulting rule.
implements IRule.Except

List

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 [not-null] The resulting rule.
implements IRule.List

Many

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 [not-null] The resulting rule.
implements IRule.Many

Match

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.

Name

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 [not-null] The resulting rule.
implements IRule.Name

See also:

Grammar.GetRule

NameProxy

Returns 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 [not-null] The rule.

Remarks:

At some later point, the proxy must be set by calling SetProxyTarget.

See also:

Grammar.GetRule

NoneOf

Returns 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 [not-null] 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 [not-null] The rule.

Not

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

[Pure]
public virtual method Not ()
type IRule
returns [not-null] The resulting rule.
implements IRule.Not

OneOf

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 [not-null] 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 [not-null] The rule.

OneOrMore

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

[Pure]
public virtual method OneOrMore ()
type IRule
returns [not-null] The resulting rule.
implements IRule.OneOrMore

Or

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 [not-null] The resulting rule.
implements IRule.Or

Range

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 [not-null] The rule.

ToCharSet

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.

ToGrammarAst

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

Token

Returns a rule that matches the given character token.

public static method Token (char token)
type IRule
params token The character token.
returns [not-null] 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 [not-null] The rule.

ToSource

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 [not-null] The string representation.
implements IRule.ToSource

Remarks:

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

ToString

[Pure]
public override method ToString ()
type string

Trim

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

[Pure]
public virtual method Trim ()
type IRule
returns [not-null] The resulting rule.
implements IRule.Trim

TrimLeft

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

[Pure]
public virtual method TrimLeft ()
type IRule
returns [not-null] The resulting rule.
implements IRule.TrimLeft

TrimRight

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

[Pure]
public virtual method TrimRight ()
type IRule
returns [not-null] The resulting rule.
implements IRule.TrimRight

Wrap

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 [not-null] 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 [not-null] 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 [not-null] 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 [not-null] 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 [not-null] 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 [not-null] The rule.

ZeroOrMore

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

[Pure]
public virtual method ZeroOrMore ()
type IRule
returns [not-null] The resulting rule.
implements IRule.ZeroOrMore

ZeroOrOne

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

[Pure]
public virtual method ZeroOrOne ()
type IRule
returns [not-null] The resulting rule.
implements IRule.ZeroOrOne

Protected / Constructors

Rule

protected constructor Rule ()

Protected / Methods

BeginMatch

protected abstract method BeginMatch (ParserContext context)
type bool
params context

DoCount

protected virtual method DoCount (IBag<IRule> rules)
type AstCount
params rules

EndMatch

protected virtual method EndMatch (ParserContext context)
params context

ToSourceInternal

protected abstract method ToSourceInternal (StringBuilder sb, RuleToSourceFlags flags, RulePrecedence outer = RulePrecedence.Lowest)
params sb
  flags
  outer