In This Article

Symbol Class

Represents an abstract base class for a symbol within a grammar.

public abstract class Symbol : IGrammarNode, IKeyedObject
Inheritance:
System.Object Object
Derived:
NonTerminal Terminal
Implements:
IKeyedObject

Constructors

Symbol(String)

Initializes a new instance of the Symbol class.

protected Symbol(string key)
Parameter Type Description
key System.String

A string that identifies the symbol.

Properties

CanMatchCallback

Gets or sets the delegate that will be called when the non-terminal needs to determine at run-time whether it can parse.

public ParserCanMatchCallback CanMatchCallback { get; set; }

Property Value

ParserCanMatchCallback:

The delegate that will be called when the non-terminal needs to determine at run-time whether it can parse.

Remarks

Once the grammar has been compiled, the setter of this property will throw an exception if called.

ErrorAlias

Gets or sets the alias to use for this symbol when reporting errors.

public string ErrorAlias { get; set; }

Property Value

System.String:

The alias to use for this symbol when reporting errors.

Remarks

Terminals always report errors and use their Key if no error alias is specified. Non-terminals will only report errors if an error alias is specified.

Once the grammar has been compiled, the setter of this property will throw an exception if called.

IsCompiled

Gets whether the grammar and its elements are compiled, via a call to its Compile() method.

public bool IsCompiled { get; }

Property Value

System.Boolean:

true if the grammar and its elements are compiled; otherwise, false.

Key

Gets or sets the string that identifies the symbol.

public string Key { get; set; }

Property Value

System.String:

The string that identifies the symbol.

Remarks

Once the grammar has been compiled, the setter of this property will throw an exception if called.

SetLabel[String]

Wraps this symbol with a labeled EbnfSymbol.

public EbnfSymbol this[string label] { get; }
Parameter Type Description
label System.String

The string label to use.

Property Value

EbnfSymbol:

The EbnfSymbol that was created.

Remarks

This indexer is defined as shorthand syntax for calling the ToTerm(String) method.

Methods

CanMatch(IParserState)

Returns whether the symbol can start to match using callbacks or the current look-ahead token.

public bool CanMatch(IParserState state)
Parameter Type Description
state IParserState

An IParserState that provides information about the current parser state.

Returns

System.Boolean:

true if the symbol can start to match; otherwise, false.

OnComplete(ParserCallback)

Wraps this symbol with an EbnfSymbol and sets the delegate that will be called after the term is parsed, regardless of success or failure.

public EbnfQuantifiableTerm OnComplete(ParserCallback callback)
Parameter Type Description
callback ParserCallback

The delegate that will be called after the term is parsed.

Returns

EbnfQuantifiableTerm:

The EbnfTerm that wraps this symbol.

OneOrMore()

Wraps this symbol with an EbnfQuantifier such that one to many instances are permitted.

public EbnfQuantifier OneOrMore()

Returns

EbnfQuantifier:

The EbnfQuantifier term that wraps this symbol.

OnError(ParserErrorCallback)

Wraps this symbol with an EbnfSymbol and sets the delegate that will be called when an error occurs while parsing the term.

public EbnfQuantifiableTerm OnError(ParserErrorCallback callback)
Parameter Type Description
callback ParserErrorCallback

The delegate that will be called when an error occurs while parsing the term.

Returns

EbnfQuantifiableTerm:

The EbnfTerm that wraps this symbol.

OnErrorContinue()

Wraps this symbol with an EbnfSymbol and marks that if an error occurs while parsing the term, the error will be reported but parsing will continue on.

public EbnfQuantifiableTerm OnErrorContinue()

Returns

EbnfQuantifiableTerm:

The EbnfTerm that wraps this symbol.

OnErrorIgnore()

Wraps this symbol with an EbnfSymbol and marks that if an error occurs while parsing the term, no error will be reported and parsing will continue on.

public EbnfQuantifiableTerm OnErrorIgnore()

Returns

EbnfQuantifiableTerm:

The EbnfTerm that wraps this symbol.

OnErrorNoReport()

Wraps this symbol with an EbnfSymbol and marks that if an error occurs while parsing the term, no error will be reported and parsing will return a match failure.

public EbnfQuantifiableTerm OnErrorNoReport()

Returns

EbnfQuantifiableTerm:

The EbnfTerm that wraps this symbol.

OnInitialize(ParserCallback)

Wraps this symbol with an EbnfSymbol and sets the delegate that will be called before the term is parsed.

public EbnfQuantifiableTerm OnInitialize(ParserCallback callback)
Parameter Type Description
callback ParserCallback

The delegate that will be called before the term is parsed.

Returns

EbnfQuantifiableTerm:

The EbnfTerm that wraps this symbol.

OnSuccess(ParserCallback)

Wraps this symbol with an EbnfSymbol and sets the delegate that will be called when the term is successfully parsed.

public EbnfQuantifiableTerm OnSuccess(ParserCallback callback)
Parameter Type Description
callback ParserCallback

