How to write correct parser rules using JavaVMTypes [message #754961] |
Sat, 05 November 2011 21:26 |
Goran Messages: 45 Registered: November 2011 |
Member |
|
|
Hello everyone,
I am working on an extension of Java in Xtext however I am having difficulties using references to the JavaVMTypes.
References work perfect for the code like:
import java.lang.System;
...
java.lang.System.currentMilliseconds();
System.currentMilliseconds();
However the editor shows errors when trying to parse code like:
The error is: "Couldn't resolve reference to JvmType 'System.out'".
My question is how do I write correct parser rules that allow references to public static fields in classes such as System.out?
Relevant parts of my grammar are as follows:
grammar org.xtext.example.mydsl.MyDsl with org.eclipse.xtext.xbase.Xtype
generate myDsl "h ttp://www.xtext.org/example/mydsl/MyDsl"
import "h ttp://www.eclipse.org/emf/2002/Ecore" as ecore
import "h ttp://www.eclipse.org/xtext/common/JavaVMTypes" as jvmTypes
CompilationUnit
: // A compilation unit starts with an optional package definition
package=PackageDeclaration?
imports+=Import*
typeDefinitions+=TypeDefinition*
;
Import:
'import' importedNamespace=QualifiedNameWithWildCard ';' ;
TypeDefinition
: JavaClassDeclaration
;
expression returns JavaExpression
: JavaBasicExpression
;
//.... the usual other expression rules
JavaUnaryExpressionNotPlusMinus returns JavaExpression
: {JavaUnaryExpressionNotPlusMinus} operator='~' unaryExpr=JavaUnaryExpression
| {JavaUnaryExpressionNotPlusMinus} operator='!' unaryExpr=JavaUnaryExpression
| JavaPrimaryExpression ({JavaUnaryExpressionNotPlusMinus.primary=current} selectors+=JavaSelector+)? ('++'|'--')?
;
JavaPrimaryExpression returns JavaExpression
: parExpression
| {JavaIdentifierReference} target=IdentifierReference //suffix=JavaIdentifierSuffix?
;
JavaSelector returns JavaExpression
: {JavaMethodCall} '.' methodName=ID arguments=JavaArguments // Method Call
;
IdentifierReference
: typeRef=JvmTypeReference
;
JvmVoid returns jvmTypes::JvmVoid:
{jvmTypes::JvmVoid} 'void'
;
JvmTypeReference returns jvmTypes::JvmParameterizedTypeReference:
JvmParameterizedTypeReference =>({JvmGenericArrayTypeReference.componentType=current} '['']')*
;
JavaVariable:
name=ID
;
//.... other rules
I tried different adjustments to the grammar without any success.
How can I solve this issue?
Thanks in advance.
[Updated on: Sun, 06 November 2011 23:19] Report message to a moderator
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.04570 seconds