Automata Docs Automata Docs
Automata Docs Automata Docs

Search Results for

    Edit this page

    Struct AlangCursor

    Represents a cursor for parsing Alang regex strings.

    Inherited Members
    ValueType.Equals(object)
    ValueType.GetHashCode()
    object.Equals(object, object)
    object.GetType()
    object.ReferenceEquals(object, object)
    Namespace: Automata.Core.Alang
    Assembly: Automata.Core.dll
    Syntax
    public ref struct AlangCursor
    Remarks

    A cursor is a lightweight struct that consumes characters from the left of the input regexString as it is parsed. For performance, regexString is never split, copied or modified. Instead, the cursor maintains a lightweight span of the remaining regex string. Also, the parser in the Automata.Core.Alang namespace only needs to maintain a single cursor instance through the entire parse process. The contract of the AlangCursor is that it always points to a non-white-space character or EOI if the regex string is empty.

    Consequently:

    - All methods in AlangCursor that move the cursor must ensure on exit that leadingwhitespace is skipped.

    - All methods in AlangCursor can assume on entry that the cursor points to a non-whitespace character.

    This struct is also the sole point for throwing all types of parsing exceptions. These are handled by the methods prefixed by Should.

    Constructors

    | Edit this page View Source

    AlangCursor(string)

    Represents a cursor for parsing Alang regex strings.

    Declaration
    public AlangCursor(string regexString)
    Parameters
    Type Name Description
    string regexString

    The regex string to parse.

    Remarks

    A cursor is a lightweight struct that consumes characters from the left of the input regexString as it is parsed. For performance, regexString is never split, copied or modified. Instead, the cursor maintains a lightweight span of the remaining regex string. Also, the parser in the Automata.Core.Alang namespace only needs to maintain a single cursor instance through the entire parse process. The contract of the AlangCursor is that it always points to a non-white-space character or EOI if the regex string is empty.

    Consequently:

    - All methods in AlangCursor that move the cursor must ensure on exit that leadingwhitespace is skipped.

    - All methods in AlangCursor can assume on entry that the cursor points to a non-whitespace character.

    This struct is also the sole point for throwing all types of parsing exceptions. These are handled by the methods prefixed by Should.

    Properties

    | Edit this page View Source

    CursorIndex

    Current position of the cursor in the original input string.

    Declaration
    public readonly int CursorIndex { get; }
    Property Value
    Type Description
    int
    | Edit this page View Source

    IsEmpty

    Indicates whether the cursor has reached the end of the input.

    Declaration
    public readonly bool IsEmpty { get; }
    Property Value
    Type Description
    bool
    | Edit this page View Source

    IsExpressionStart

    Indicates whether the current character indicates the start of an expression. false if the input is empty.

    Declaration
    public readonly bool IsExpressionStart { get; }
    Property Value
    Type Description
    bool
    | Edit this page View Source

    NextAsString

    String representation of the next character in the input, or "End-Of-Input" if at the end of the input.

    Declaration
    public readonly string NextAsString { get; }
    Property Value
    Type Description
    string

    Methods

    | Edit this page View Source

    ConsumeSymbol()

    Consumes an Symbol from the input.

    Declaration
    public Symbol ConsumeSymbol()
    Returns
    Type Description
    Symbol

    The consumed Symbol.

    Remarks

    This method will return an empty (invalid) Symbol if no characters could be consumed. It is up to the calling code to handle this.

    | Edit this page View Source

    Is(char)

    Indicates whether the first character in the remaining input is the specified character.

    Declaration
    public readonly bool Is(char c)
    Parameters
    Type Name Description
    char c

    The character to check.

    Returns
    Type Description
    bool

    true iff the first character is the specified character.

    | Edit this page View Source

    IsNot(char)

    Indicates whether the first character in the remaining input is not the specified character.

    Declaration
    public readonly bool IsNot(char c)
    Parameters
    Type Name Description
    char c

    The character to check.

    Returns
    Type Description
    bool

    true iff the first character is NOT the specified character.

    | Edit this page View Source

    ShouldBeRightOperand(char)

    Validates that there is right operand after a binary operator.

    Declaration
    public readonly void ShouldBeRightOperand(char binaryOperator)
    Parameters
    Type Name Description
    char binaryOperator

    The preceding binary operator character. (Only used for better informed error messages if validation fails).

    Exceptions
    Type Condition
    AlangFormatException

    Thrown when the current character is not a right parenthesis ')'.

    | Edit this page View Source

    ShouldBeRightParen()

    Validates that the current character is a right parenthesis.

    Declaration
    public readonly void ShouldBeRightParen()
    Exceptions
    Type Condition
    AlangFormatException

    Thrown when the current character is not a right parenthesis ')'.

    | Edit this page View Source

    ShouldNotBeEmpty()

    Validates that the cursor is not at the end of input.

    Declaration
    public readonly void ShouldNotBeEmpty()
    Remarks

    This method enforces the rule that empty input is not valid in Alang expressions. To represent an empty set, use parentheses '()' instead.

    Exceptions
    Type Condition
    AlangFormatException

    Thrown when the cursor is at the end of input.

    | Edit this page View Source

    ShouldNotBeOperator()

    Validates that the current character is not an operator.

    Declaration
    public readonly void ShouldNotBeOperator()
    Remarks

    This method ensures expressions do not start with an operator.

    Exceptions
    Type Condition
    AlangFormatException

    Thrown when the current character is an operator.

    | Edit this page View Source

    ShouldNotBeRightParen()

    Validates that the current character is not a right parenthesis.

    Declaration
    public readonly void ShouldNotBeRightParen()
    Exceptions
    Type Condition
    AlangFormatException

    Thrown when the current character is a right parenthesis ')'.

    | Edit this page View Source

    ToString()

    String representation of the remaining input.

    Declaration
    public override readonly string ToString()
    Returns
    Type Description
    string

    A string that represents the remaining input.

    Overrides
    ValueType.ToString()
    | Edit this page View Source

    TryConsume(char)

    Tries to consume the specified character from the input and advances the cursor if successful.

    Declaration
    public bool TryConsume(char c)
    Parameters
    Type Name Description
    char c

    The character to attempt to consume.

    Returns
    Type Description
    bool

    true iff the character was successfully consumed.

    | Edit this page View Source

    TryConsumeAny(params char[])

    Tries to consume one of the specified characters from the input and advances the cursor if successful.

    Declaration
    public char TryConsumeAny(params char[] chars)
    Parameters
    Type Name Description
    char[] chars

    An array of characters to attempt to consume.

    Returns
    Type Description
    char

    The character that was consumed if successful; otherwise, Invalid.

    Remarks

    This method supports inclusion of EOI to also match against End-Of-Input.

    | Edit this page View Source

    TryConsumeBinaryOperator(char)

    Tries to consume a binary operator from the input and advances the cursor if successful.

    Declaration
    public bool TryConsumeBinaryOperator(char binaryOperator)
    Parameters
    Type Name Description
    char binaryOperator

    The binary operator character to attempt to consume.

    Returns
    Type Description
    bool

    true iff the binary operator was successfully consumed and the next character is a valid expression start.

    Exceptions
    Type Condition
    AlangFormatException

    Thrown when the binary operator was consumed but the next character was not IsExpressionStart .