Skip to main content



      Home
Home » Modeling » TMF (Xtext) » Converting fragment from Antlr to Xtext
Converting fragment from Antlr to Xtext [message #1765292] Thu, 08 June 2017 04:04 Go to next message
Eclipse UserFriend
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 04:50 Go to previous messageGo to next message
Eclipse UserFriend
did you consider an additional terminal aka

Scripting:
value=SCRIPT
;

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

terminal SCRIPT_ATOM:
! ('{' | '}')
| '"' (!'"')* '"'
| '//' !('\r'|'\n')*
| SCRIPT
;
Re: Converting fragment from Antlr to Xtext [message #1765302 is a reply to message #1765298] Thu, 08 June 2017 05:25 Go to previous messageGo to next message
Eclipse UserFriend
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 05:40 Go to previous message
Eclipse UserFriend
yes it helps. if you do scoping right or the default values are fine it will work out of the box
Previous Topic:An internal error occurred during: "calculating highlighting".
Next Topic:JvmModelInferrer - Generate a method call
Goto Forum:
  


Current Time: Tue Jul 08 06:16:28 EDT 2025

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

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

Back to the top