Partial parsing to an EObject which contains a cross reference across grammars [message #755629] |
Wed, 09 November 2011 01:05 |
Eclipse User |
|
|
|
Hi,
During model to model transformation, we sometimes parse code snippets to get the Grammar based EObjects.
This way of working with certain pieces helps because we need not write code for the transformation of the snippet.
Parsing of snippet works fine during the transformation as long as there is no cross reference (across different grammar; I have not tried within same grammar too).
I tried to use ILinker.linkModel after parsing but that fails since I am not using XTextResource during parsing (since the parse is partial).
The reason it fails is because it does not set the referenced object in the EObject.
I have not tried PartialParsingHelper because I do not have the original root node (I am trying to construct that right now).
The code is as follows:
Grammar definitions
/***************/
/* First.xtext */
Model : ...
Statement:
'Statement' name=ID
;
/***************/
/***************/
/* Second.xtext */
import ...
.....
Statements:
(statements+=BaseStatment)*
;
BaseStatment:
BasicStatement | ReferenceStatement
;
BasicStatement:
'Basic' name=ID
;
ReferenceStatement:
'Reference' reference=[first::Statement]
;
/***************/
Java code snippet in my model to model transformation code.
/***************/
IParseResult parseResult = parser.parse("Statements", new StringReader("Reference HelloWorld"))
if (parseResult.getRootNode() != null
&& !NodeContentAdapter.containsNodeContentAdapter(parseResult.getRootNode()))
{
NodeContentAdapter.createAdapterAndAddToNode(parseResult.getRootNode());
}
EObject eObject = parseResult.getRootASTElement();
/***************/
// The reference feature of ReferenceStatementEObject in above is null.
Can somebody throw some light as to where should I start to look at to fix this issue?
I am using XText 1.0.1.
|
|
|
Powered by
FUDForum. Page generated in 0.02888 seconds