我遇到了一个问题,就是让XText生成一个解析器,可以在限定名称和方法之间区分Java风格。
例如,考虑以下形式的陈述:
x.y.z();
这可以是:
如何使用XText处理以下内容(稍微无意义但完全语义敏感)的Java表达式:
java.util.Collections.EMPTY_LIST.size() + "foo".concat("bar").length();
目前给我一个解析错误:
SEVERE: Error at line 5: mismatched input '.' expecting '(' [Thu Dec 04 14:45:20 CST 2014]
SEVERE: Error at line 5: missing EOF at '.' [Thu Dec 04 14:45:20 CST 2014]
目前XText代码的相关片段:
grammar it.unibo.alchemist.language.FieldCalculus with org.eclipse.xtext.common.Terminals
import "http://www.eclipse.org/emf/2002/Ecore" as ecore
[...]
QualifiedName: ID ('.' ID)* ;
FunctionCall returns Expression:
(function=QualifiedName)'('args=ExprList?')'
;
Expression:
Logical ';'?
;
Logical returns Expression:
[... order of operations build-up to ...]
Postfix returns Expression:
Primary
({Expression.left=current}(
(name='.' methodName=ID '(' (args=ExprList)? ')')
))?
;
Primary returns Expression:
(v = (VarVal | FunctionCall | Rep | NBR | If) | '(' Expression ')')
;