Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Converting fragment from Antlr to Xtext
Converting fragment from Antlr to Xtext [message #1765292] Thu, 08 June 2017 08:04 Go to next message
Udeshika Sewwandi is currently offline Udeshika SewwandiFriend
Messages: 118
Registered: March 2017
Senior Member
Hi

Can I create a fragment rule for the following Antlr fragment?
SCRIPT
 : '{' SCRIPT_ATOM* '}'
 ;

 fragment SCRIPT_ATOM
  : ~[{}]
  | '"' ~["]* '"'
  | '//' ~[\r\n]*
  | SCRIPT
  ;


I could create a terminal rule as follows.
SCRIPT:
	'{' SCRIPT_ATOM* '}'
;

terminal SCRIPT_ATOM:
  ! ('{' | '}')
  | '"' (!'"')* '"'
  | '//' !('\r'|'\n')*
  //| SCRIPT
;


But SCRIPT parser rule cannot be called inside the terminal rule. What needs to be done here?
Thank you.
Re: Converting fragment from Antlr to Xtext [message #1765298 is a reply to message #1765292] Thu, 08 June 2017 08:50 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14492
Registered: July 2009
Senior Member
did you consider an additional terminal aka

Scripting:
value=SCRIPT
;

terminal SCRIPT:
'{' SCRIPT_ATOM* '}'
;

terminal SCRIPT_ATOM:
! ('{' | '}')
| '"' (!'"')* '"'
| '//' !('\r'|'\n')*
| SCRIPT
;


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Converting fragment from Antlr to Xtext [message #1765302 is a reply to message #1765298] Thu, 08 June 2017 09:25 Go to previous messageGo to next message
Udeshika Sewwandi is currently offline Udeshika SewwandiFriend
Messages: 118
Registered: March 2017
Senior Member
The additional terminal for SCRIPT worked fine. :)

Does having cross references among the grammar rules helps in content assisting? I feel it's hard to maintain cross references in my grammar since it is a bit complex.

Thank you.
Re: Converting fragment from Antlr to Xtext [message #1765305 is a reply to message #1765302] Thu, 08 June 2017 09:40 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14492
Registered: July 2009
Senior Member
yes it helps. if you do scoping right or the default values are fine it will work out of the box

Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Previous Topic:An internal error occurred during: "calculating highlighting".
Next Topic:JvmModelInferrer - Generate a method call
Goto Forum:
  


Current Time: Thu Jun 01 14:01:38 GMT 2023

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

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

Back to the top