Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » What is wrong with my simple grammar ?
What is wrong with my simple grammar ? [message #1064902] Fri, 21 June 2013 14:59 Go to next message
Vincent De Bry is currently offline Vincent De BryFriend
Messages: 55
Registered: May 2013
Member
Hi,

I'm trying to define a grammar able to support writing the following text:
--NECST HEADER Scripts
#NESCT START
#NECST MIDDLE [free_text1][free_text2]

    --NECST ONE Script
    --NECST TWO Script

#NECST EXIT


For that, I have define the following grammar:
grammar org.xtext.example.mydsl.MyDsl with org.eclipse.xtext.common.Terminals hidden (NECST_PARAM)

generate myDsl "http://www.xtext.org/example/mydsl/MyDsl"

Model:{Model}
	'--NECST HEADER Scripts'
	(commentNecst+=CommandNecst*)?
	scripts+=Script+;
	
CommandNecst:
	'#NECST' command=ENUM_COMMANDNECST param+=NECST_PARAM*;
enum ENUM_COMMANDNECST : START|MIDDLE|EXIT;

Script:
	'--NECST' script=ENUM_SCRIPT 'Script'
;
enum ENUM_SCRIPT : ONE|TWO|THREE;

terminal NECST_PARAM : '[' -> ']';


But, I am not able to type anything after the first line.
What is wrong ?

Thanks
Re: What is wrong with my simple grammar ? [message #1064907 is a reply to message #1064902] Fri, 21 June 2013 15:15 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi,

the problem is the hidden statement it should include ws and others. besides ws in keywords is a bad idea

grammar org.xtext.example.mydsl.MyDsl with org.eclipse.xtext.common.Terminals hidden (NECST_PARAM,WS, ML_COMMENT, SL_COMMENT)

generate myDsl "http://www.xtext.org/example/mydsl/MyDsl"

Model:{Model}
	'--NECST' 'HEADER' 'Scripts'
	(commentNecst+=CommandNecst*)
	scripts+=Script+;
	
CommandNecst:
	'#NECST' command=ENUM_COMMANDNECST param+=NECST_PARAM*;
enum ENUM_COMMANDNECST : START|MIDDLE|EXIT;

Script:
	'--NECST' script=ENUM_SCRIPT 'Script'
;
enum ENUM_SCRIPT : ONE|TWO|THREE;

terminal NECST_PARAM : '[' -> ']';


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: What is wrong with my simple grammar ? [message #1064924 is a reply to message #1064907] Fri, 21 June 2013 16:31 Go to previous messageGo to next message
Vincent De Bry is currently offline Vincent De BryFriend
Messages: 55
Registered: May 2013
Member
Great Christian, Thanks !

I am now able to write the beginning of my file, except the final "#NECST EXIT".
Can you give me a tip for this issue ?

Thanks
Re: What is wrong with my simple grammar ? [message #1064939 is a reply to message #1064924] Fri, 21 June 2013 17:57 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
your grammar says the file ends with scripts

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: What is wrong with my simple grammar ? [message #1064950 is a reply to message #1064939] Fri, 21 June 2013 21:02 Go to previous messageGo to next message
Vincent De Bry is currently offline Vincent De BryFriend
Messages: 55
Registered: May 2013
Member
Ok, so I've tried the following:

grammar org.xtext.example.mydsl.MyDsl with org.eclipse.xtext.common.Terminals hidden (NECST_PARAM,WS, ML_COMMENT, SL_COMMENT)

generate myDsl "http://www.xtext.org/example/mydsl/MyDsl"

Model:{Model}
	'--NECST' 'HEADER' 'Scripts'
	commandNecst+=CommandNecst*
	script+=Script+
	e=Exit
;

CommandNecst:
	'#NECST' command=ENUM_COMMANDNECST param+=NECST_PARAM*;
enum ENUM_COMMANDNECST : START|MIDDLE;

Exit:
	'#NECST' 'EXIT'
;

Script:
	'--NECST' script=ENUM_SCRIPT 'Script'
;
enum ENUM_SCRIPT : ON|TWO|THREE;

terminal NECST_PARAM : '[' -> ']';

But after having typed some "Script", the content assist keeps proposing me other "Script" but no "Exit" rule;and I don't know how to do so.

Any Idea ?
Thanks
Re: What is wrong with my simple grammar ? [message #1064958 is a reply to message #1064950] Fri, 21 June 2013 22:07 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi,

you have to define content assist for custom datatype rules yourself by implementing the corresponding method in the proposalprovider
alternatively you can change the datatype rule to a real parser rule e.g.

Exit:
{Exit} '#NECST' 'EXIT'
;


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: What is wrong with my simple grammar ? [message #1064969 is a reply to message #1064958] Sat, 22 June 2013 08:12 Go to previous message
Vincent De Bry is currently offline Vincent De BryFriend
Messages: 55
Registered: May 2013
Member
Thank you very much Christian, that works fine now !
Previous Topic:Xtext validation on closed files
Next Topic:LLVM Suport
Goto Forum:
  


Current Time: Tue Apr 23 16:01:22 GMT 2024

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

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

Back to the top