Class AlangRegex
Represents an expression in the Alang
(Automata language) used for defining finite-state automata.
AlangRegex has a one-to-one correspondence with Finite State Automata.
Inherited Members
Namespace: Automata.Core.Alang
Assembly: Automata.Core.dll
Syntax
public abstract class AlangRegex
Remarks
The Alang
language is a domain-specific language designed for defining and working with finite-state automata.
This class serves as the starting point for parsing Alang
expressions with Parse(string).
For more information about the Alang
language, see the Alang Grammar Specification.
Constructors
| Edit this page View SourceAlangRegex()
Initializes a new instance of the AlangRegex class.
Declaration
protected AlangRegex()
Properties
| Edit this page View SourceAlangExpressionString
String representation of this expression in valid Alang language syntax.
Declaration
public abstract string AlangExpressionString { get; }
Property Value
Type | Description |
---|---|
string | A string representing the expression in Alang syntax. |
IsEmptyString
Indicates whether this expression is an empty string. An empty string is not a valid expression in Alang. Used internally by the Parser to handle empty strings.
Declaration
public bool IsEmptyString { get; }
Property Value
Type | Description |
---|---|
bool | true
|
Precedence
Precedence level of this expression according to the Alang grammar specification.
Declaration
public abstract int Precedence { get; }
Property Value
Type | Description |
---|---|
int | An integer representing the precedence level of the expression. |
Methods
| Edit this page View SourceCompile()
Compiles this AlangRegex into an automaton. A new Alphabet for the automaton is created containing all referenced symbols.
Declaration
public Mfa Compile()
Returns
Type | Description |
---|---|
Mfa | An Mfa representing the compiled finite state automaton. |
Remarks
This method creates a new Alphabet.
When possible, consider using a shared single alphabet for multiple automata, for added performance.
Compile(Alphabet)
Compiles this AlangRegex into an automaton using the specified alphabet
.
Declaration
public Mfa Compile(Alphabet alphabet)
Parameters
Type | Name | Description |
---|---|---|
Alphabet | alphabet | The alphabet to use for compilation. |
Returns
Type | Description |
---|---|
Mfa | An Mfa representing the compiled finite state automaton. |
Remarks
The alphabet is extended with any symbols not currently in it.
Compile(string)
Compiles the specified regex string directly into a finite-state automaton. A new Alphabet for the automaton is created, containing all symbols in the regex string.
Declaration
public static Mfa Compile(string regexString)
Parameters
Type | Name | Description |
---|---|---|
string | regexString | A regex string on Alang format. |
Returns
Type | Description |
---|---|
Mfa | An Mfa representing the compiled automaton. |
Remarks
When possible, consider using a shared single alphabet for multiple automata, for added performance.
Exceptions
Type | Condition |
---|---|
AlangFormatException | Thrown when the regex string is in invalid format. |
Compile(string, params string[])
Compiles the specified regex string directly into a finite-state automaton. A new Alphabet for the automaton is created, containing all symbols in the regex string and the specified additional symbols.
Declaration
public static Mfa Compile(string regexString, params string[] addSymbols)
Parameters
Type | Name | Description |
---|---|---|
string | regexString | A regex string on Alang format. |
string[] | addSymbols | Additional symbols to include in the alphabet. |
Returns
Type | Description |
---|---|
Mfa | An Mfa representing the compiled automaton. |
Remarks
All alphabet symbols will be included in generic constructs, such as '.
' (Wildcard) and '~
' (Complement)
When possible, consider using a shared single alphabet for multiple automata, for added performance.
Exceptions
Type | Condition |
---|---|
AlangFormatException | Thrown when the regex string is in invalid format. |
Compile(params string[])
Compiles this AlangRegex into an automaton. A new Alphabet for the automaton is created, containing all referenced symbols and the specified additional symbols.
Declaration
public Mfa Compile(params string[] addSymbols)
Parameters
Type | Name | Description |
---|---|---|
string[] | addSymbols | Additional symbols to include in the alphabet. |
Returns
Type | Description |
---|---|
Mfa | An Mfa representing the compiled finite state automaton. |
Remarks
All alphabet symbols will be included in generic constructs, such as '.
' (Wildcard) and '~
' (Complement)
When possible, consider using a shared single alphabet for multiple automata, for added performance.
DescendantsAndSelf()
Returns this expression and all its descendant expressions in a depth-first order.
Declaration
public IEnumerable<AlangRegex> DescendantsAndSelf()
Returns
Type | Description |
---|---|
IEnumerable<AlangRegex> | An IEnumerable<T> of AlangRegex representing this expression and all its descendants. |
Param(AlangRegex, AlangRegex)
Returns the string of the given expression, enclosed in parentheses only if necessary based on operator precedence.
Declaration
protected static string Param(AlangRegex expr, AlangRegex parent)
Parameters
Type | Name | Description |
---|---|---|
AlangRegex | expr | The expression to get the string representation of. |
AlangRegex | parent | The parent expression of |
Returns
Type | Description |
---|---|
string | The expression string, potentially enclosed in parentheses. |
Remarks
Parentheses are added if the precedence of the given expression is lower than the precedence of the parent.
Parse(string)
Parses the specified regex string into an AlangRegex.
Declaration
public static AlangRegex Parse(string regexString)
Parameters
Type | Name | Description |
---|---|---|
string | regexString | A regex string on Alang format. |
Returns
Type | Description |
---|---|
AlangRegex | An AlangRegex representing the parsed expression. |
Exceptions
Type | Condition |
---|---|
AlangFormatException | Thrown when the regex string is in invalid format. |
ToString()
String that represents the current expression in Alang format.
Declaration
public override string ToString()
Returns
Type | Description |
---|---|
string | The expression string of this expression in Alang format. |