示例#1
0
    private void ParseValues(UssToken token)
    {
        if (token.IsIgnoreable)
        {
            return;
        }

        if (token.type == UssTokenType.SemiColon)
        {
            if (valueState != ValueParsingState.End)
            {
                throw new UssUnexpectedTokenException(token);
            }

            state = ParsingState.Root;
            return;
        }

        if (valueState == ValueParsingState.Key)
        {
            if (token.type != UssTokenType.ValueRef)
            {
                throw new UssUnexpectedTokenException(token, UssTokenType.ValueRef);
            }

            valueKey   = token.body.Substring(1);
            valueState = ValueParsingState.Colon;
        }
        else if (valueState == ValueParsingState.Colon)
        {
            if (token.type == UssTokenType.LeftBracket)
            {
                state    = ParsingState.Properties;
                nodeType = CurrentNodeType.Bundle;
            }
            else if (token.type == UssTokenType.Colon)
            {
                valueState = ValueParsingState.Value;
            }
            else
            {
                throw new UssUnexpectedTokenException(token);
            }
        }
        else if (valueState == ValueParsingState.Value)
        {
            if (token.IsValue == false)
            {
                throw new UssUnexpectedTokenException(token);
            }

            values.Add(valueKey, UssValue.Create(token));
            valueState = ValueParsingState.End;
        }
    }
示例#2
0
文件: UssParser.cs 项目: jwvg0425/uss
    public UssParsingResult ParseAll(UssToken[] _tokens)
    {
        tokens = new List <UssToken>(_tokens);
        styles = new List <UssStyleDefinition>();
        values = new Dictionary <string, UssValue>();

        FlushCurrentDifinition();
        for (cur = 0; cur < tokens.Count; cur++)
        {
            var token = tokens[cur];

            if (state == ParsingState.Root)
            {
                if (token.IsIgnoreable)
                {
                    continue;
                }

                if (token.type == UssTokenType.ValueRef)
                {
                    Debug.Log(token.body);
                    state      = ParsingState.Values;
                    valueState = ValueParsingState.Key;
                }
                else
                {
                    state = ParsingState.Conditions;
                }
            }

            if (state == ParsingState.Values)
            {
                ParseValues(token);
            }
            else if (state == ParsingState.Conditions)
            {
                ParseConditions(token);
            }
            else if (state == ParsingState.Properties)
            {
                if (ParseProperties(token))
                {
                    FlushCurrentDifinition();
                }
            }
        }

        return(new UssParsingResult()
        {
            styles = styles.ToArray(),
            values = values
        });
    }
示例#3
0
 private UssParser()
 {
     state         = ParsingState.Root;
     propertyState = PropertyParsingState.Key;
     valueState    = ValueParsingState.Key;
 }