Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » problem for define my dsl
problem for define my dsl [message #931957] Wed, 03 October 2012 17:38 Go to next message
Laigle jérôme is currently offline Laigle jérômeFriend
Messages: 26
Registered: August 2012
Junior Member
Hi,

I'm working on a DSL but i have a problem with my grammar

It's just a few part of my dsl but i have some conflit between OnErrorGoto and OnGoto

CompilationUnit:
abalElements+=AbalElement*;

AbalElement:
OnErrorGoto|OnGoto|VariableDeclaration|Etiquette
;

OnErrorGoto:
('on local error goto'| 'on error goto')'&'etiquette=[Etiquette]
;
OnGoto:
'on' variable=[Symbol]'goto' ('(''&'etiquette+=[Etiquette] (',' '&' etiquette+=[Etiquette])* ')')?
;
Etiquette :
'&'name=ID
;
VariableDeclaration returns Symbol:
'dcl' name= ID
('endloc')?('[,S]')?
;

terminal ID : ( ('a'..'z'|'A'..'Z'|'_')) (('a'..'z'|'A'..'Z'|'_'|'0'..'9'|'#'|'$'|'%'|'?'))*;

terminal SL_COMMENT : (';') !('\n'|'\r')* ('\r'? '\n')?;

terminal WS : (' '|'\t'|'\r'|'\n')+;


I do junit test

@RunWith(typeof(XtextRunner))
@InjectWith(typeof(LanguageInjectorProvider))

class test{
@Inject extension ParseHelper<CompilationUnit>
@Test def void testOnGoto() {
val compilationUnit =
'''
on choix goto (&saisie,&imprime,&suite)
dcl choix
&saisie
&imprime
&suite

'''.parse

val abalElement = compilationUnit.abalElements.head
val onGoto=abalElement as OnGoto
val variable=onGoto.variable as Symbol
Assert::assertEquals("choix",variable.name)
Assert::assertEquals("saisie",onGoto.etiquette.get(0).name)
Assert::assertEquals("imprime",onGoto.etiquette.get(1).name)
Assert::assertEquals("suite",onGoto.etiquette.get(2).name)

}
}


And test returned a failure trace Null Pointer Exception

I don't know what is the solution
Maybe somebody has an idea or can point me into the right direction? Thanks in advance!

Best regards,
Jérôme
Re: problem for define my dsl [message #932220 is a reply to message #931957] Wed, 03 October 2012 23:50 Go to previous message
Sebastian Zarnekow is currently offline Sebastian ZarnekowFriend
Messages: 3118
Registered: July 2009
Senior Member
Hi Jerome,

please try to avoid keywords that contains spaces, e.g. use
'on' 'error' 'goto'
instead of
'on error goto'

That should help.

Regards,
Sebastian
--
Looking for professional support for Xtext, Xtend or Eclipse Modeling?
Go visit: http://xtext.itemis.com

Am 03.10.12 10:38, schrieb Laigle jérôme:
> Hi,
>
> I'm working on a DSL but i have a problem with my grammar
> It's just a few part of my dsl but i have some conflit between
> OnErrorGoto and OnGoto
>
> CompilationUnit:
> abalElements+=AbalElement*;
>
> AbalElement:
> OnErrorGoto|OnGoto|VariableDeclaration|Etiquette
> ;
>
> OnErrorGoto:
> ('on local error goto'| 'on error goto')'&'etiquette=[Etiquette] ;
> OnGoto:
> 'on' variable=[Symbol]'goto' ('(''&'etiquette+=[Etiquette] (','
> '&' etiquette+=[Etiquette])* ')')?
> ;
> Etiquette :
> '&'name=ID
> ;
> VariableDeclaration returns Symbol:
> 'dcl' name= ID ('endloc')?('[,S]')?
> ;
>
> terminal ID : ( ('a'..'z'|'A'..'Z'|'_'))
> (('a'..'z'|'A'..'Z'|'_'|'0'..'9'|'#'|'$'|'%'|'?'))*;
>
> terminal SL_COMMENT : (';') !('\n'|'\r')* ('\r'? '\n')?;
>
> terminal WS : (' '|'\t'|'\r'|'\n')+;
>
>
> I do junit test
> @RunWith(typeof(XtextRunner)) @InjectWith(typeof(LanguageInjectorProvider))
>
> class test{
> @Inject extension ParseHelper<CompilationUnit>
> @Test def void testOnGoto() {
> val compilationUnit = '''
> on choix goto (&saisie,&imprime,&suite)
> dcl choix
> &saisie
> &imprime
> &suite
> '''.parse
>
> val abalElement = compilationUnit.abalElements.head
> val onGoto=abalElement as OnGoto
> val variable=onGoto.variable as Symbol
> Assert::assertEquals("choix",variable.name)
> Assert::assertEquals("saisie",onGoto.etiquette.get(0).name)
> Assert::assertEquals("imprime",onGoto.etiquette.get(1).name)
> Assert::assertEquals("suite",onGoto.etiquette.get(2).name)
>
> }
> }
>
>
> And test returned a failure trace Null Pointer Exception
>
> I don't know what is the solution
> Maybe somebody has an idea or can point me into the right direction?
> Thanks in advance!
>
> Best regards,
> Jérôme
Previous Topic:Concrete syntax vs desired model structure
Next Topic:Exception with ResourceSetBasedResourceDescriptions occurs
Goto Forum:
  


Current Time: Tue Apr 16 20:54:03 GMT 2024

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

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

Back to the top