Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Rule for enclosing a value in apostrophes
Rule for enclosing a value in apostrophes [message #1068140] Fri, 12 July 2013 11:53 Go to next message
Tobias Freudenreich is currently offline Tobias FreudenreichFriend
Messages: 19
Registered: July 2013
Junior Member
Hi,

I am trying to write a rule that (as part of my language) supports statements like
(keyword='value')


I have the rules
Statement:
	"(" attribute=Attribute "=" state=AttributeValue ")"
;

Attribute:
	ID
;

AttributeValue:
	"'" ID "'"
;


The problem I am facing is that the generated editor complains about statements like test='hi'. Reporting that "mismatched input 'hi' expecting ''' "

If I replace the last rule with
AttributeValue:
	"!" ID "!"
;


the generated editor accepts test=!hi!. So I assume that I am somehow treating ' wrong. Does anyone know how to correctly handle this? I have no custom terminal rules (just the ones imported from the Terminals file).
Re: Rule for enclosing a value in apostrophes [message #1068143 is a reply to message #1068140] Fri, 12 July 2013 12:09 Go to previous messageGo to next message
Alexander Nittka is currently offline Alexander NittkaFriend
Messages: 1193
Registered: July 2009
Senior Member
Hi,

the definition collides with the STRING terminal definition. Is there a reason not to use STRING directly?

Alex


Need training, onsite consulting or any other kind of help for Xtext?
Go visit http://xtext.itemis.com or send a mail to xtext@itemis.de
Re: Rule for enclosing a value in apostrophes [message #1068155 is a reply to message #1068143] Fri, 12 July 2013 12:52 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi Alex

The default STRING terminal supports "..." and '...' strings.

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

If this is not what you want, you need to define/inherit a custom
variant of org.eclipse.xtext.common.Terminals that perhaps does

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

It is worth preserving as many of the standard terminal names as
possible since there is helpful built-in functionality for ID etc.

You will however need to reference and implement a ValueConverterService
to make SINGLE_QUOTED_STRING work as required.

Regards

Ed Willink

On 12/07/2013 13:09, Alexander Nittka wrote:
> Hi,
>
> the definition collides with the STRING terminal definition. Is there
> a reason not to use STRING directly?
>
> Alex
Re: Rule for enclosing a value in apostrophes [message #1069122 is a reply to message #1068155] Mon, 15 July 2013 07:50 Go to previous message
Tobias Freudenreich is currently offline Tobias FreudenreichFriend
Messages: 19
Registered: July 2013
Junior Member
Thank you for the replies. STRING is exactly what I need. I feel sort of dumb to have missed that one. It works perfectly now, thanks a lot again!
Previous Topic:Errors during xtext ui project export operation
Next Topic:<language>.xtextbin not found
Goto Forum:
  


Current Time: Fri Apr 26 11:55:47 GMT 2024

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

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

Back to the top