[Xtext] Matching Value for a locale Rule not allowed in other Rules? [message #60874] |
Sun, 19 July 2009 15:42 |
Eclipse User |
|
|
|
Hi
I would like to explain my problem considering the grammar example as
follows:
grammar org.xtext.example.MyDsl with org.eclipse.xtext.common.Terminals
generate myDsl "http://www.xtext.org/example/MyDsl"
Model :
'Model' '{'
(modelParamValuePair+=ParamValuePair)+
(blocks+=Block)+
(line+=Line)+
'}';
Block :
'Block'
'{'
('Name' name=STRING | blockParamValuePair+=ParamValuePair)+
'}'
;
Line :
'Line'
'{'
'SrcBlock' srcBlock=[Block|STRING]
'SrcPort' srcPort=INT
('DstBlock' dstBlock=[Block|STRING]
'DstPort' dstPort=INT)?
'}'
;
ParamValuePair :
parameter=(ID) value=STRING
;
You can see here, that a "Block" exlipcitely has a feature "name". And a
String after the Keyword "Name" will be the value of such a feature.
But the generated editor do not accept to have a Parameter Value Pair with
Parameter-Name "Name" directly in the "Model{ ... }" Context.
My question is: why is it not possible to have "Name" "AValue" after
"Model{"?
That is working:
Model{
param "ParamVal"
Block{
Name "Helko"
}
Line {
SrcBlock "Helko"
SrcPort 1
}
}
That throws an editor error, but should work:
Model{
Name "kA" //should be ok, but says "required (...)+ loop did not match
anything at input 'Name'"
param "ParamVal"
Block{
Name "Helko"
}
Line {
SrcBlock "Helko"
SrcPort 1
}
}
Thanks in advance, Helko
|
|
|
|
|
Re: [Xtext] Matching Value for a locale Rule not allowed in other Rules? [message #60952 is a reply to message #60928] |
Mon, 20 July 2009 07:38 |
Eclipse User |
|
|
|
Thank you - Sven and Alexander for the quick reply -
The problem is, that the model file that should be parsed will be
generated by an external tool. So, it is impossible to adjust the export
mechanism in that that it writes ^Name instead of Name.
Alexanders second solution is also problematic....
Because, only the token after Keyword "Name" shall be saved into the
Blocks feature/variable "name" to be able to apply cross reference links.
The rest of the generic parameter value pairs shall be saved as a simple
set of ParamValuePair Objects.
Regards, Helko
Alexander Nittka wrote:
> Hi,
> My guess is that as "Name" is a keyword in your grammar, the tokeniser
> marks it as keyword. But then it won't be accepted as an ID. But your
> ParamValuePair expects an ID as parameter name. You could try escaping
> Name in your model file "^Name" so that it is tokenised as ID or you
> could adjust your grammar, such that ID and a list of keywords you want
> to be allowed are accepted as parameter names. Something like
> ParamValuePair:
> parameter=ExtendedID value=STRING;
> ExtendedID:
> ID|'Name'|'Line';
> However, the first alternative is the one to be favoured (there is a
> reason why keywords are keywords);
|
|
|
Re: [Xtext] Matching Value for a locale Rule not allowed in other Rules? [message #60979 is a reply to message #60952] |
Mon, 20 July 2009 08:22 |
Alexander Nittka Messages: 1193 Registered: July 2009 |
Senior Member |
|
|
> Alexanders second solution is also problematic....
> Because, only the token after Keyword "Name" shall be saved into the
> Blocks feature/variable "name" to be able to apply cross reference links.
> The rest of the generic parameter value pairs shall be saved as a simple
> set of ParamValuePair Objects.
OK, how about the following.
Model :
'Model' '{'
(modelParamValuePair+=ExtendedParamValuePair)+
(blocks+=Block)+
(line+=Line)+
'}';
Block :
'Block'
'{'
('Name' name=STRING | blockParamValuePair+=ParamValuePair)+
'}'
;
Line :
'Line'
'{'
'SrcBlock' srcBlock=[Block|STRING]
'SrcPort' srcPort=INT
('DstBlock' dstBlock=[Block|STRING]
'DstPort' dstPort=INT)?
'}'
;
ExtendedParamValuePair:
ParamValuePair|NameParamValuePair;
ParamValuePair :
parameter=(ID) value=STRING
;
NameParamValuePair returns ParamValuePair:
parameter='Name' value=STRING;
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
|
|
|
Powered by
FUDForum. Page generated in 0.03129 seconds