Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Terminals overriding
icon5.gif  Terminals overriding [message #774258] Tue, 03 January 2012 15:57 Go to next message
Jeff MAURY is currently offline Jeff MAURYFriend
Messages: 44
Registered: July 2009
Member
I have a grammar that uses the Terminals standard definitions (ID, STRING).
However, I am facing the following issue:
the ID definition allows for _ and not - and my grammar needs to accept - and not _.
So I defined a new terminal MyID.
But parsing fails on a specific optional because I suspect the lexer returns an ID instead of an MyID token.
I tried to redefine ID in my grammar but there is a side effect on the ProposalProvider. If you want proposal for ID, you need to defined a method complete_ID but there is no way to reuse the complete_ID method from TerminalsProposalProvider.

What solution do you suggest ?

Regards
Jeff
Re: Terminals overriding [message #774440 is a reply to message #774258] Tue, 03 January 2012 23:19 Go to previous messageGo to next message
Henrik Lindberg is currently offline Henrik LindbergFriend
Messages: 2509
Registered: July 2009
Senior Member
The idea is that you should override the ID (or for that matter make a
copy of all the terminals and change what you like - i.e. not use the
built in ones at all - more responsibility, but full control).

What is it that does not work exactly when you override ID to include
'-' instead of/in addition to '_' ?

Proposals for ID are typically performed when there is a reference, not
where the ID is specified - it is typically a name, which could be just
about anything - just like for all other terminals.

Regards
- henrik

On 2012-03-01 16:57, Jeff MAURY wrote:
> I have a grammar that uses the Terminals standard definitions (ID, STRING).
> However, I am facing the following issue:
> the ID definition allows for _ and not - and my grammar needs to accept
> - and not _.
> So I defined a new terminal MyID.
> But parsing fails on a specific optional because I suspect the lexer
> returns an ID instead of an MyID token.
> I tried to redefine ID in my grammar but there is a side effect on the
> ProposalProvider. If you want proposal for ID, you need to defined a
> method complete_ID but there is no way to reuse the complete_ID method
> from TerminalsProposalProvider.
>
> What solution do you suggest ?
>
> Regards
> Jeff
>
Re: Terminals overriding [message #774606 is a reply to message #774440] Wed, 04 January 2012 09:19 Go to previous messageGo to next message
Jeff MAURY is currently offline Jeff MAURYFriend
Messages: 44
Registered: July 2009
Member
The problem when you override ID in your own grammar is that the complete_ID method is defined in AbstractMyDslProposalProvider (as empty) and should be defined in MyDslProposalProvider.
My aim is to reuse the code from TerminalsProposalProvider but there is no way to do it as there is no way in Java to call a method from a grand parent class. So the only solution is see it to copy/paste the code from TerminalsProposalProvider into MyDslProposalProvider which is very bad in terms of code reuse and technical debt.
Re: Terminals overriding [message #774799 is a reply to message #774606] Wed, 04 January 2012 16:33 Go to previous message
Henrik Lindberg is currently offline Henrik LindbergFriend
Messages: 2509
Registered: July 2009
Senior Member
On 2012-04-01 10:19, Jeff MAURY wrote:
> The problem when you override ID in your own grammar is that the
> complete_ID method is defined in AbstractMyDslProposalProvider (as
> empty) and should be defined in MyDslProposalProvider.
> My aim is to reuse the code from TerminalsProposalProvider but there is
> no way to do it as there is no way in Java to call a method from a grand
> parent class. So the only solution is see it to copy/paste the code from
> TerminalsProposalProvider into MyDslProposalProvider which is very bad
> in terms of code reuse and technical debt.

You could inject TerminalsProposalProvider and delegate to it instead of
copying.

Regards
- henrik
Previous Topic:syntax sugar for creating EMF objects in Xbase
Next Topic:How to infer Java enum
Goto Forum:
  


Current Time: Tue Apr 23 09:49:46 GMT 2024

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

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

Back to the top