Handling characters that return ecore::EChar and identifiers [message #1790263] |
Thu, 07 June 2018 16:26 |
Rohit Verma Messages: 21 Registered: August 2017 |
Junior Member |
|
|
Hi,
(Please see attached ecore and Grammar files)
I am writing a grammar for expressions where I need to have support for Characters and Identifiers. A Character definition should return an ecore::EChar and Identifier definition should return ecore::EString.
The issue is that both Character and an Identifier could be a single alphabet, Eg: < x >
I know that a character is supposed to look like < 'x' > and an identifier will be just < x >, so they have different concrete syntax. However, I cannot have a rule for a character like " E_CHAR returns ecore::EChar : '\\'' SINGLE_CHAR '\\'' " because since it returns an ecore::EChar, the value assigned to this E_CHAR is the first character of <'x'> which is a single quote <'>. For this reason, I created a rule like {LiteralChar} "'" value = SINGLE_CHAR "'" which works fine for characters but now XText understands that characters are supposed to look like < x > and hence I can't now use identifiers like < x >.
How can I write a rule that handles this issue and lets me use both < 'x' > and < x > for Characters and Identifiers respectively?
So far I am thinking about removing the Character definition and only having identifiers, then in a custom program look for strings that are like <' SINGLE_CHAR '> and then create a new Char object from there.
Thanks.
-
Attachment: ExpressionsDsl.xtext
(Size: 2.30KB, Downloaded 77 times) -
Attachment: RAM.aird
(Size: 2.26MB, Downloaded 183 times) -
Attachment: RAM.ecore
(Size: 53.59KB, Downloaded 153 times) -
Attachment: RAM.genmodel
(Size: 27.95KB, Downloaded 197 times)
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03872 seconds