Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » General Problem with Grammar and Generator
General Problem with Grammar and Generator [message #1802815] Sun, 17 February 2019 06:34 Go to next message
Markus Häge is currently offline Markus HägeFriend
Messages: 56
Registered: August 2018
Member
Hello again,
I tried a while to create a grammar and a generator for my thesis but get stucked. The Editor would do what I want, but the Generator doesn't find the needed item. I think there is a general problem in how to invent a language.
The Language is for Testing. I create Testcases for a framework. Mainly i call functions with arguments. Let's say I have PreCon, PostAction and TestStep.
In Teststep i have

TestStep:
'TestStep' '{'
number = INT '|'
act = (Function | ProjectFunction) '|'

react = CANOEFunction
'}'
;
Function:
name = 'WaitForMessage'
msg = Message
waittime = INT 'ms'|

name = 'WaitForTimeout'
waittime = INT 'ms' |

name = 'WaitForSignal'
//msg = Message
sig = MsgSignal
waittime = INT 'ms'

;

MsgSignal:
name = 'Msg1'
signal = (sig1| sig2) |

name = 'Mgs2'
signal = (sig1| sig2| sig3)
;

sig1:
name = 'name1'

option = ('opt1' |
'opt2' |
'op3' |
'opt4')
;

My generator doesn't find msgSignal.name or anything below this like msgsignal.option.
Maybe i need another way to declare my gramar or a function from the generator which i don't find.

thanks
Markus
Re: General Problem with Grammar and Generator [message #1802816 is a reply to message #1802815] Sun, 17 February 2019 07:02 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
hmmm your dsl looks quite static and unusal. and the grammar snippet is incomplete. if it even is a grammar

using this test i cannot reproduce your problem. so can you provide more context?

TestStep:
'TestStep' '{'
number = INT '|'
act = (Function) 

'}'
;
Function:
name = 'WaitForSignal'
//msg = Message
sig = MsgSignal
waittime = INT 'ms'

;

MsgSignal:
name = 'Msg1'
signal = (sig1| sig2) |

name = 'Mgs2'
signal = (sig1| sig2| sig3)
;

sig1: name = 'name1'

option = ('opt1' |
'opt2' |
'op3' |
'opt4')
;

sig2: name = 'name2'

option = ('opt1' |
'opt2' |
'op3' |
'opt4')
;

sig3: name = 'name3'

option = ('opt1' |
'opt2' |
'op3' |
'opt4')
;


@Test
	def void loadModel() {
		val result = parseHelper.parse('''
			TestStep {
				0|
				WaitForSignal
				Msg1
				name1
				opt4
				2 ms
			}
		''')
		Assertions.assertNotNull(result)
		val errors = result.eResource.errors
		Assertions.assertTrue(errors.isEmpty, '''Unexpected errors: «errors.join(", ")»''')
		val msgSignal =
		result.act.sig
		println(msgSignal.name)
		println(msgSignal.signal)
		println((msgSignal.signal as sig1).name)
		println((msgSignal.signal as sig1).option)
	}


as you can see your grammar regarding sigs is bad.
but that is the part of the grammar you dont show.
i dont know why you hardcode so much stuff into the grammar
instead of doing it via validation

you can also introduce uncalled rules to tweak the metamodel a bit

AbstractSignal:
	sig1|sig2|sig3
;


		println(msgSignal.signal.name)
		println(msgSignal.signal.option)


i assume you have the abstract problem already on functions level


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

[Updated on: Sun, 17 February 2019 07:06]

Report message to a moderator

Re: General Problem with Grammar and Generator [message #1802817 is a reply to message #1802816] Sun, 17 February 2019 07:17 Go to previous message
Markus Häge is currently offline Markus HägeFriend
Messages: 56
Registered: August 2018
Member
Hi,
Thanks for the advice.
I just read about validation, never used it. The first approach was the grammar.

Markus
Previous Topic:Modify template proposal description
Next Topic:Broken Build when changing grammar with org.eclipse.xtext.xbase.Xbase
Goto Forum:
  


Current Time: Thu Apr 18 16:19:30 GMT 2024

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

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

Back to the top