public ProtoSpecEnumValue SetEnumValue(string name, int value) { if (EnumValueDict.ContainsKey(name)) { Error("枚举值" + name + "重复定义"); } ProtoSpecEnumValue result = new ProtoSpecEnumValue(name, value); EnumValueDict.Add(name, result); return(result); }
public ProtoSpecEnumValue AllocEnumValue(string name) { if (EnumValueDict.ContainsKey(name)) { return(EnumValueDict[name]); } if (EnumValue > 255) { Error("枚举值自动增长超过了255"); } ProtoSpecEnumValue value = new ProtoSpecEnumValue(name, EnumValue); EnumValueDict.Add(name, value); EnumValue = EnumValue + 1; return(value); }
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); }