Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Partial parsing to an EObject which contains a cross reference across grammars(Partial parsing of a text to an EObject which contains a cross reference to another EObject which is defined in another grammar (cross-referencing across grammars).)
icon5.gif  Partial parsing to an EObject which contains a cross reference across grammars [message #755732] Wed, 09 November 2011 12:15 Go to next message
Suraj Varghese is currently offline Suraj VargheseFriend
Messages: 4
Registered: November 2011
Junior Member
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.
Re: Partial parsing to an EObject which contains a cross reference across grammars [message #755776 is a reply to message #755732] Wed, 09 November 2011 14:50 Go to previous message
Jan Koehnlein is currently offline Jan KoehnleinFriend
Messages: 760
Registered: July 2009
Location: Hamburg
Senior Member
While partial parsing makes sens internally, partial linking doesn't as
linking always requires some kind of context and changes in one region
could cause the links to change in completely different regions.

It's a better idea to use Xtext on the basis of resources not text
snippets, i.e. write your grammar such that each snippet makes a valid
model.

Could you explain how your snippets are related to each other and where
they get their contexts for cross-references?



Am 09.11.11 13:15, schrieb suraj.varghese:
> 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.


--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com


---
Get professional support from the Xtext committers at www.typefox.io
Previous Topic:Xtext 2.1.0 Distribution (Indigo) - Cannot create Xtext project
Next Topic:EclipseCon North America
Goto Forum:
  


Current Time: Tue Apr 16 15:46:05 GMT 2024

Powered by FUDForum. Page generated in 0.61846 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top