public void ExportEnumValues(ProtoSpecEnumValueList list) { foreach (KeyValuePair <string, ProtoSpecEnumValue> pair in EnumValueDict) { list.Add(pair.Value); } }
public ProtoSpecModule(string name, string moduleId) { Name = name; ModuleId = moduleId; Actions = new ProtoSpecActionList(this); EnumValues = new ProtoSpecEnumValueList(); Classes = new ProtoSpecClassDefList(this); }
public ProtoSpecColumn(string name, ProtoSpecColumnType columnType, ProtoSpecEnumValueList values) { Name = name; ColumnType = columnType; Values = values; }
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); }
private ProtoSpecSubset ParseSpecSubset(ProtoSpecAction action) { if (CurrentToken.Type != ProtoSpecTokenType.LeftBrace) { Error("规格定义起始位置,缺少'{'"); } ProtoSpecSubset subset = new ProtoSpecSubset(action); while (true) { NextToken(); if (CurrentToken.Type != ProtoSpecTokenType.Identifier) { if (CurrentToken.Type != ProtoSpecTokenType.EndOfFile && CurrentToken.Type != ProtoSpecTokenType.RightBrace) { Error("缺少列名"); } break; } string name = CurrentToken.Text; NextToken(); if (CurrentToken.Type != ProtoSpecTokenType.Colon) { Error("列名之后缺少':'"); break; } NextToken(); if (IsColumnType(CurrentToken.Type) == false) { Error("缺少类型定义"); break; } ProtoSpecColumnType type = (ProtoSpecColumnType)CurrentToken.Type; ProtoSpecColumn column = null; if (CurrentToken.Type == ProtoSpecTokenType.List) { NextToken(); if (CurrentToken.Type == ProtoSpecTokenType.LeftAngular) { NextToken(); if (CurrentToken.Type != ProtoSpecTokenType.Identifier) { Error("列表类型缺少类型名"); break; } string part1 = CurrentToken.Text; string part2 = null; NextToken(); if (CurrentToken.Type == ProtoSpecTokenType.Dot) { NextToken(); if (CurrentToken.Type != ProtoSpecTokenType.Identifier) { Error("列表类型的模块名后缺少类型名"); break; } part2 = CurrentToken.Text; NextToken(); } if (CurrentToken.Type != ProtoSpecTokenType.RightAngular) { Error("列表类型后缺少闭合符号'>'"); break; } if (part2 == null) { column = new ProtoSpecColumn(name, type, part1); } else { column = new ProtoSpecColumn(name, type, part1, part2); } } else { ProtoSpecSubset format = ParseSpecSubset(action); column = new ProtoSpecColumn(name, type, format); } } else if (CurrentToken.Type == ProtoSpecTokenType.TypeOf) { NextToken(); if (CurrentToken.Type != ProtoSpecTokenType.LeftAngular) { Error("自定义类型前缺少起始符号'<'"); break; } NextToken(); if (CurrentToken.Type != ProtoSpecTokenType.Identifier) { Error("自定义类型的模块名后缺少类型名"); break; } string part1 = CurrentToken.Text; string part2 = null; NextToken(); if (CurrentToken.Type == ProtoSpecTokenType.Dot) { NextToken(); if (CurrentToken.Type != ProtoSpecTokenType.Identifier) { Error("自定义类型的模块名后缺少类型名"); break; } part2 = CurrentToken.Text; NextToken(); } if (CurrentToken.Type != ProtoSpecTokenType.RightAngular) { Error("自定义类型后缺少闭合符号'>'"); break; } if (part2 == null) { column = new ProtoSpecColumn(name, type, part1); } else { column = new ProtoSpecColumn(name, type, part1, part2); } } else if (CurrentToken.Type == ProtoSpecTokenType.Enum) { ProtoSpecEnumValueList values = ParseEnum(); column = new ProtoSpecColumn(name, type, values); } else { column = new ProtoSpecColumn(name, type); } subset.Columns.Add(column); } if (CurrentToken.Type != ProtoSpecTokenType.RightBrace) { Error("规格定义结束位置,缺少'}'"); } return(subset); }