The delegate that will be called when the term is successfully parsed.

Returns

EbnfQuantifiableTerm:

The EbnfTerm that wraps this symbol.

Optional()

Wraps this symbol with an EbnfQuantifier such that zero or one instances are permitted.

public EbnfQuantifier Optional()

Returns

EbnfQuantifier:

The EbnfQuantifier term that wraps this symbol.

Range(Int32, Nullable<Int32>)

Wraps this symbol with an EbnfQuantifier such that a range of instances are permitted.

public EbnfQuantifier Range(int min, int? max)
Parameter Type Description
min System.Int32

The minimum number of instances.

max System.Nullable<System.Int32>

The maximum number of instances.

Returns

EbnfQuantifier:

The EbnfQuantifier term that wraps this symbol.

ToString()

Returns a String that represents the current Object.

public override string ToString()

Returns

System.String:

A String that represents the current Object.

ToTerm()

Wraps this symbol with an EbnfSymbol.

public EbnfSymbol ToTerm()

Returns

EbnfSymbol:

The EbnfSymbol that was created.

ToTerm(String)

Wraps this symbol with a labeled EbnfSymbol.

public abstract EbnfSymbol ToTerm(string label)
Parameter Type Description
label System.String

The string label to use.

Returns

EbnfSymbol:

The EbnfSymbol that was created.

ZeroOrMore()

Wraps this symbol with an EbnfQuantifier such that zero to many instances are permitted.

public EbnfQuantifier ZeroOrMore()

Returns

EbnfQuantifier:

The EbnfQuantifier term that wraps this symbol.

Operators

Addition(EbnfTerm, Symbol)

Implements a concatenation operator between EbnfTerm and Symbol.

public static EbnfConcatenation operator +(EbnfTerm left, Symbol right)
Parameter Type Description
left EbnfTerm

A EbnfTerm to compare.

right Symbol

A Symbol to compare.

Returns

EbnfConcatenation:

The EbnfConcatenation that was created.

Addition(Symbol, EbnfTerm)

Implements a concatenation operator between Symbol and EbnfTerm.

public static EbnfConcatenation operator +(Symbol left, EbnfTerm right)
Parameter Type Description
left Symbol

A Symbol to compare.

right EbnfTerm

A EbnfTerm to compare.

Returns

EbnfConcatenation:

The EbnfConcatenation that was created.

Addition(Symbol, Symbol)

Implements a concatenation operator between Symbol and Symbol.

public static EbnfConcatenation operator +(Symbol left, Symbol right)
Parameter Type Description
left Symbol

A Symbol to compare.

right Symbol

A Symbol to compare.

Returns

EbnfConcatenation:

The EbnfConcatenation that was created.

BitwiseOr(EbnfTerm, Symbol)

Implements an OR operator between EbnfTerm and Symbol.

public static EbnfAlternation operator |(EbnfTerm left, Symbol right)
Parameter Type Description
left EbnfTerm

A EbnfTerm to compare.

right Symbol

A Symbol to compare.

Returns

EbnfAlternation:

The EbnfAlternation that was created.

BitwiseOr(Symbol, EbnfTerm)

Implements an OR operator between Symbol and EbnfTerm.

public static EbnfAlternation operator |(Symbol left, EbnfTerm right)
Parameter Type Description
left Symbol

A Symbol to compare.

right EbnfTerm

A EbnfTerm to compare.

Returns

EbnfAlternation:

The EbnfAlternation that was created.

BitwiseOr(Symbol, Symbol)

Implements an OR operator between Symbol and Symbol.

public static EbnfAlternation operator |(Symbol left, Symbol right)
Parameter Type Description
left Symbol

A Symbol to compare.

right Symbol

A Symbol to compare.

Returns

EbnfAlternation:

The EbnfAlternation that was created.

GreaterThan(Symbol, ITreeConstructionNode)

Implements a greater-than operator between Symbol and ITreeConstructionNode.

public static EbnfProduction operator>(Symbol symbol, ITreeConstructionNode treeConstructor)
Parameter Type Description
symbol Symbol

A Symbol.

treeConstructor ITreeConstructionNode

A ITreeConstructionNode.

Returns

EbnfProduction:

The EbnfProduction that was created.

LessThan(Symbol, ITreeConstructionNode)

Implements a less-than operator between Symbol and ITreeConstructionNode.

public static EbnfProduction operator <(Symbol symbol, ITreeConstructionNode treeConstructor)
Parameter Type Description
symbol Symbol

A Symbol.

treeConstructor ITreeConstructionNode

A ITreeConstructionNode.

Returns

EbnfProduction:

The EbnfProduction that was created.

Inherited Members

  • System.Object.Equals(System.Object)
  • System.Object.Equals(System.Object, System.Object)
  • System.Object.ReferenceEquals(System.Object, System.Object)
  • System.Object.GetHashCode()
  • System.Object.GetType()
  • System.Object.MemberwiseClone()