Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Can't get a value from a variable
Can't get a value from a variable [message #1804152] Tue, 19 March 2019 13:21 Go to next message
Noslen Acesnof is currently offline Noslen AcesnofFriend
Messages: 23
Registered: February 2019
Junior Member
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]

Report message to a moderator

Re: Can't get a value from a variable [message #1804153 is a reply to message #1804152] Tue, 19 March 2019 13:36 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
hi,

please provide a complete minimal grammar and unit test
in your grammar i e.g. miss an assignment for TriggerDeclaration
e.g

decl=TriggerDeclaration


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Can't get a value from a variable [message #1804155 is a reply to message #1804153] Tue, 19 March 2019 13:59 Go to previous messageGo to next message
Noslen Acesnof is currently offline Noslen AcesnofFriend
Messages: 23
Registered: February 2019
Junior Member
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 #1804159 is a reply to message #1804155] Tue, 19 March 2019 14:53 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
how does REPO look like?

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Can't get a value from a variable [message #1804160 is a reply to message #1804159] Tue, 19 March 2019 14:55 Go to previous messageGo to next message
Noslen Acesnof is currently offline Noslen AcesnofFriend
Messages: 23
Registered: February 2019
Junior Member
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


noslen
Re: Can't get a value from a variable [message #1804161 is a reply to message #1804159] Tue, 19 March 2019 15:01 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
besides that this pattern you use all over the place

Repository:
'repositories' ':'
BEGIN
RepositoryDeclaration
END

and its bogus


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Can't get a value from a variable [message #1804162 is a reply to message #1804161] Tue, 19 March 2019 15:05 Go to previous messageGo to next message
Noslen Acesnof is currently offline Noslen AcesnofFriend
Messages: 23
Registered: February 2019
Junior Member
terminal BEGIN: 'synthetic:BEGIN';
terminal END: 'synthetic:END';


noslen
Re: Can't get a value from a variable [message #1804163 is a reply to message #1804161] Tue, 19 March 2019 15:05 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
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»
'''

)
}
}


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Can't get a value from a variable [message #1804168 is a reply to message #1804163] Tue, 19 March 2019 16:01 Go to previous message
Noslen Acesnof is currently offline Noslen AcesnofFriend
Messages: 23
Registered: February 2019
Junior Member
Thanks, with that test you helped me with the problem, and teach how to make a test :D

noslen
Previous Topic:Content Assist for Hidden Terminal Rules
Next Topic:XTEXT Custom Content Assist
Goto Forum:
  


Current Time: Wed Apr 24 13:40:46 GMT 2024

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

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

Back to the top