Beispiel #1
0
 private static void LoadAttributes(StructLexer lexer, List <Attribute> attrs)
 {
     if (lexer.PeekNextToken() == StructTokenType.OpenSquare)
     {
         lexer.GetNextToken(StructTokenType.OpenSquare);
         while (true)
         {
             TextPosition pos      = lexer.CurrentPosition;
             string       attrName = lexer.GetNextToken(StructTokenType.String);
             string       attrValue;
             if (lexer.CheckNextToken(StructTokenType.Equals))
             {
                 attrValue = lexer.GetAttributeValue(out pos);
             }
             else
             {
                 attrValue = "1";
             }
             attrs.Add(new Attribute(attrName, attrValue, pos));
             if (lexer.CheckNextToken(StructTokenType.CloseSquare))
             {
                 break;
             }
             if (!lexer.CheckNextToken(StructTokenType.Comma))
             {
                 throw new Exception("Unexpected token");
             }
         }
     }
 }
Beispiel #2
0
        private void LoadEnum(StructLexer lexer, List <Attribute> attrs)
        {
            string  name    = lexer.GetNextToken(StructTokenType.String);
            EnumDef enumDef = new EnumDef(_curStructFile, name);

            LoadAttributes(lexer, attrs);

            foreach (Attribute attr in attrs)
            {
                enumDef.SetAttribute(attr.Key, attr.Value);
            }

            lexer.GetNextToken(StructTokenType.OpenCurly);
            uint lastValue = UInt32.MaxValue;

            while (!lexer.CheckNextToken(StructTokenType.CloseCurly))
            {
                string constName = lexer.GetNextToken(StructTokenType.String);
                if (lexer.CheckNextToken(StructTokenType.Equals))
                {
                    string constValue = lexer.GetNextToken(StructTokenType.String);
                    lastValue = (uint)ExpressionParser.Parse(constValue).EvaluateInt(null);
                }
                else
                {
                    lastValue++;
                }
                enumDef.AddValue(constName, lastValue);

                if (!lexer.CheckNextToken(StructTokenType.Comma))
                {
                    if (lexer.PeekNextToken() != StructTokenType.CloseCurly)
                    {
                        throw new Exception("Unexpected token in enum: " + lexer.PeekNextToken());
                    }
                }
            }
            _curStructFile.Add(enumDef);
        }