Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » How to represent triple double quote string(Lexer grammar)
How to represent triple double quote string [message #1800977] Thu, 10 January 2019 14:55
Henry Henry is currently offline Henry HenryFriend
Messages: 4
Registered: January 2015
Junior Member
Hi,

I am having some difficulties trying to declare triple double-quoted string and preventing it from conflicting with the existing single double-quoted string.
Example:
""" The reader says "The quick brown fox jumps over the lazy dog" while reading the book. """
Which should be accepted as a string similar to:
"The reader says \"The quick brown fox jumps over the lazy dog\" while reading the book."

This is common in some modern language like scala or kotlin. Basically when a string is declared inside triple double quoted string, any double quote or single quote does not need to be escaped.


Currently I tried using this
StringValue:
value= (STRING|TRIPLE_QUOTE_STRING)
;

Where the terminals are defined as:

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

terminal TRIPLE_QUOTE_STRING returns ecore::EString:
'"""' ( '\\' ('b'|'t'|'n'|'f'|'r'|'"'|"'"|'\\') | !('\\'|'"') )* '"""'
;

However, it only works when there are no quote within the triple quote. It is not working whenever a quote is added inside the string.
Previous Topic:How to format nested loops ?
Next Topic:How can i disable backtracking ?
Goto Forum:
  


Current Time: Sun Aug 18 03:00:29 GMT 2019

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

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

Back to the top