Skip to main content



      Home
Home » Modeling » TMF (Xtext) » problem with string rule and double quote rule
problem with string rule and double quote rule [message #900500] Tue, 07 August 2012 06:10 Go to next message
Eclipse UserFriend
Hi,

I'm working on a DSL and i have a problem on the rule

It's just a part of my dsl:


Program:
'program' name=DoubleQuoteID
Value=STRING
'end'
;
DoubleQuoteID:
('"'ID'"')
;

terminal ID : ('a'..'z'|'A'..'Z') ('a'..'z'|'A'..'Z'|'0'..'9')*;

terminal STRING :
'"' ( '\\' ('b'|'t'|'n'|'f'|'r'|'u'|'"'|"'"|'\\') | !('\\'|'"') )* '"' |
"'" ( '\\' ('b'|'t'|'n'|'f'|'r'|'u'|'"'|"'"|'\\') | !('\\'|"'") )* "'"
;

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

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



I use to in parallel Xtend for realise junit test

My test :


class test{
@Inject extension ParseHelper<Program>


@Test def void testBadProgramDeclaration() {
val program =
'''
program toto
"abc"
end
'''.parse

Assert::assertNotNull(program)
Assert::assertEquals("toto",program.name)//test pass but it shouldn't pass
Assert::assertEquals("abc",program.value)
}
@Test def void testGoodProgramDeclaration() {
val program =
'''
program "toto"
"abc"
end
'''.parse

Assert::assertNotNull(program)
Assert::assertEquals("toto",program.name)// FAILED ==> expected:<toto> but was:<null>
Assert::assertEquals("abc",program.value)
}
}



I have a problem with the rule DoubleQuoteID because Double quote are obligatory but it's not define obligatory

I can't create a terminal for DoubledQuoteID because it create conflict with String rule


I don't know how i can do it

I'm new to Xtext and so this question might be quite stupid. Maybe somebody has an idea or can point me into the right direction? Thanks in advance!

Best regards,
Jérôme
Re: problem with string rule and double quote rule [message #900505 is a reply to message #900500] Tue, 07 August 2012 06:23 Go to previous messageGo to next message
Eclipse UserFriend
Hi Jerome,

A DoubleQuoteID is a STRING, so the parser recognizes the more general rule.

I would define the name as a STRING and use a validation rule to check that the contents is a valid ID.

regards,
Vlad
Re: problem with string rule and double quote rule [message #900772 is a reply to message #900505] Wed, 08 August 2012 08:50 Go to previous message
Eclipse UserFriend
thank you for your help
Previous Topic:How does the Serializer work? Reg. NFA + NodeModel
Next Topic:Rename/Move Resource refactoring for importURI-style includes
Goto Forum:
  


Current Time: Sun Jul 13 10:56:55 EDT 2025

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

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

Back to the top