Skip to main content



      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 09:55
Eclipse UserFriend
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 create a rule containing regular expression?
Goto Forum:
  


Current Time: Thu Jun 19 12:56:20 EDT 2025

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

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

Back to the top