Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » problem for define dsl
problem for define dsl [message #932973] Thu, 04 October 2012 16:15 Go to next message
Laigle jérôme is currently offline Laigle jérômeFriend
Messages: 26
Registered: August 2012
Junior Member
hi,

i want that my dsl support this type of declaration
dcl num%, num2#,num3.....
but i have a problem with PauseSymbolRef


CompilationUnit:
abalElements+=AbalElement*;

AbalElement:
VariableDeclaration|PauseSymbolRef
;

VariableDeclaration returns Symbol:
'dcl' name+= ID type+=Type (','name+= ID type+=Type)*
('endloc')?('[,S]')?
;
PauseSymbolRef :
'pause' symbol=[Symbol]
;
Type:
ShortNumericType | NumericType | StringType |BCDType
;

ShortNumericType:
{ShortNumericType}'#';

NumericType:
{NumericType}'%';


StringType:
{StringType}'$'('='size=INT)?
;

BCDType:
{BCDType}('='size=INT)?;

terminal INT returns ecore::EInt: ('0'..'9')+;

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 realised JUnit test :

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

class test{
@Inject extension ParseHelper<CompilationUnit>
@Test def void testOnTimerGoto() {
val compilationUnit =
'''

dcl choix %
pause choix
'''.parse

val abalElement = compilationUnit.abalElements.head
val symbol=abalElement as Symbol
//val variable=onTimerGoto.variable as Symbol
Assert::assertEquals("choix",symbol.name.get(0))
//Assert::assertEquals("num",symbol.name.get(1))
val abalElement1 = compilationUnit.abalElements.get(1)
val pause=abalElement1 as PauseSymbolRef
print(pause.symbol.name)
Assert::assertEquals("choix",pause.symbol.name.get(0))
}

}
but test termined with the failure trace
because pause.symbol.name is empty

i tried to do 'pause' symbol+=[Symbol]
but test failed also

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 dsl [message #933014 is a reply to message #932973] Thu, 04 October 2012 16:49 Go to previous message
Henrik Lindberg is currently offline Henrik LindbergFriend
Messages: 2509
Registered: July 2009
Senior Member
Symbol has a List as its name, that does not work when you are trying to
find it by matching an ID against this list.

Try something like this perhaps (this is just a guess, as not clear what
you were trying to do).

VariableDeclaration :
'dcl' symbols+=Symbol (','symbols += Symbol)*
('endloc')?('[,S]')?
;

Symbol : name = ID type=Type ;

PauseSymbolRef : 'pause' symbol=[Symbol];

Regards
- henrik

On 2012-04-10 18:15, Laigle jérôme wrote:
> hi,
>
> i want that my dsl support this type of declaration dcl num%,
> num2#,num3.....
> but i have a problem with PauseSymbolRef
>
>
> CompilationUnit:
> abalElements+=AbalElement*;
>
> AbalElement:
> VariableDeclaration|PauseSymbolRef
> ;
>
> VariableDeclaration returns Symbol:
> 'dcl' name+= ID type+=Type (','name+= ID type+=Type)*
> ('endloc')?('[,S]')?
> ;
> PauseSymbolRef :
> 'pause' symbol=[Symbol]
> ;
> Type:
> ShortNumericType | NumericType | StringType |BCDType
> ;
>
> ShortNumericType:
> {ShortNumericType}'#';
>
> NumericType:
> {NumericType}'%';
>
>
> StringType:
> {StringType}'$'('='size=INT)?
> ;
>
> BCDType:
> {BCDType}('='size=INT)?;
>
> terminal INT returns ecore::EInt: ('0'..'9')+;
>
> 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 realised JUnit test :
>
> @RunWith(typeof(XtextRunner)) @InjectWith(typeof(LanguageInjectorProvider))
>
> class test{
> @Inject extension ParseHelper<CompilationUnit>
> @Test def void testOnTimerGoto() {
> val compilationUnit = '''
> dcl choix %
> pause choix '''.parse
>
> val abalElement = compilationUnit.abalElements.head
> val symbol=abalElement as Symbol
> //val variable=onTimerGoto.variable as Symbol
> Assert::assertEquals("choix",symbol.name.get(0))
> //Assert::assertEquals("num",symbol.name.get(1))
> val abalElement1 = compilationUnit.abalElements.get(1)
> val pause=abalElement1 as PauseSymbolRef
> print(pause.symbol.name)
> Assert::assertEquals("choix",pause.symbol.name.get(0))
> }
>
> }
> but test termined with the failure trace
> because pause.symbol.name is empty
>
> i tried to do 'pause' symbol+=[Symbol]
> but test failed also
>
> 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:Recursive iQualifiedName
Next Topic:Why isn't compiled class cached in CompilationTestHelper.compile?
Goto Forum:
  


Current Time: Thu Apr 25 09:25:58 GMT 2024

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

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

Back to the top