|
Re: General Problem with Grammar and Generator [message #1802816 is a reply to message #1802815] |
Sun, 17 February 2019 07:02 |
|
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
|
|
|
|
Powered by
FUDForum. Page generated in 0.01952 seconds