namespace sys.core
class AsciiParser
Implements a basic parser operating on ASCII data. The data needs to be null ('\0') terminated.
this{ref const data: String};
this{ref const data: String, skipSpaces: Bool};
this{ref const data: Slice};
this{ref const data: Slice, skipSpaces: Bool};
Constructs a new parser based on an input buffer.
The buffer is not copied over so its lifespan must exceed the lifespan of the parser instance.
By default, upon creation, the parse will consume whitespaces, leaving its internal cursor on the first non-whitespace character. Use `skipSpaces = false` to supress this behavior.
data | the data to parse |
---|---|
skipSpaces | skip spaces option |
def EatSpaces(): Bool;
Attempts to consume whitespaces and comments.
If there was nothing to consume, the state of the parser is not changed.
true if anything was consumed
def EatSpacesNoLineSkip(): Bool;
Attempts to consume whitespaces but stops on a newline character.
If there was nothing to consume, the state of the parser is not changed.
true if anything was consumed
func IsId(): Bool;
func IsId(id: String): Bool;
Checks if the parser's current token is an identifier.
Identifiers use "C" rules.
id | the identifier to search for |
---|
`true` if the identifier was found
def EatId(id: String): Bool;
Attempts to consume a given identifier. If the identifier was not found, the state of the parser is not changed.
id | the identifier to search for |
---|
`true` if something was consumed
def ReadId(): String;
Attempt to read and consume an identifier.
Should be used ideally after `IsId`.
the read identifier
func Peek(): Char;
Peeks into the buffer and returns the next byte without changing the state of the parser.
the next byte
func IsChar(c: Char): Bool;
func IsChar(c1: Char, c2: Char): Bool;
func IsChar(c1: Char, c2: Char, c3: Char): Bool;
Checks if the next 1-3 bytes in the parser are the input ones.
Does not alter the state of the parser.
c | the first byte to check for |
---|---|
c1 | the first byte to check for |
c2 | the second byte to check for |
c3 | the third byte to check for |
`true` if the sequence is found.
def EatChar(c: Char): Bool;
def EatChar(c1: Char, c2: Char): Bool;
def EatChar(c1: Char, c2: Char, c3: Char): Bool;
Attempts to consume 1-3 input bytes.
c | the first byte to check for |
---|---|
c1 | the first byte to check for |
c2 | the second byte to check for |
c3 | the third byte to check for |
`true` if the bytes were found and consumed
func IsInt(): Bool;
Checks if the parser contains an integer, including sign.
`true` if integer was found
def EatSign(): Int;
Atempts to interpret the next character as a numeric sign and return the sign converted to an amount to multiply with.
If not sign or '+' is encountered, it returns '1'.
If '-' is found, it returns '-1'.
`1` or `-1` based on sign
func IsNumber(base: Int): Bool;
Returns true if the parser sees a number in a given base.
base | the base |
---|
`true` if integer is base `base` is found
def ReadInt(): Int;
Attempts to read and consume an integer in a base 10.
the integer value
def ReadNumber(base: Int): DWord;
Attempts to read and consume an number in a given base.
base | the base |
---|
the integer value
val SkipWhitespace;
If set to `true`, every time an entity is consumed, whitespace following said entity is also consumed.
If set to `false`, whitespace is not consumed and. It can manually be consumed with `EatSpaces`.
val SkipComments;
If set to true, every time whitespace is consumed, comments are also consumed.
val NestComments;
If set to true, every time comments are consumed, they can nest.