Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » XText entry rule
XText entry rule [message #1057846] Thu, 09 May 2013 09:53 Go to next message
Alfredo Motta is currently offline Alfredo MottaFriend
Messages: 41
Registered: June 2012
Member
Hello everybody,

in XText the first rule of the grammar is the entry rule.
When I use the generated parser in my standalone application I do the
following:

   Resource resource = 
resourceSet.createResource(URI.createURI("file:/example.mydsl"));
   InputStream in = new ByteArrayInputStream(inputString.getBytes());
   resource.load(in, resourceSet.getLoadOptions());
   Model model = (Model) resource.getContents().get(0);


where "Model" is the first rule of my grammar.

I am wondering if it is possible to obtain a parser where the entry rule
is any of the other rules defined in the grammar.
In other words I am wondering if it is possible to know if I can write
something like

   Resource resource = 
resourceSet.createResource(URI.createURI("file:/example.mydsl"));
   InputStream in = new ByteArrayInputStream(inputString.getBytes());
   resource.load(in, resourceSet.getLoadOptions());
   RuleOfChoice parsedRule = (RuleOfChoice) resource.getContents().get(0);


where "RuleOfChoice" is one of the rules defined in mydsl, but it is not
the entry rule.

Thank you for your help
Re: XText entry rule [message #1057849 is a reply to message #1057846] Thu, 09 May 2013 09:55 Go to previous messageGo to next message
Alfredo Motta is currently offline Alfredo MottaFriend
Messages: 41
Registered: June 2012
Member
On 05/09/2013 11:53 AM, Alfredo Motta wrote:
> In other words I am wondering if it is possible to know if I can write
> something like

EDIT:
In other words I am wondering if it is possible to write something like:
Re: XText entry rule [message #1057976 is a reply to message #1057849] Fri, 10 May 2013 09:30 Go to previous messageGo to next message
Alfredo Motta is currently offline Alfredo MottaFriend
Messages: 41
Registered: June 2012
Member
I will try to explain myself again.

Does XText produce additional parsers apart from the standard one that
starts parsing the input using the entry rule?

In other words I would like to write something like "parse this input
and use the following rule of the grammar as the entry point"

Thank you

On 05/09/2013 11:55 AM, Alfredo Motta wrote:
> On 05/09/2013 11:53 AM, Alfredo Motta wrote:
>> In other words I am wondering if it is possible to know if I can write
>> something like
>
> EDIT:
> In other words I am wondering if it is possible to write something like:
Re: XText entry rule [message #1057988 is a reply to message #1057976] Fri, 10 May 2013 10:52 Go to previous message
Alexander Nittka is currently offline Alexander NittkaFriend
Messages: 1193
Registered: July 2009
Senior Member
Hi,

did you have a look at the Parser? It has a method parse(ParserRule rule, Reader reader). The parser rule you could obtain from the GrammarAccess of your language.

Alex


Need training, onsite consulting or any other kind of help for Xtext?
Go visit http://xtext.itemis.com or send a mail to xtext@itemis.de
Previous Topic:Redefining imported name
Next Topic:Missing type info in JvmType model
Goto Forum:
  


Current Time: Fri Apr 19 06:02:30 GMT 2024

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

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

Back to the top