Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » [Xtext 2.0] How to loose up member order in grammar
[Xtext 2.0] How to loose up member order in grammar [message #668818] Sat, 07 May 2011 23:44 Go to next message
Alex Ruiz is currently offline Alex RuizFriend
Messages: 103
Registered: March 2011
Senior Member
Greetings,

I'm working on a protocol buffer editor for Eclipse using Xtext 2.0. Here is the relevant part of the grammar:

import "http://www.eclipse.org/emf/2002/Ecore" as ecore
generate protobuf "http://www.google.com/eclipse/protobuf/Protobuf"

Protobuf:
  (syntax=Syntax)?	
  (package=Package)?
  (imports+=Import)*
  (options+=Option)*
  (elements+=ProtobufElement)*;

Syntax:
  'syntax' '=' name=STRING ';';  
  
Package:
  'package' name=QualifiedName ';';

Import: 
  'import' importURI=STRING ';';

QualifiedName:
  ID ('.' ID)*;

Option:
  'option' name=ID '=' value=ValueRef ';';

ProtobufElement:
  Type | ExtendMessage | Service;


In the editor, I must specify "package" as the first element, then "imports" and "options". If I specify "options" before "imports" Xtext shows syntax errors.

It turns out that the protocol buffer compiler considers having imports before or after options as valid. How can I emulate this behavior in Xtext?

Many thanks in advance,
-Alex
Re: [Xtext 2.0] How to loose up member order in grammar [message #668830 is a reply to message #668818] Sun, 08 May 2011 11:55 Go to previous messageGo to next message
Jan Koehnlein is currently offline Jan KoehnleinFriend
Messages: 760
Registered: July 2009
Location: Hamburg
Senior Member
How about

Protobuf:
(syntax=Syntax)?
(package=Package)?
(imports+=Import | options+=Option)*
(elements+=ProtobufElement)*;

You could also have a look at unordered groups.

Am 08.05.11 02:39, schrieb Alex Ruiz:
> Greetings,
>
> I'm working on a protocol buffer editor for Eclipse using
> Xtext 2.0. Here is the relevant part of the grammar:
>
>
> import "http://www.eclipse.org/emf/2002/Ecore" as ecore
> generate protobuf
> "http://www.google.com/eclipse/protobuf/Protobuf"
>
> Protobuf:
> (syntax=Syntax)?
> (package=Package)?
> (imports+=Import)*
> (options+=Option)*
> (elements+=ProtobufElement)*;
>
> Syntax:
> 'syntax' '=' name=STRING ';';
>
> Package:
> 'package' name=QualifiedName ';';
>
> Import:
> 'import' importURI=STRING ';';
>
> QualifiedName:
> ID ('.' ID)*;
>
> Option:
> 'option' name=ID '=' value=ValueRef ';';
>
> ProtobufElement:
> Type | ExtendMessage | Service;
>
>
> In the editor, I must specify "package" as the first
> element, then "imports" and "options". If I specify
> "options" before "imports" Xtext shows syntax errors.
>
> It turns out that the protocol buffer compiler considers
> having imports before or after options as valid. How can I
> emulate this behavior in Xtext?
>
> Many thanks in advance,
> -Alex


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


---
Get professional support from the Xtext committers at www.typefox.io
Re: [Xtext 2.0] How to loose up member order in grammar [message #668835 is a reply to message #668818] Sun, 08 May 2011 15:00 Go to previous messageGo to next message
Alex Ruiz is currently offline Alex RuizFriend
Messages: 103
Registered: March 2011
Senior Member
Thanks Jan!

Protobuf:
  (syntax=Syntax)?	
  (package=Package)? 
  (imports+=Import | options+=Option)*
  (elements+=ProtobufElement)*;


works for imports and options just as I wanted! Smile

The only remaining issue is "package". It can be declared anywhere between "syntax" and "elements". I tried unordered groups as follows:

Protobuf:
  (syntax=Syntax)?	
  (package=Package)? & (imports+=Import | options+=Option)*
  (elements+=ProtobufElement)*;


but I got the following when running the mwe2 file:

warning(200): ../com.google.eclipse.protobuf/src-gen/com/google/eclipse/protobuf/parser/antlr/internal/InternalProtobuf.g:95:17: Decision can match input such as "'syntax'" using multiple alternatives: 1, 2
As a result, alternative(s) 2 were disabled for that input
Semantic predicates were present but were hidden by actions.
warning(200): ../com.google.eclipse.protobuf/src-gen/com/google/eclipse/protobuf/parser/antlr/internal/InternalProtobuf.g:113:3: Decision can match input such as "'package'" using multiple alternatives: 1, 2
As a result, alternative(s) 2 were disabled for that input
Semantic predicates were present but were hidden by actions.
warning(200): ../com.google.eclipse.protobuf/src-gen/com/google/eclipse/protobuf/parser/antlr/internal/InternalProtobuf.g:180:2: Decision can match input such as "'import'" using multiple alternatives: 1, 3
As a result, alternative(s) 3 were disabled for that input
Semantic predicates were present but were hidden by actions.
warning(200): ../com.google.eclipse.protobuf/src-gen/com/google/eclipse/protobuf/parser/antlr/internal/InternalProtobuf.g:180:2: Decision can match input such as "'option'" using multiple alternatives: 2, 3
As a result, alternative(s) 3 were disabled for that input
Semantic predicates were present but were hidden by actions.
warning(200): ../com.google.eclipse.protobuf/src-gen/com/google/eclipse/protobuf/parser/antlr/internal/InternalProtobuf.g:198:1: Decision can match input such as "'service'" using multiple alternatives: 1, 2
As a result, alternative(s) 2 were disabled for that input
Semantic predicates were present but were hidden by actions.
warning(200): ../com.google.eclipse.protobuf/src-gen/com/google/eclipse/protobuf/parser/antlr/internal/InternalProtobuf.g:198:1: Decision can match input such as "'enum'" using multiple alternatives: 1, 2
As a result, alternative(s) 2 were disabled for that input
Semantic predicates were present but were hidden by actions.
warning(200): ../com.google.eclipse.protobuf/src-gen/com/google/eclipse/protobuf/parser/antlr/internal/InternalProtobuf.g:198:1: Decision can match input such as "'message'" using multiple alternatives: 1, 2
As a result, alternative(s) 2 were disabled for that input
Semantic predicates were present but were hidden by actions.
warning(200): ../com.google.eclipse.protobuf/src-gen/com/google/eclipse/protobuf/parser/antlr/internal/InternalProtobuf.g:198:1: Decision can match input such as "'extend'" using multiple alternatives: 1, 2
As a result, alternative(s) 2 were disabled for that input
Semantic predicates were present but were hidden by actions.


Many thanks in advance,
-Alex
Re: [Xtext 2.0] How to loose up member order in grammar [message #668849 is a reply to message #668835] Sun, 08 May 2011 19:33 Go to previous message
Alex Ruiz is currently offline Alex RuizFriend
Messages: 103
Registered: March 2011
Senior Member
I got it working as follows:

((package=Package)? & (imports+=Import)* & (options+=Option)*)


Cheers!
-Alex
Previous Topic:[Xtext 2.0] How to loose up member order in grammar
Next Topic:Re: Change of IUnitOfWork behaviour in 2.0M7
Goto Forum:
  


Current Time: Fri Apr 19 21:17:07 GMT 2024

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

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

Back to the top