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: 14732
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
;


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Day Job: https://www.everest-systems.com
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: 14732
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

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Day Job: https://www.everest-systems.com
Previous Topic:An internal error occurred during: "calculating highlighting".
Next Topic:JvmModelInferrer - Generate a method call
Goto Forum:
  


Current Time: Tue Nov 12 23:53:30 GMT 2024

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

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

Back to the top