Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Use ANTLR grammar within Xtext
Use ANTLR grammar within Xtext [message #958257] Thu, 25 October 2012 22:04 Go to next message
Frank Schrank is currently offline Frank SchrankFriend
Messages: 4
Registered: October 2012
Junior Member
Greetings!
A simple question in addition to my other thread: Can I somehow reuse an already existing ANTLR grammar within Xtext? (or do I have to define it anew with the Xtext grammar language?)

Here's an excerpt of what my grammar looks like:
...
fragment operationBlock
  : deleteWorkspaceOperation 
  | ( (createWorkspaceOperation | selectWorkspaceOperation) dataOperation* )
  ;

fragment dataOperation
  : assignOperation
  | upsertOperation 
  ;

//namespace  
fragment namespaceDeclarationBlock 
  : defaultNamespaceDeclaration? namespaceDeclaration*
    //-> defaultNamespaceDeclaration? namespaceDeclaration*
  ;
  
defaultNamespaceDeclaration 
  : DEFAULT NAMESPACE uri SEMI
    -> ^(NAMESPACE uri)
  ;
...


Thank you,
best regards

[Updated on: Fri, 26 October 2012 18:02]

Report message to a moderator

Re: Use ANTLR grammar within Xtext [message #958540 is a reply to message #958257] Fri, 26 October 2012 03:24 Go to previous messageGo to next message
Henrik Lindberg is currently offline Henrik LindbergFriend
Messages: 2509
Registered: July 2009
Senior Member
Yes, more or less. You can have a separate "external lexer" if your
lexing needs are more advanced than what the .xtext grammar allows.

Everything in antlr is not supported in .xtext grammars.

- henrik

On 2012-26-10 24:04, Frank Schrank wrote:
> Greetings!
> A simple question in addition to
> http://www.eclipse.org/forums/index.php/t/414240/: Can I somehow reuse
> an already existing ANTLR grammar within Xtext? (or do I have to define
> it anew with the Xtext grammar language?)
>
> Here's an excerpt of what my grammar looks like:
>
> ...
> fragment operationBlock
> : deleteWorkspaceOperation | ( (createWorkspaceOperation |
> selectWorkspaceOperation) dataOperation* )
> ;
>
> fragment dataOperation
> : assignOperation
> | upsertOperation ;
>
> //namespace fragment namespaceDeclarationBlock :
> defaultNamespaceDeclaration? namespaceDeclaration*
> //-> defaultNamespaceDeclaration? namespaceDeclaration*
> ;
>
> defaultNamespaceDeclaration : DEFAULT NAMESPACE uri SEMI
> -> ^(NAMESPACE uri)
> ;
> ...
>
>
> Thank you,
> best regards,
> Hannes
Re: Use ANTLR grammar within Xtext [message #959685 is a reply to message #958540] Fri, 26 October 2012 22:53 Go to previous messageGo to next message
Frank Schrank is currently offline Frank SchrankFriend
Messages: 4
Registered: October 2012
Junior Member
Hello Henrik,
and thank you for this information. Just to get this clear: So it is not possible, to simply take the ANTLR grammar I have and use it instead of translating it into a .text grammar?
I think .xtext provides all the functionality I need, I just wanted to know, whether I could conveniently reuse the ANTLR grammar I already have before going through the effort of defining the language a second time.
Re: Use ANTLR grammar within Xtext [message #959819 is a reply to message #959685] Sat, 27 October 2012 01:28 Go to previous messageGo to next message
Henrik Lindberg is currently offline Henrik LindbergFriend
Messages: 2509
Registered: July 2009
Senior Member
On 2012-27-10 24:53, Frank Schrank wrote:
> Hello Henrik,
> and thank you for this information. Just to get this clear: So it is not
> possible, to simply take the ANTLR grammar I have and use it instead of
> translating it into a .text grammar?
> I think .xtext provides all the functionality I need, I just wanted to
> know, whether I could conveniently reuse the ANTLR grammar I already
> have before going through the effort of defining the language a second
> time.
>
Hi,
read my response again, my 'yes' was quite ambiguous.

so...

No, you can not reuse the ANTLR grammar.
You may be able to reuse some of the lexer rules.

There are good reasons for this - an ANTLR grammar allows you to do many
things that are not declarative and hence difficult (i.e. impossible) to
generate default implementations for.

Unless your grammar is terribly complex, it should not be that difficult
to re-implement.

Regards
- henrik
Re: Use ANTLR grammar within Xtext [message #963256 is a reply to message #959819] Mon, 29 October 2012 17:28 Go to previous message
Frank Schrank is currently offline Frank SchrankFriend
Messages: 4
Registered: October 2012
Junior Member
Dear Henrik,
thanks again - this time it was really clear.
With best regards
Previous Topic:Customize proposals of a grammar
Next Topic:Referencing elements in an external file (with a different grammar)
Goto Forum:
  


Current Time: Fri Apr 26 16:30:58 GMT 2024

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

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

Back to the top