class GUIStyleSheetParser

Parses a GUI style sheet source file and outputs a GUIStyleSheet.

Public

Constructors

GUIStyleSheetParser

GUIStyleSheetParser()

Methods

Parse

SPtr<GUIStyleSheet> Parse(const SPtr<SourceCode> &sourceCode)

Attempts to parse the provided style sheet file and outputs the parsed style sheet, if successful.

GetErrors

const String &GetErrors() const

Returns errors in case parsing failed.

GetWarnings

String GetWarnings() const

Returns any warnings generated during the parse process.

Private

Methods

TryParseIntegerLiteral

bool TryParseIntegerLiteral(i32 &outValue)

Attempts to parse the next token as an integer literal.

Integer literal is detected as a set of digits with no decimal point or suffix. If successful, returns true and outputs the parsed value.

TryParseIntegerLiteral

bool TryParseIntegerLiteral(u32 &outValue)

Attempts to parse the next token as an integer literal.

Integer literal is detected as a set of digits with no decimal point or suffix. If successful, returns true and outputs the parsed value.

TryParsePixelLiteral

bool TryParsePixelLiteral(i32 &outValue)

Attempts to parse the next token as a pixel literal.

Pixel literal is detected as a set of digits with no decimal point with 'px' suffix. If successful, returns true and outputs the parsed value.

TryParsePixelLiteral

bool TryParsePixelLiteral(u32 &outValue)

Attempts to parse the next token as a pixel literal.

Pixel literal is detected as a set of digits with no decimal point with 'px' suffix. If successful, returns true and outputs the parsed value.

TryParseDecimalLiteral

bool TryParseDecimalLiteral(float &outValue)

Attempts to parse the next token as a decimal literal.

Decimal literal is detected as a set of digits with an optional decimal point. If successful, returns true and outputs the parsed value.

TryParsePercentLiteral

bool TryParsePercentLiteral(float &outValue)

Attempts to parse the next token as a percent literal.

Percent literal is detected as a set of digits with an optional decimal point, with a '%' suffix. If successful, returns true and outputs the parsed value.

TryParseStringLiteral

bool TryParseStringLiteral(String &outValue)

Attempts to parse the next token as a string literal.

String literal is detected as a pair of '"', with an optional text in-between. If successful, returns true and outputs the parsed value.

TryParseElementSelector

bool TryParseElementSelector(String &outValue)

Attempts to parse the next token as an element selector.

If successful, returns true and outputs the parsed value.

TryParseNone

bool TryParseNone()

Attempts to parse the next token as 'none' token and returns true if successful.

TryParseColor

bool TryParseColor(Color &outValue)

Attempts to parse the next token (or set of tokens) as a color.

