Skip to content

Struct Lexer

Definition

Namespace: StardewUI.Framework.Grammar
Assembly: StardewUI.dll

Consumes raw StarML content as a token stream.

[System.Obsolete]
public ref struct Lexer

Inheritance
ObjectValueType ⇦ Lexer

Members

Constructors

Name Description
Lexer(ReadOnlySpan<Char>) Consumes raw StarML content as a token stream.

Properties

Name Description
Current The most recent token that was read, if the previous call to MoveNext() was successful; otherwise, an empty token.
Eof Whether the lexer is at the end of the content, either at the very end or with only trailing whitespace.
Position The current position in the markup text, i.e. the position at the end the Current token.

Methods

Name Description
Equals(Object) (Inherited from ValueType)
GetEnumerator() Returns a reference to this Lexer.
GetHashCode() (Inherited from ValueType)
MoveNext() Reads the next token into Current and advances the Position.
ReadOptionalToken(TokenType) Attempts to read the next token and, if successful, validates that it has a specific type.
ReadRequiredToken(TokenType) Reads the next token and validates that it has a specific type.
ToString() (Inherited from ValueType)

Details

Constructors

Lexer(ReadOnlySpan<Char>)

Consumes raw StarML content as a token stream.

public Lexer(ReadOnlySpan<System.Char> text);
Parameters

text   ReadOnlySpan<Char>
The markup text.


Properties

Current

The most recent token that was read, if the previous call to MoveNext() was successful; otherwise, an empty token.

public StardewUI.Framework.Grammar.Token Current { get; private set; }
Property Value

Token


Eof

Whether the lexer is at the end of the content, either at the very end or with only trailing whitespace.

public bool Eof { get; }
Property Value

Boolean


Position

The current position in the markup text, i.e. the position at the end the Current token.

public int Position { get; }
Property Value

Int32


Methods

GetEnumerator()

Returns a reference to this Lexer.

public StardewUI.Framework.Grammar.Lexer GetEnumerator();
Returns

Lexer

Remarks

Implementing this, along with Current and MoveNext(), allows it to be used in a foreach loop without having to implement IEnumerable<T>, which is not allowed on a ref struct.


MoveNext()

Reads the next token into Current and advances the Position.

public bool MoveNext();
Returns

Boolean

true if a token was read; false if the end of the content was reached.


ReadOptionalToken(TokenType)

Attempts to read the next token and, if successful, validates that it has a specific type.

public bool ReadOptionalToken(StardewUI.Framework.Grammar.TokenType expectedTypes);
Parameters

expectedTypes   TokenType
The TokenTypes allowed for the next token.

Returns

Boolean

true if a token was read and was one of the expectedTypes; false if the end of the content was reached.


ReadRequiredToken(TokenType)

Reads the next token and validates that it has a specific type.

public void ReadRequiredToken(StardewUI.Framework.Grammar.TokenType expectedTypes);
Parameters

expectedTypes   TokenType
The TokenTypes allowed for the next token.