problem for define my dsl [message #931957] |
Wed, 03 October 2012 13:38  |
Eclipse User |
|
|
|
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 19:50  |
Eclipse User |
|
|
|
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
|
|
|
Powered by
FUDForum. Page generated in 0.05139 seconds