Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Error in creating fragment for STRING(Related with 'fragment STRING' definition in Xtext)
Error in creating fragment for STRING [message #1799725] Thu, 13 December 2018 03:09 Go to next message
P J is currently offline P JFriend
Messages: 64
Registered: October 2018
Member
Hi,
I have the below code for a DSL that I'm building using Xtext in Eclipse (I'm converting a .g4 file to Xetxt: -

Domainmodel:
	elements+=projection_name elements+=projection_component elements+=layer_specification
	elements+=description
;

projection_name
   : keywords+=KEYWORD_projection model_name+=projection_name_model_name punctuations+=SEMICOLON
   ;

projection_name_model_name
   : identifiers+=identifier2
   ;


projection_component
   : keywords+=KEYWORD_component component_name+=projection_component_component_name punctuations+=SEMICOLON
   ;

projection_component_component_name
   : identifier+=identifier2
   ;


layer_specification
   : keywords+=KEYWORD_layer layer_name+=layer_specification_layer_name punctuations+=SEMICOLON
   ;

layer_specification_layer_name
   : identifier+=identifier2
   ;


description
   : keywords+=KEYWORD_description string+=STRING punctuations+=SEMICOLON
   ;

KEYWORD_component
   : ( key='component' )
 
   ;


KEYWORD_description
   : ( key='description' )
 
   ;

KEYWORD_layer
   : ( key='layer' )
 
   ;

KEYWORD_projection
   : ( key='projection' )
 
   ;


fragment STRING
   : '"' ( ('\\'|'"') | ('\\'|'"'))* '"'
 
   ;

SEMICOLON
   : symbol=';'
 
   ;


identifier2
   : IDENTIFIER
   ;

projectionmainidentifier
   : IDENTIFIER
   ;

offlineexpressionidentifier
   : IDENTIFIER
   | KEYWORD_description
   | KEYWORD_projection
   ;

IDENTIFIER
   : name=ID
 
   ;


Everything is fine except for the 'fragment STRING' definition. The word 'STRING' gets underlined in red and states "A datatype rule cannot override a terminal rule."

Could you please tell me how this should be corrected?
Regards.

[Updated on: Thu, 13 December 2018 03:30]

Report message to a moderator

Re: Error in creating fragment for STRING [message #1799728 is a reply to message #1799725] Thu, 13 December 2018 04:04 Go to previous messageGo to next message
Karsten Thoms is currently offline Karsten ThomsFriend
Messages: 762
Registered: July 2009
Location: Dortmund, Germany
Senior Member

@Override 
terminal STRING
   : '"' ( ('\\'|'"') | ('\\'|'"'))* '"'
 
   ;
Re: Error in creating fragment for STRING [message #1799735 is a reply to message #1799728] Thu, 13 December 2018 08:12 Go to previous messageGo to next message
P J is currently offline P JFriend
Messages: 64
Registered: October 2018
Member
Thank you Karsten. After implementing the syntax you suggested, the artifacts are generated without errors. But when I try to type the syntax 'description' in runtime, I get the error that I have attached with this reply.
Could you kindly help me overcome this error?

Re: Error in creating fragment for STRING [message #1799738 is a reply to message #1799735] Thu, 13 December 2018 08:17 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
the fragment misses a NOT i think (have a look at the string rule in the superclass)
(i dont understand what your intention with that rule is)


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de

[Updated on: Thu, 13 December 2018 08:19]

Report message to a moderator

Re: Error in creating fragment for STRING [message #1799740 is a reply to message #1799735] Thu, 13 December 2018 08:24 Go to previous messageGo to next message
Karsten Thoms is currently offline Karsten ThomsFriend
Messages: 762
Registered: July 2009
Location: Dortmund, Germany
Senior Member

@Override 
terminal STRING
   : '"' ( '\\' . | !('\\'|'"') )* '"' 
   ;
Re: Error in creating fragment for STRING [message #1799744 is a reply to message #1799740] Thu, 13 December 2018 08:58 Go to previous messageGo to next message
P J is currently offline P JFriend
Messages: 64
Registered: October 2018
Member
Thank you Karsten and Christian! It is working fine now.
Re: Error in creating fragment for STRING [message #1799745 is a reply to message #1799744] Thu, 13 December 2018 09:00 Go to previous messageGo to next message
P J is currently offline P JFriend
Messages: 64
Registered: October 2018
Member
How can I find the definitions provided by Default in Xtext. e.g: the default definition given for STRING ?
Re: Error in creating fragment for STRING [message #1799746 is a reply to message #1799745] Thu, 13 December 2018 09:03 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
simply klick on the default terminal grammar name in the top

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Error in creating fragment for STRING [message #1799747 is a reply to message #1799746] Thu, 13 December 2018 09:11 Go to previous messageGo to next message
P J is currently offline P JFriend
Messages: 64
Registered: October 2018
Member
I tried this. But when I click on 'terminal STRING', what I get is:

TerminalRule STRING

ALERT_LINE_COMMENT : ( '//!' ('\r'|'\n')* ) ; QUESTION_LINE_COMMENT : ( '//?' ('\r'|'\n')* ) ; GOOD_LINE_COMMENT : ( '//=' ('\r'|'\n')* ) ; CHARACTER : ('\'') ('\'') ('\'') ; terminal TIME : ( ('0'..'9')+ ':' ('0'..'9')+ ) ;


This is, surprisingly, the syntax definitions (that are commented) I have mentioned above the terminal STRING rule!
The other thing I realized was that, when I removed the comments from the above said definitions, the default STRING is given just as 'TerminalRule STRING'. So I guess the definition I'm getting must be wrong, because whatever I put as comments above the terminal rule, will be displayed as its definition. Could you please help me with this problem?

[Updated on: Thu, 13 December 2018 09:21]

Report message to a moderator

Re: Error in creating fragment for STRING [message #1799753 is a reply to message #1799747] Thu, 13 December 2018 09:42 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
noooooooooo
i means this line:
!!!!!!!
grammar org.xtext.example.mydsl.MyDsl with org.eclipse.xtext.common.Terminals
!!!!!!!!!!


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Error in creating fragment for STRING [message #1799759 is a reply to message #1799753] Thu, 13 December 2018 10:17 Go to previous messageGo to next message
P J is currently offline P JFriend
Messages: 64
Registered: October 2018
Member
Do you mean the Rules listed down in the outline tab, as in the attached pictire below?
  • Attachment: xtext.png
    (Size: 93.77KB, Downloaded 85 times)
Re: Error in creating fragment for STRING [message #1799763 is a reply to message #1799759] Thu, 13 December 2018 10:36 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
no just move the cursor on the "org.eclipse.xtext.common.Terminals"
and F3 or crtl+click


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Error in creating fragment for STRING [message #1799765 is a reply to message #1799763] Thu, 13 December 2018 10:42 Go to previous message
P J is currently offline P JFriend
Messages: 64
Registered: October 2018
Member
Thank you Christian. Ctrl+click worked.
Previous Topic:Creating two xtext grammar files within one project
Next Topic:Adding Content Assist to Xtext Gradle Project
Goto Forum:
  


Current Time: Thu Apr 25 10:36:35 GMT 2024

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

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

Back to the top