Skip to main content



      Home
Home » Modeling » TMF (Xtext) » [Xtext] Matching Value for a locale Rule not allowed in other Rules?
[Xtext] Matching Value for a locale Rule not allowed in other Rules? [message #60874] Sun, 19 July 2009 11:42 Go to next message
Eclipse UserFriend
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 #60907 is a reply to message #60874] Mon, 20 July 2009 02:33 Go to previous messageGo to next message
Eclipse UserFriend
Hi Helko,

'Name' is not an ID anymore since you introduced a corresponding keyword
in the rule Block. Keywords as well as terminal rules are globally visible.
If you want to make a word an identifier which would otherwise be
recognized as a keyword you could use the identifier escape character
'^'. That is you could write :

Model {
^Name "fgfgf"
...

Cheers,
Sven

Helko Glathe schrieb:
> 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
>


--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com
Re: [Xtext] Matching Value for a locale Rule not allowed in other Rules? [message #60928 is a reply to message #60874] Mon, 20 July 2009 02:43 Go to previous messageGo to next message
Eclipse UserFriend
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 #60952 is a reply to message #60928] Mon, 20 July 2009 03:38 Go to previous messageGo to next message
Eclipse UserFriend
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 04:22 Go to previous message
Eclipse UserFriend
> 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;
Previous Topic:Quoted Strings in Enums?
Next Topic:Importing XML schema as metamodel?
Goto Forum:
  


Current Time: Sun Jun 01 07:27:37 EDT 2025

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

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

Back to the top