[TCS] Grammar file ".g" [message #32193] |
Wed, 18 March 2009 10:44  |
Eclipse User |
|
|
|
Hello,
I have a question regarding the grammar file generated in a TCS project.
By default, whene I create a new TCS project an empty grammar file is
generated. Should we specify the grammar ourselves?? or is there something
wrong with that?
Thank you for your reply
Best regards,
Hayfa.
|
|
|
|
|
|
|
|
|
|
|
Re: [TCS] Grammar file ".g" [message #37557 is a reply to message #37456] |
Mon, 06 April 2009 09:06   |
Eclipse User |
|
|
|
"Sven Efftinge" <sven.efftinge@itemis.de> wrote in message
news:grcs34$ktr$1@build.eclipse.org...
> Andy Carpenter schrieb:
>> Although I find TMF Xtext definitions much more verbose than
>> TCS ones, TMF Xtext will have the capabilities that you need and
>> my advise would be to use it for your project.
>
> What specifically do you find more verbose in TMF Xtext?
> Or did you mean less verbose?
I did mean that Xtext was more verbose. Consider a comma
separated parameter list, associated with a feature called
parameters. In TCS I can write
parameters{separator=","}
I just started with Xtext, so there might be an alternative, but at
the moment to express the same in Xtext I'm writing
parameters+=Parameter (',' parameters+=Parameter)*
Since, my original post I've been using Xtext more and have
discovered that it appears to assume that a resource is a flat
namespace. Thus, to resolve references in my DSL which is
scoped, I've had to write an implementation of both IScopeProvider
and IScope that allow nested namespaces within a resource.
In TCS I had to just indicate which syntactic elements gave a
scope and which elements were added to the current scope.
The biggest issue I've faced with Xtext is parsing a multiplicity
statement that supports specified (0..n), unspecified (?) and
unbounded (*) values. The TCS function to parse this was
not simple, but it did allow me to have simple numeric
lowerBound and upperBound features.
function multiplicity(ETypedElement) :
(lowerBound = 0 and upperBound = -2
? "[" "?" "]"
: (lowerBound = 0 and upperBound = 1
?
: (lowerBound = 0 and upperBound = -1
? "[" "*" "]"
: (lowerBound = 0 and upperBound = -1
? "[" "]"
: (lowerBound = 1 and upperBound = -1
? "[" "+" "]"
: (upperBound = -3 -- TODO equals lowerBound
? "[" lowerBound "]"
: (upperBound = -1
? "[" lowerBound ".." "*" "]"
: (upperBound = -2
? "[" lowerBound ".." "?" "]"
: "[" lowerBound ".." upperBound"]"
)
)
)
)
)
)
)
);
To do this in Xtext I've currently introduced the elements shown
below into the meta-model and am about to write the m2m
transformation that removes them from the meta-model that
my application uses.
ElementBound : SpecifiedBound | UnspecifiedBound | UnlimitedBound;
SpecifiedBound : bound=INT;
UnspecifiedBound : '?';
UnlimitedBound : '*';
( '[' lowerBound=ElementBound ('..' upperBound=ElementBound)? ']' )?
Please don't take my view of Xtext as just negative, these are
the issues that I've found while using it. I have found that it
does much of what I want and I'm building on it.
Andy.
|
|
|
[Xtext] Feedback (was Re: [TCS] Grammar file ".g") [message #37640 is a reply to message #37557] |
Mon, 06 April 2009 10:33   |
Eclipse User |
|
|
|
Hi Andy,
thanks for the feedback.
Please find my comments inlined.
Andy Carpenter schrieb:
> In TCS I can write
>
> parameters{separator=","}
>
> I just started with Xtext, so there might be an alternative, but at
> the moment to express the same in Xtext I'm writing
>
> parameters+=Parameter (',' parameters+=Parameter)*
Yes, we've been thinking about this, since this is a common recurring thing.
However, we wanted to make sure that we find a good generalized solution
and also wanted to spend our time on other things, since this can be
solved even if in a little more verbose manner.
> Since, my original post I've been using Xtext more and have
> discovered that it appears to assume that a resource is a flat
> namespace. Thus, to resolve references in my DSL which is
> scoped, I've had to write an implementation of both IScopeProvider
> and IScope that allow nested namespaces within a resource.
> In TCS I had to just indicate which syntactic elements gave a
> scope and which elements were added to the current scope.
Yes, the flat scoping is the default.
The difference to the approach in TCS is, that we don't have any special
scoping syntax in the grammar DSL, but provide an orthogonal API
(IScopeProvider) to do it.
> The biggest issue I've faced with Xtext is parsing a multiplicity
> statement that supports specified (0..n), unspecified (?) and
> unbounded (*) values. The TCS function to parse this was
> not simple, but it did allow me to have simple numeric
> lowerBound and upperBound features.
>
> function multiplicity(ETypedElement) :
> (lowerBound = 0 and upperBound = -2
> ? "[" "?" "]"
> : (lowerBound = 0 and upperBound = 1
> ?
> : (lowerBound = 0 and upperBound = -1
> ? "[" "*" "]"
> : (lowerBound = 0 and upperBound = -1
> ? "[" "]"
> : (lowerBound = 1 and upperBound = -1
> ? "[" "+" "]"
> : (upperBound = -3 -- TODO equals lowerBound
> ? "[" lowerBound "]"
> : (upperBound = -1
> ? "[" lowerBound ".." "*" "]"
> : (upperBound = -2
> ? "[" lowerBound ".." "?" "]"
> : "[" lowerBound ".." upperBound"]"
> )
> )
> )
> )
> )
> )
> )
> );
>
> To do this in Xtext I've currently introduced the elements shown
> below into the meta-model and am about to write the m2m
> transformation that removes them from the meta-model that
> my application uses.
>
> ElementBound : SpecifiedBound | UnspecifiedBound | UnlimitedBound;
> SpecifiedBound : bound=INT;
> UnspecifiedBound : '?';
> UnlimitedBound : '*';
>
> ( '[' lowerBound=ElementBound ('..' upperBound=ElementBound)? ']' )?
>
Yes, we don't support assignment of literal values in actions.
Maybe we should consider adding support for that.
Feedback like this is vital to set the priorities right.
Thanks,
Sven
|
|
|
|
|
|
|
Re: [TCS] Grammar file ".g" [message #38560 is a reply to message #38071] |
Tue, 07 April 2009 02:53  |
Eclipse User |
|
|
|
It's just that Andy wants to set two features with one syntactic value
(i.e. * results in lowerBound=0 upperBound=-1)
So in this case value converters won't do the trick, at least if Andy
does not want to make a compromise either in the concrete or abstract
syntax.
Sebastian Zarnekow schrieb:
> Hi Andy,
>
> ValueConverters can be used with datatype rules, which are actually
> parser rules and therefore can call other parser rules:
>
> Cardinality:
> '[' lowerBound=ElementBound ('..' upperBound=ElementBound)? ']'
> ;
>
> ElementBound returns ecore::EInt: // datatype rule
> '*' | '?' | INT
> ;
>
> All you have to do is to register a ValueConverter for ElementBound.
>
> Regards,
> Sebastian
>
>
> Andy Carpenter schrieb:
>> "Krzysztof Kowalczyk" <kowalczyk.krzysztof@gmail.com> wrote in message
>> news:grd5l9$d5s$1@build.eclipse.org...
>>>> ElementBound : SpecifiedBound | UnspecifiedBound | UnlimitedBound;
>>>> SpecifiedBound : bound=INT;
>>>> UnspecifiedBound : '?';
>>>> UnlimitedBound : '*';
>>>>
>>>> ( '[' lowerBound=ElementBound ('..' upperBound=ElementBound)? ']' )?
>>>>
>>> I think you can define your own terminal rule like that
>>>
>>> terminal MULTI returns ecore::EInt : ('*'|'?'|('0'..'9')+);
>>>
>>> and use value converter
>>> (http://wiki.eclipse.org/Xtext/Documentation/ValueConverter). I
>>> suppose it would do the trick (not tested).
>>>
>>> Regards,
>>> Krzysztof Kowalczyk
>>
>> For a DSL developer, that's just moving around where they do
>> their implementation work. I'm also not sure that it would work
>> where an element in the list requires a grammar rule to
>> parse it.
>>
>> Andy.
>>
>>
|
|
|
Powered by
FUDForum. Page generated in 0.05334 seconds