class GUIStyleSheetLexer

Scans style sheet code and outputs token that can then by used by the parser to parse style sheet code.

Public

Constructors

GUIStyleSheetLexer

GUIStyleSheetLexer()

Methods

StartScanning

bool StartScanning(const SPtr<SourceCode> &sourceCode)

Starts scanning the provided code.

Calling this method starts (or restarts scanning). Returns true if the scanning started successfully.

ScanNextToken

TOptional<GUIStyleSheetToken> ScanNextToken(bool skipWhitespace = true)

Returns the current token and advances to the next token.

EndOfStream token will be returned once end of stream has been reached. Returns null if token scanning failed. Error that caused the failure can be read from GetErrors().

GetErrors

const String &GetErrors() const

Returns errors that occurred during scanning, if any.

Private

Methods

IsCurrentCharacterNewLine

bool IsCurrentCharacterNewLine() const

Checks is the current character a newline character.

IsCurrentCharacter

bool IsCurrentCharacter(char character) const

Checks is the current character the provided character.

GetCurrentCharacter

char GetCurrentCharacter() const

Returns the current character.

GetCurrentCharacterAndAdvance

char GetCurrentCharacterAndAdvance()

Returns the current character and advances to the next character.

GetCurrentCharacterAndAdvance

bool GetCurrentCharacterAndAdvance(char expected, char &outCharacter)

Reads the current character and compares it to the expected value.

If the value matches the character is output in , stream is advanced to the next character and the method returns true.

If the value does not match the expected character an error is logged and false is returned.

CreateToken

GUIStyleSheetToken CreateToken(const TokenType &type, bool takeCharacter = false)

Constructs a new token.

type
Type of the token to create.
takeCharacter
If true, the current character is consumed and the stream advanced. The token spelling will be the taken character.

Returns: Created token.

CreateToken

GUIStyleSheetToken CreateToken(const TokenType &type, String &spelling, bool takeCharacter = false)

Constructs a new token.

type
Type of the token to create.
spelling
Text that was scanned matching the token.
takeCharacter
If true, the current character is consumed and the stream advanced. The token spelling will be appended with the taken character.

Returns: Created token.

CreateToken

GUIStyleSheetToken CreateToken(const TokenType &type, String &spelling, const SourceCodePosition &sourceCodePosition, bool takeCharacter = false)

Constructs a new token.

type
Type of the token to create.
spelling
Text that was scanned matching the token.
sourceCodePosition
Explicit source code position at which the token is located.
takeCharacter
If true, the current character is consumed and the stream advanced. The token spelling will be appended with the taken character.

Returns: Created token.

SkipMatching

void SkipMatching(const Function<bool (char)> &predicate)

Advances the stream as long as the characters are matching the provided predicate (predicate returns true).

SkipWhiteSpaces

void SkipWhiteSpaces(bool includeNewLines = true)

Advances the stream until the current character is not a whitespace.

includeNewLines
If true, newline are counted as whitespace and will also be skipped.

SaveCurrentSourcePosition

void SaveCurrentSourcePosition()

Saves current source code position to be used for any following call using the source code position (e.g. error reporting).

ScanToken

TOptional<Token> ScanToken()

Tries to scan the next token and returns the token if scanning is successful.

Token type will be automatically determined based on the current character.

ScanElementSelectorOrHexColor

TOptional<Token> ScanElementSelectorOrHexColor()

Tries to scan the next token as an element selector identifier or a hex color (both starting with #).

Returns null if the scanning failed.

ScanIdentifier

TOptional<Token> ScanIdentifier(bool isStartingWithDot)

Tries to scan the next token as an identifier.

Returns null if the scanning failed.

ScanStringLiteral

TOptional<Token> ScanStringLiteral()

Tries to scan the next token as a string literal (text surrounded by "").

Returns null if the scanning failed.

ScanNumberOrClassSelector

TOptional<Token> ScanNumberOrClassSelector()

Tries to scan the next token as a number or a class selector.

Assumes the current token is a '.'. Returns null if the scanning failed.

ScanNumber

TOptional<Token> ScanNumber(bool isStartingWithDot)

Tries to scan the next token as a number.

Returns null if the scanning failed.

Error

TOptional<Token> Error(const String &message)

Records an error message and returns null.

ErrorUnexpected

TOptional<Token> ErrorUnexpected()

Records an error message that the current character is unexpected and returns null.

ErrorUnexpected

TOptional<Token> ErrorUnexpected(char expectedCharacter)

Records an error message that the current character doesn't match and returns null.

Fields

mSourceCode

SPtr<SourceCode> mSourceCode

mCurrentCharacter

char mCurrentCharacter

mCurrentPosition

SourceCodePosition mCurrentPosition

mErrors

String mErrors

mPropertyKeywords

UnorderedMap<String, TokenType> mPropertyKeywords