Class Lexer
Lexicological parser, parses tokens out of a continuous piece of text. Ported from adm-utils: https://github.com/Admer456/adm-utils/blob/master/src/Text/Lexer.hpp
public class Lexer : ILexer
- Inheritance
-
Lexer
- Implements
- Inherited Members
Remarks
Right now it works with string, it may be worth investigating a ReadOnlySpan<T> version.
Constructors
Lexer(string, string)
public Lexer(string text, string delimiters = "()[]{}.:,;")
Parameters
Fields
DelimitersFull
public const string DelimitersFull = "()[]{}.:,;=+-*/&@'?!#%"
Field Value
DelimitersSimple
public const string DelimitersSimple = "()[]{}.:,;"
Field Value
Properties
IgnoreDelimiters
Whether or not to ignore delimiters while scanning for characters.
public bool IgnoreDelimiters { get; set; }
Property Value
Methods
Clear()
Clears the text buffer.
public void Clear()
Expect(string, bool)
Peeks at the next string and, optionally, advances seeking.
public bool Expect(string expectedToken, bool advanceIfTrue = false)
Parameters
expectedToken
stringThe token to expect.
advanceIfTrue
boolAdvance the seeking upon success? Behaves about the same as Next then.
Returns
- bool
true if the next token and expectedToken match.
ExpectAnythingUntilNewline()
Is there anything other than whitespaces until the newline?
public bool ExpectAnythingUntilNewline()
Returns
GetLineInfo()
Gets the current line and column, formatted in a string.
public string GetLineInfo()
Returns
GetLineNumber()
Gets the current line number.
public int GetLineNumber()
Returns
IsEnd()
Whether or not the end of the text has been reached.
public bool IsEnd()
Returns
Load(string)
Loads the given text
public void Load(string text)
Parameters
text
string
NewLine()
Skip the current line.
public void NewLine()
Next()
Continues parsing the string and extracts the next token from it.
public string Next()
Returns
- string
The next token in line, "" if EOF is reached.
ParsingException(string)
Throws an exception with the attached errorMessage
.
Includes line and column info.
public Exception ParsingException(string errorMessage)
Parameters
errorMessage
string
Returns
Peek()
Peeks at the next string.
public string Peek()
Returns
- string
The next token in line, "" if EOF is reached.
PeekUntil(string, bool, bool)
Returns all characters that were encountered between the current position
and what
. If skipPeeked
is true
,
the cursor will skip the result too.
public string PeekUntil(string what, bool skipPeeked = false, bool skipWhatToo = true)
Parameters
Returns
SetDelimiters(string)
Sets new delimiters.
public void SetDelimiters(string delimiters)
Parameters
delimiters
string
SkipUntil(string, bool)
Skips characters until a given string what
has been found.
If skipThatToo
is true
, it'll skip that string as well.
public void SkipUntil(string what, bool skipThatToo = false)
Parameters
TokenListBeforeNewline()
An array of tokens until the newline.
public IList<string> TokenListBeforeNewline()
Returns
TokensBeforeNewline()
Returns a string of tokens until the newline.
public string TokensBeforeNewline()