Exemple #1
0
 private UssParser()
 {
     state         = ParsingState.Root;
     propertyState = PropertyParsingState.Key;
     valueState    = ValueParsingState.Key;
 }
Exemple #2
0
    private bool ParseProperties(UssToken token)
    {
        if (token.IsIgnoreable)
        {
            return(false);
        }

        if (propertyState == PropertyParsingState.Key &&
            token.type == UssTokenType.RightBracket)
        {
            state = ParsingState.Root;
            return(true);
        }

        if (propertyState == PropertyParsingState.Key)
        {
            if (token.type == UssTokenType.ValueRef)
            {
                bundles.Add(token.body.Substring(1));

                if (GetNextToken().type == UssTokenType.SemiColon)
                {
                    WasteNextToken();
                }
                else
                {
                    throw new UssUnexpectedTokenException(GetNextToken(), UssTokenType.SemiColon);
                }
            }
            else if (token.type == UssTokenType.Id)
            {
                propertyValues = new List <UssValue>();

                propertyKey   = token.body;
                propertyState = PropertyParsingState.Colon;
            }
            else
            {
                throw new InvalidOperationException("Invalid token `" + token.body + "`. (expected Id)");
            }
        }
        else if (propertyState == PropertyParsingState.Colon)
        {
            if (token.type != UssTokenType.Colon)
            {
                throw new InvalidOperationException("Invalid token `" + token.body + "`. (expected Colon)");
            }

            propertyState = PropertyParsingState.Value;
        }
        else
        {
            if (token.IsValue)
            {
                propertyValues.Add(UssValue.Create(token));
            }
            else if (token.type == UssTokenType.SemiColon)
            {
                properties.Add(new UssStyleProperty()
                {
                    key    = propertyKey,
                    values = propertyValues.ToArray()
                });

                propertyState = PropertyParsingState.Key;
            }
            else
            {
                throw new InvalidOperationException("Invalid token `" + token.body + "`. (expected Value)");
            }
        }

        return(false);
    }