这个问题与Irony项目的C#语法示例有关。
原始语法位于此处:CSharpGrammar.cs。
这是我修改后的C#语法,但应将[attribute]非终结符从[全局属性]更改为[attributes],而无需命名空间。
怎么办?
this.Root = compilation_unit;
compilation_unit.Rule = extern_alias_directives_opt
+ using_directives_opt
+ global_attributes_opt
+ namespace_member_declarations;
var global_attribute_target = new NonTerminal("global_attribute_target");
global_attribute_target.Rule = ToTerm("field") | "event" | "method" | "param" | "property" | "return" | "type";
global_attributes_opt.Rule = MakeStarRule(global_attributes_opt, null, global_attribute_section);
global_attribute_section.Rule = PreferShiftHere()+ "[" + global_attribute_target + colon + attribute_list + comma_opt + "]";
attribute_target_specifier_opt.Rule = Empty | attribute_target + colon;
attribute_target.Rule = ToTerm("field") | "event" | "method" | "param" | "property" | "return" | "type";
attribute_arguments_par_opt.Rule = Empty | Lpar + attribute_arguments_opt + Rpar;
attribute_arguments_opt.Rule = MakeStarRule(attribute_arguments_opt, comma, attr_arg);
attr_arg.Rule = identifier + "=" + expression | expression;