Can be a hex color (#FFFFFF, rgb(), hsl(), rgba() or hsla() construct). If successful, returns true and outputs the parsed value.

TryParseURL

bool TryParseURL(String &outValue)

Attempts to parse the next tokens as url("some-url").

If successful, returns true and outputs the parsed value.

TryParseIcon

bool TryParseIcon(String &outIconName, float &outIconSize)

Attempts to parse the next tokens as icon(icon-name, icon-size).

If successful, returns true and outputs the parsed value.

TryParseImage

bool TryParseImage(HSpriteImage &outValue)

Attempts to parse the next token as an image based on provided path or icon name.

If successful, returns true and outputs the parsed value.

TryParseFont

bool TryParseFont(HFont &outValue)

Attempts to parse the next token as an image loaded from the resource system based on provided font name.

If successful, returns true and outputs the parsed value.

TryParseRectOffset

bool TryParseRectOffset(RectOffset &outValue)

TryParseBorderStyle

bool TryParseBorderStyle(GUIBorderElementStyle &outValue)

Attempts to parse the next token as a border style.

Token must be one of supported border style identifiers. If successful, returns true and outputs the parsed value.

TryParseBorderStyle

bool TryParseBorderStyle(GUIBorderElementStyle &outTop, GUIBorderElementStyle &outRight, GUIBorderElementStyle &outBottom, GUIBorderElementStyle &outLeft)

TryParseBorderWidth

bool TryParseBorderWidth(u32 &outTop, u32 &outRight, u32 &outBottom, u32 &outLeft)

TryParseBorderColor

bool TryParseBorderColor(Color &outTop, Color &outRight, Color &outBottom, Color &outLeft)

TryParseTextAlign

bool TryParseTextAlign(GUIHorizontalTextAlignment &outValue)

Attempts to parse the next token as a text alignment style.

Token must be one of supported text alignment identifiers. If successful, returns true and outputs the parsed value.

TryParseVerticalAlign

bool TryParseVerticalAlign(GUIVerticalTextAlignment &outValue)

Attempts to parse the next token as a vertical alignment style.

Token must be one of supported vertical alignment identifiers. If successful, returns true and outputs the parsed value.

TryParseWordWrapMode

bool TryParseWordWrapMode(GUIWordWrapMode &outValue)

Attempts to parse the next token as a word wrap mode.

Token must be one of supported word wrap mode identifiers. If successful, returns true and outputs the parsed value.

TryParseVisibility

bool TryParseVisibility(GUIElementVisibility &outValue)

Attempts to parse the next token as a visibility mode.

Token must be one of supported visibility mode identifiers. If successful, returns true and outputs the parsed value.

TryParseBorderElement

bool TryParseBorderElement(GUIStyleSheetBorderElement &outValue)

Attempts to parse the next 1 to 3 tokens as style, width and color for the border.

Tokens may be provided in any order, but cannot be duplicated. If successful, returns true and outputs the parsed value.

TryParseBorderRadius

bool TryParseBorderRadius(u32 &outTopLeft, u32 &outTopRight, u32 &outBottomLeft, u32 &outBottomRight)

Attempts to parse the next set of 1 to 4 tokens as colors for each corner.

If successful, returns true and outputs the parsed values.

If one value is parsed, all corners are assigned the parsed value. If two values are parsed, first value is assigned to top-left/bottom-right and second value to bottom-left/top-right corners. If three values are parsed, first value is assigned to top-left, second value to bottom-left/top-right, and third value to bottom-right corner. If four values are parsed, first value is assigned to top-left, second value to top-right, third value to bottom-right, and fourth value to bottom-left corner.

TryParseAndLookupVariableValue

bool TryParseAndLookupVariableValue(ValueType expectedType, VariableValue &outValue)

Attempts to parse the variable value of the specified type.

Internally redirects to the correct parsing method depending on the value type.

expectedType
Variable type to parse.
outValue
Output value.

Returns: True if parsing is successful, false otherwise.

TryParseProperty

bool TryParseProperty(GUIStyleSheetRules &inOutValue)

Attempts to parse a property and its value.

If successful, returns true and writes the property data in the provided data structure.

TryParseVariable

bool TryParseVariable(VariableContext &inOutVariableContext)

Attempts to parse a variable declaration and its value.

If successful, returns true and appends (or overwrites) the variable in the provided context.

TryParseRuleset

bool TryParseRuleset()

Attempts to parse all properties and/or variable declarations in a particular ruleset.

If successful returns true and the rule information is added to the local ruleset array.

TryParseSelectorList

TOptional<GUIStyleSheetSelectorList> TryParseSelectorList()

Parses all selectors and generates a selector list, if any are provided.

TryParseAndLookupVariableValue

bool TryParseAndLookupVariableValue(ValueType expectedType, String &outValue)

TryParseAndLookupVariableValue

bool TryParseAndLookupVariableValue(ValueType expectedType, HSpriteImage &outValue)

TryParseAndLookupVariableValue

bool TryParseAndLookupVariableValue(ValueType expectedType, HFont &outValue)

TryParseInteger

bool TryParseInteger(const StringView &toParse, i32 &outValue) const

Attempts to parse an integer from the provided string.

Returns true if successful, and outputs the parsed integer.

TryParseFloat

bool TryParseFloat(const StringView &toParse, float &outValue) const

Attempts to parse a float from the provided string.

Returns true if successful, and outputs the parsed float.

TryParseHexColor

bool TryParseHexColor(const StringView &toParse, Color &outValue) const

Attempts to parse a color from the provided hex string (e. #FFFFFF or #FFFFFFAA).

Returns true if successful, and outputs the parsed color.

IsCurrentToken

bool IsCurrentToken(TokenType type) const

Returns true if the current token is of the specified type.

IsCurrentToken

bool IsCurrentToken(TokenType type, const String &spelling) const

Returns true if the current token is of the specified type and has the provided spelling.

GetCurrentTokenType

TokenType GetCurrentTokenType() const

Returns the type of the current token.

GetCurrentToken

TOptional<Token> GetCurrentToken() const

Returns the current token.

GetCurrentTokenAndAdvance

TOptional<Token> GetCurrentTokenAndAdvance(bool skipWhitespace = true)

Returns the current token and advances to the next token.

GetCurrentTokenAndAdvance

TOptional<Token> GetCurrentTokenAndAdvance(TokenType expectedType)

Returns the current token if it matches the provided type, and advances to the next token.

If the type is not matching and error is logged and null is returned.

GetCurrentTokenAndAdvance

TOptional<Token> GetCurrentTokenAndAdvance(TokenType expectedType, const String &spelling)

Returns the current token if it matches the provided type and spelling, and advances to the next token.

If the type or spelling is not matching and error is logged and null is returned.

SkipToken

void SkipToken(TokenType type)

Skips the current token if it matches the provided type.

Warning

void Warning(const String &message)

Records a warning message.

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 token is unexpected and returns null.

ErrorUnexpected

TOptional<Token> ErrorUnexpected(TokenType expectedTokenType)

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

ErrorUnexpected

TOptional<Token> ErrorUnexpected(const String &expectedTokenSpelling)

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

staticValueTypeToString

static const char *ValueTypeToString(ValueType type)

Converts property value type into a human readable string.

staticCanCastValue

static bool CanCastValue(ValueType expectedType, ValueType receivedType)

Returns true if the values of the provided types can be cast between each other safely.

Fields

mSourceCode

SPtr<SourceCode> mSourceCode

mLexer

mCurrentToken

TOptional<Token> mCurrentToken

mParsedRulesets

TArray<GUIStyleSheetRuleset> mParsedRulesets

mGlobalVariableContext

VariableContext mGlobalVariableContext

mLocalVariableContext

VariableContext mLocalVariableContext

mStringLiterals

Vector<String> mStringLiterals

mErrors

String mErrors

mWarnings

StringStream mWarnings

mPropertyKeywords

UnorderedMap<String, PropertyInformation> mPropertyKeywords