Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Parsing a portion of the model
Parsing a portion of the model [message #723120] Wed, 07 September 2011 16:46 Go to next message
drew frantz is currently offline drew frantzFriend
Messages: 340
Registered: July 2009
Senior Member
I am trying to parse a single statement of my grammar and upon doing so with
the code below the elements of the rule that are references are null. I am
sure I am missing something because in order to resolve references I must
need to pass those statements containing the referred to elements to the
parser , but I am not clear on how to accomplish this.

Everything works as expected below except that any grammar rules that
contain references are null. Anyone have a suggestion on how to parse a
portion of a model that contains references?

IParseResult getParsedResult(String theRule, String expression)
{

IParseResult res = myAntlrParser.parse(theRule, new
StringInputStream(expression));
return res;
}
Re: Parsing a portion of the model [message #723152 is a reply to message #723120] Wed, 07 September 2011 20:11 Go to previous messageGo to next message
Sebastian Zarnekow is currently offline Sebastian ZarnekowFriend
Messages: 3118
Registered: July 2009
Senior Member
Hi Drew,

please have a look at
org.eclipse.xtext.ui.codetemplates.ui.projectedEditing.PartialParser.assignRootRule(XtextResource,
ParserRule)

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

On 07.09.11 18:46, Drew wrote:
> I am trying to parse a single statement of my grammar and upon doing so
> with the code below the elements of the rule that are references are
> null. I am sure I am missing something because in order to resolve
> references I must need to pass those statements containing the referred
> to elements to the parser , but I am not clear on how to accomplish this.
>
> Everything works as expected below except that any grammar rules that
> contain references are null. Anyone have a suggestion on how to parse a
> portion of a model that contains references?
>
> IParseResult getParsedResult(String theRule, String expression)
> {
>
> IParseResult res = myAntlrParser.parse(theRule, new
> StringInputStream(expression));
> return res;
> }
Re: Parsing a portion of the model [message #723166 is a reply to message #723152] Wed, 07 September 2011 21:12 Go to previous message
drew frantz is currently offline drew frantzFriend
Messages: 340
Registered: July 2009
Senior Member
Based on what I see in PartialParser (which is a 2.0 class, I am still using
1.x). I just tried doing this in 1.x by doing the following experiments in
1.x.

Experiment 1: Cast to IAntlrParser gets me the correct rootAstElement
Result: Get back a valid rootAstElement that has most of what I need, but
leaves the references null inside the child elements. (Essentially the same
behavior I already had).
EObject existingItemInModel = theItem;
XtextResource xResource = (XtextResource )existingItemInModel.eResource();
IAntrlParser theParser = (IAntrlParser )xResource.getParser();
IParseResult res = theParser.parse(theRule, new
StringInputStream(expression));


Experiment 2: Just use IParser
Result: this nulls out the rootAstElement, and just has a rootNode which I
would need to somehow translate into EMF elements,
EObject existingItemInModel = theItem;
XtextResource xResource = (XtextResource )existingItemInModel.eResource();
IParser theParser = xResource.getParser();
IParseResult res = theParser.parse(new StringInputStream(expression));




"Sebastian Zarnekow" <Sebastian.Zarnekow@itemis.de> wrote in message
news:j48igr$tmq$1@news.eclipse.org...
> Hi Drew,
>
> please have a look at
> org.eclipse.xtext.ui.codetemplates.ui.projectedEditing.PartialParser.assignRootRule(XtextResource,
> ParserRule)
>
> Regards,
> Sebastian
> --
> Need professional support for Eclipse Modeling?
> Go visit: http://xtext.itemis.com
>
> On 07.09.11 18:46, Drew wrote:
>> I am trying to parse a single statement of my grammar and upon doing so
>> with the code below the elements of the rule that are references are
>> null. I am sure I am missing something because in order to resolve
>> references I must need to pass those statements containing the referred
>> to elements to the parser , but I am not clear on how to accomplish this.
>>
>> Everything works as expected below except that any grammar rules that
>> contain references are null. Anyone have a suggestion on how to parse a
>> portion of a model that contains references?
>>
>> IParseResult getParsedResult(String theRule, String expression)
>> {
>>
>> IParseResult res = myAntlrParser.parse(theRule, new
>> StringInputStream(expression));
>> return res;
>> }
>
>
Previous Topic:XBase for developing code generator for C# and XML?
Next Topic:GMF and Xtext working on same resource - How?
Goto Forum:
  


Current Time: Thu Apr 25 20:57:08 GMT 2024

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

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

Back to the top