Can't get a value from a variable [message #1804152] |
Tue, 19 March 2019 13:21  |
Eclipse User |
|
|
|
Hello,
I'm having a problem to get a value from a variable. My "reduced" grammar is this:
Trigger:
{Trigger} 'trigger' (manual=MANUAL)? | ('cron' cronExpression=STRING)?
BEGIN
TriggerDeclaration
END
;
And when I'm trying to get the value of cronExpression I'm receive a null value. (yes, when I'm creating a script in my DSL I specify the value).
Here you can see how I'm trying to get the value in generator:
«IF p.elements.filter(Pipeline).get(0).repo.filter(RepositoryDeclaration).get(0).repoComp.get(0).cronExpression!==null»
"timer": {
"only_on_changes": false
},
«ENDIF»
And here you can find a example of my DSL:
trigger cron "0 * * ? * *"
git "https://github.com/...
[Updated on: Tue, 19 March 2019 13:28] by Moderator Report message to a moderator
|
|
|
|
Re: Can't get a value from a variable [message #1804155 is a reply to message #1804153] |
Tue, 19 March 2019 13:59   |
Eclipse User |
|
|
|
Here you can find a minimal grammar:
Program:
(elements+=ProgramElements)+
;
ProgramElements:
Pipeline
;
Pipeline:
'pipeline' name=ID ':'
(BEGIN
(repo+=Repository )*
END)?
;
Repository:
'repositories' ':'
BEGIN
RepositoryDeclaration
END
;
RepositoryDeclaration:
( repoComp+=Trigger | repoDef+=RepoDef )*
;
RepoDef:
(repo=REPO) url=STRING ('to' locationToSave=STRING)? ('login' username=STRING':'password=STRING)?
;
Trigger:
'trigger' (manual=MANUAL)? | ('cron' cronExpression=STRING)?
BEGIN
RepoDef
END
;
terminal MANUAL: 'manual';
I'm trying to discover a little bit more about xtext/xtend so I don't know how to do a unit test, but if I program this in my DSL:
pipeline potatos:
repositories :
trigger cron "0 * * ? * *"
git "https://githubs.com/..." to "appless"
git "https://github.com/..." to "potatos"
Should generate:
...
"timer": {
"only_on_changes": false
}
...
It's strange why this don't work, because when is supposed to have the "manual" value I can get it.
|
|
|
|
Re: Can't get a value from a variable [message #1804160 is a reply to message #1804159] |
Tue, 19 March 2019 14:55   |
Eclipse User |
|
|
|
Sorry, I forgot that one
terminal REPO: 'git' | 'svn' ;
But I found that the problem isn't in "cronExpression" variable, because if I switch order with "manual" variable I can get the value from "cronExpression" but I loose the access of the "manual" variable
|
|
|
|
|
Re: Can't get a value from a variable [message #1804163 is a reply to message #1804161] |
Tue, 19 March 2019 15:05   |
Eclipse User |
|
|
|
e.g. chaning this
Trigger:
'trigger' (manual=MANUAL)? | ('cron' cronExpression=STRING)?
BEGIN
def=RepoDef
END
;
will allow
/*
* generated by Xtext 2.17.0
*/
package org.xtext.example.mydsl.tests
import com.google.inject.Inject
import org.eclipse.xtext.testing.InjectWith
import org.eclipse.xtext.testing.extensions.InjectionExtension
import org.eclipse.xtext.testing.util.ParseHelper
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.^extension.ExtendWith
import org.xtext.example.mydsl.myDsl.Program
import org.xtext.example.mydsl.myDsl.Pipeline
import org.xtext.example.mydsl.myDsl.RepositoryDeclaration
@ExtendWith(InjectionExtension)
@InjectWith(MyDslInjectorProvider)
class MyDslParsingTest {
@Inject
ParseHelper<Program> parseHelper
@Test
def void loadModel() {
val result = parseHelper.parse('''
pipeline potatos:
repositories :
trigger cron "0 * * ? * *"
git "https://githubs.com/..." to "appless"
git "https://github.com/..." to "potatos"
''')
Assertions.assertNotNull(result)
val errors = result.eResource.errors
Assertions.assertTrue(errors.isEmpty, '''Unexpected errors: «errors.join(", ")»''')
println(
'''
«FOR e : result.elements»
«IF e instanceof Pipeline»
p: «e.name»
«FOR r : e.repo»
r:
«IF r instanceof RepositoryDeclaration»
triggers:
«FOR x : r.repoComp »
manual «x.manual»
cron «x.cronExpression»
repo «x.def.repo»
url «x.def.url»
locationToSave «x.def.locationToSave»
username «x.def.username»
password «x.def.password»
«ENDFOR»
reposdef:
«FOR x : r.repoDef»
repo «x.repo»
url «x.url»
locationToSave «x.locationToSave»
username «x.username»
password «x.password»
«ENDFOR»
«ENDIF»
«ENDFOR»
«ENDIF»
«ENDFOR»
'''
)
}
}
|
|
|
|
Powered by
FUDForum. Page generated in 0.03995 seconds