eclipse-ocl / org.eclipse.ocl

Eclipse Public License 2.0
0 stars 0 forks source link

Cannot use backslash character inside string literals #178

Closed eclipse-ocl-bot closed 13 hours ago

eclipse-ocl-bot commented 13 hours ago

| --- | --- | | Bugzilla Link | 184948 | | Status | CLOSED FIXED | | Importance | P2 major | | Reported | May 01, 2007 14:32 EDT | | Modified | May 27, 2011 02:41 EDT | | Version | 1.1.0 | | Reporter | Christian Damus |

Description

For string-valued properties that represent file-system paths, regular expressions, and other strings in which backslashes are known to occur, it would be nice to be able to formulate OCL expressions that compare these with literal strings.

However, it is effectively impossible to use backslashes in string literals because the lexer grammar defines escape sequences (in the Java style, not OCL-compliant) that the parser does not process when constructing Java strings.

For example, on attempting to construct a regex like:

self.regex = '(\w+)\(\)'

the parser complains that \w, (, ) are not valid escape sequences. The solution purports to be the following:

self.regex = '(\w+)\(\)'

to escape the backslashes. However, the result is that the parser creates a Java string whose value literally is

"(\\w+)\\(\\)"

i.e., it does not process the escapes.

It would be best to just eliminate these escape rules from the grammar, since they aren't OCL-compliant anyway (OCL defines no escape syntax). Existing OCL expressions that, by coincidence, happen to have strings that seem to work, e.g.,

self.fileName = 'c:\normal\result\table'

(\n, \r, \t being supported by the grammar) will continue to work because \ will no longer be a special character.

eclipse-ocl-bot commented 13 hours ago

By Christian Damus on May 03, 2007 09:19

Removed the definition of backslash escapes from the Lexer grammar (except for \", which is only used in the "..." escape syntax for names containing whitespace, which itself is non-standard anyway).

Implemented an escape for single-quotation marks in string literals, following the SQL syntax: simply follow the ' with another ' : '' (not ").

eclipse-ocl-bot commented 13 hours ago

By Nick Boldt on Jan 28, 2008 16:37

Move to verified as per bug 206558.

eclipse-ocl-bot commented 13 hours ago

By Ed Willink on May 27, 2011 02:39

Closing after over a year in verified state.

eclipse-ocl-bot commented 13 hours ago

By Ed Willink on May 27, 2011 02:41

Closing after over a year in verified state.