[xtext 2] Problem with QualifiedNames [message #666574] |
Thu, 21 April 2011 06:13 |
Alex Ruiz Messages: 103 Registered: March 2011 |
Senior Member |
|
|
Greetings,
I have spent a considerable amount of time trying to figure out this, without success. I apologize for the long question.
I'm using Xtext 2 to create an editor for Protocol Buffers (there are like 5 out there, and none of them work.) This work will be open sourced, once we have something to offer.
The problem I have is that with Protocol Buffers, qualified names may or may not include the package. For example, given the package "hello.world" the element "Person" can be referred as "hello.world.Person" or just "Person". So far, in my editor only "hello.world.Person" can be found by Xtext.
How can I enable "multiple" valid QualifiedNames for a element?
I'm attaching a bunch of stuff. Here is the grammar:
grammar com.google.eclipse.protobuf.Protobuf with org.eclipse.xtext.common.Terminals
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;
Type:
Message | Enum;
Message:
'message' name=ID '{'
elements+=MessageElement*
('extensions' extensionsFrom=INT 'to' (extensionsTo=INT | 'max') ';')?
'}'(';')?;
MessageElement:
Type | Property;
Property:
modifier=Modifier type=AbstractTypeReference name=ID '=' index=INT (('[' 'default' '=' default=ValueRef
']') | ('[' 'packed' '=' packed=BooleanRef ']'))? ';';
enum Modifier:
required
| optional
| repeated;
AbstractTypeReference:
ScalarTypeReference | TypeReference;
ScalarTypeReference:
scalar=ScalarType;
enum ScalarType:
double
| float
| int32
| int64
| uint32
| uint64
| sint32
| sint64
| fixed32
| fixed64
| sfixed32
| sfixed64
| bool
| string
| bytes;
TypeReference:
type=[Type | QualifiedName];
ValueRef:
LiteralRef
| BooleanRef
| IntRef
| FloatRef
| StringRef;
LiteralRef:
literal=[Literal];
BooleanRef:
boolean=BOOL;
enum BOOL:
true
| false;
IntRef:
int=INT;
FloatRef:
float=FLOAT;
StringRef:
string=STRING;
Enum:
'enum' name=ID '{'
literals+=Literal*
'}' ';'?;
Literal:
name=ID '=' index=INT ';';
ExtendMessage:
'extend' message=[Message] '{'
elements+=MessageElement*
'}';
Service:
'service' name=ID '{'
rpc=Rpc
'}';
Rpc:
'rpc' name=ID '(' argType=MessageReference ')' 'returns' '(' returnType=MessageReference ')' ';'
;
MessageReference:
type=[Message | QualifiedName];
terminal INT returns ecore::EInt: ('0'..'9')+;
terminal FLOAT returns ecore::EFloat: ('0'..'9')* ('.' ('0'..'9')+)?;
In the mwe2 file I have the following:
// java-based API for validation
fragment = validation.JavaValidatorFragment {
composedCheck = "org.eclipse.xtext.validation.ImportUriValidator"
composedCheck = "org.eclipse.xtext.validation.NamesAreUniqueValidator"
// registerForImportedPackages = true
}
// scoping and exporting API
// fragment = scoping.ImportURIScopingFragment {}
// fragment = exporting.SimpleNamesFragment {}
// scoping and exporting API
fragment = scoping.ImportNamespacesScopingFragment {}
fragment = exporting.QualifiedNamesFragment {}
fragment = builder.BuilderIntegrationFragment {}
Since the package is optional, but it should be part of the FQN, I created my own IQualifiedNameProvider. It works fine.
Any help will be greatly appreciated
-Alex
|
|
|
Re: [xtext 2] Problem with QualifiedNames [message #666596 is a reply to message #666574] |
Thu, 21 April 2011 09:01 |
Jan Koehnlein Messages: 760 Registered: July 2009 Location: Hamburg |
Senior Member |
|
|
I don't know about the Protocol Buffers language: What does it mean if
no package is specified?
You should implement an IScopeProvider to put the elements with the
simple names on the scope. This is a good solution if these short names
are only valid a specific referring context, e.g. from elements within
the same package.
Am 21.04.11 08:14, schrieb Alex Ruiz:
> Greetings,
>
> I have spent a considerable amount of time trying to figure out this,
> without success. I apologize for the long question.
>
> I'm using Xtext 2 to create an editor for Protocol Buffers (there are
> like 5 out there, and none of them work.) This work will be open
> sourced, once we have something to offer.
>
> The problem I have is that with Protocol Buffers, qualified names may or
> may not include the package. For example, given the package
> "hello.world" the element "Person" can be referred as
> "hello.world.Person" or just "Person". So far, in my editor only
> "hello.world.Person" can be found by Xtext.
>
> How can I enable "multiple" valid QualifiedNames for a element?
>
> I'm attaching a bunch of stuff. Here is the grammar:
>
>
> grammar com.google.eclipse.protobuf.Protobuf with
> org.eclipse.xtext.common.Terminals
>
> 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;
>
> Type:
> Message | Enum;
>
> Message:
> 'message' name=ID '{'
> elements+=MessageElement*
> ('extensions' extensionsFrom=INT 'to' (extensionsTo=INT | 'max') ';')?
> '}'(';')?;
>
> MessageElement:
> Type | Property;
>
> Property:
> modifier=Modifier type=AbstractTypeReference name=ID '=' index=INT (('['
> 'default' '=' default=ValueRef
> ']') | ('[' 'packed' '=' packed=BooleanRef ']'))? ';';
>
> enum Modifier:
> required
> | optional
> | repeated;
>
> AbstractTypeReference:
> ScalarTypeReference | TypeReference;
>
> ScalarTypeReference:
> scalar=ScalarType;
>
> enum ScalarType:
> double
> | float
> | int32
> | int64
> | uint32
> | uint64
> | sint32
> | sint64
> | fixed32
> | fixed64
> | sfixed32
> | sfixed64
> | bool
> | string
> | bytes;
>
> TypeReference:
> type=[Type | QualifiedName];
>
> ValueRef:
> LiteralRef
> | BooleanRef
> | IntRef
> | FloatRef
> | StringRef;
>
> LiteralRef:
> literal=[Literal];
>
> BooleanRef:
> boolean=BOOL;
>
> enum BOOL:
> true
> | false;
>
> IntRef:
> int=INT;
>
> FloatRef:
> float=FLOAT;
>
> StringRef:
> string=STRING;
>
> Enum:
> 'enum' name=ID '{'
> literals+=Literal*
> '}' ';'?;
>
> Literal:
> name=ID '=' index=INT ';';
>
> ExtendMessage:
> 'extend' message=[Message] '{'
> elements+=MessageElement*
> '}';
>
> Service:
> 'service' name=ID '{'
> rpc=Rpc
> '}';
>
> Rpc: 'rpc' name=ID '(' argType=MessageReference ')' 'returns' '('
> returnType=MessageReference ')' ';'
> ;
>
> MessageReference:
> type=[Message | QualifiedName];
>
> terminal INT returns ecore::EInt: ('0'..'9')+; terminal FLOAT returns
> ecore::EFloat: ('0'..'9')* ('.' ('0'..'9')+)?;
>
>
> In the mwe2 file I have the following:
>
>
> // java-based API for validation fragment =
> validation.JavaValidatorFragment {
> composedCheck = "org.eclipse.xtext.validation.ImportUriValidator"
> composedCheck = "org.eclipse.xtext.validation.NamesAreUniqueValidator"
> // registerForImportedPackages = true
> }
>
> // scoping and exporting API
> // fragment = scoping.ImportURIScopingFragment {}
> // fragment = exporting.SimpleNamesFragment {}
>
> // scoping and exporting API fragment =
> scoping.ImportNamespacesScopingFragment {}
> fragment = exporting.QualifiedNamesFragment {}
> fragment = builder.BuilderIntegrationFragment {}
>
>
> Since the package is optional, but it should be part of the FQN, I
> created my own IQualifiedNameProvider. It works fine.
>
> Any help will be greatly appreciated :)
>
> -Alex
--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com
---
Get professional support from the Xtext committers at www.typefox.io
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03670 seconds