Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    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 10:10 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 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 10:23 Go to previous messageGo to next message
Vlad Dumitrescu is currently offline Vlad DumitrescuFriend
Messages: 431
Registered: July 2009
Location: Gothenburg
Senior Member
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 12:50 Go to previous message
Laigle jérôme is currently offline Laigle jérômeFriend
Messages: 26
Registered: August 2012
Junior Member
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: Fri Apr 26 16:04:34 GMT 2024

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

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

Back to the top