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

I am having some difficulties trying to declare triple double-quoted string and preventing it from conflicting with the existing single double-quoted string.
""" 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

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: Mon Dec 09 10:23:05 GMT 2019

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

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

Back to the top