Esempio n. 1
0
 public void ExportEnumValues(ProtoSpecEnumValueList list)
 {
     foreach (KeyValuePair <string, ProtoSpecEnumValue> pair in EnumValueDict)
     {
         list.Add(pair.Value);
     }
 }
Esempio n. 2
0
        private ProtoSpecEnumValueList ParseEnum()
        {
            NextToken();

            if (CurrentToken.Type != ProtoSpecTokenType.LeftBrace)
            {
                Error("枚举定义起始位置,缺少'{'");
            }

            ProtoSpecEnumValueList result = new ProtoSpecEnumValueList();

            NextToken();

            while (true)
            {
                if (CurrentToken.Type != ProtoSpecTokenType.Identifier)
                {
                    if (CurrentToken.Type != ProtoSpecTokenType.EndOfFile && CurrentToken.Type != ProtoSpecTokenType.RightBrace)
                    {
                        Error("枚举值缺少名称");
                    }

                    break;
                }

                string name = CurrentToken.Text;

                ProtoSpecEnumValue value = null;

                NextToken();

                if (CurrentToken.Type == ProtoSpecTokenType.Equal)
                {
                    NextToken();

                    if (CurrentToken.Type == ProtoSpecTokenType.Numeral)
                    {
                        value = SetEnumValue(name, int.Parse(CurrentToken.Text));

                        NextToken();
                    }
                    else
                    {
                        Error("枚举值必须是0 ~ 255之间的数值");
                    }
                }
                else
                {
                    value = AllocEnumValue(name);
                }

                result.Add(value);
            }

            if (CurrentToken.Type != ProtoSpecTokenType.RightBrace)
            {
                Error("枚举定义结束位置,缺少'}'");
            }

            return(result);
        }