无法为同时使用括号和交叉引用的语法生成 Xtext 工件
Cannot generate Xtext artifacts for grammar which uses parentheses and cross-references at once
我正在尝试从这个语法生成 DSL:
grammar org.xtext.example.mydsl.MyDsl with org.eclipse.xtext.common.Terminals
generate myDsl "http://www.xtext.org/example/mydsl/MyDsl"
Program:
"print" expression=Expression "where" constant=Constant |
"print" expression=Expression;
Expression:
Add;
Add returns Expression:
Primary({Add.expression1=current} "+" expression2=Primary)*;
Primary returns Expression:
ExpressionParentheses | Number | ConstUsage;
Number returns Expression:
value=INT;
Constant:
name=ID "=" number=Number;
ConstUsage returns Expression:
name=[Constant];
ExpressionParentheses returns Expression:
"(" Add ")";
但是在 Eclipse 中生成 Xtext 工件总是会产生错误。当我同时在主要规则中使用 ExpressionParentheses 和 ConstUsage 时,它总是会发生。当我将 ConstUsage 或 ExpressionParentheses 放在那里时,一切正常。我的语法可能有什么问题?
以下语法可以正常工作
Program:
"print" expression=Expression ("where" constant=Constant)?
;
Expression:
Add;
Add returns Expression:
Primary({Add.expression1=current} "+" expression2=Primary)*;
Primary returns Expression:
Number | ConstUsage | "("Add")";
Number returns Expression:
value=INT;
Constant:
name=ID "=" number=Number;
ConstUsage returns Expression:
name=[Constant];
我正在尝试从这个语法生成 DSL:
grammar org.xtext.example.mydsl.MyDsl with org.eclipse.xtext.common.Terminals
generate myDsl "http://www.xtext.org/example/mydsl/MyDsl"
Program:
"print" expression=Expression "where" constant=Constant |
"print" expression=Expression;
Expression:
Add;
Add returns Expression:
Primary({Add.expression1=current} "+" expression2=Primary)*;
Primary returns Expression:
ExpressionParentheses | Number | ConstUsage;
Number returns Expression:
value=INT;
Constant:
name=ID "=" number=Number;
ConstUsage returns Expression:
name=[Constant];
ExpressionParentheses returns Expression:
"(" Add ")";
但是在 Eclipse 中生成 Xtext 工件总是会产生错误。当我同时在主要规则中使用 ExpressionParentheses 和 ConstUsage 时,它总是会发生。当我将 ConstUsage 或 ExpressionParentheses 放在那里时,一切正常。我的语法可能有什么问题?
以下语法可以正常工作
Program:
"print" expression=Expression ("where" constant=Constant)?
;
Expression:
Add;
Add returns Expression:
Primary({Add.expression1=current} "+" expression2=Primary)*;
Primary returns Expression:
Number | ConstUsage | "("Add")";
Number returns Expression:
value=INT;
Constant:
name=ID "=" number=Number;
ConstUsage returns Expression:
name=[Constant];