I managed to parse this string : "" (one backslash between quotes) with the definition of strings provided in the default Spoofax project.

The parser should reject that input and give a parse error.

There is the rule:

lexical restrictions
BackSlashChar -/- ["]

but it has no effect.

Tested with Spoofax 1.1

Submitted by Radu Mereuta on 24 April 2013 at 16:37

On 21 May 2013 at 09:35 Radu Mereuta commented:

I recently found this as an issue, and I finally understand what happens.
Indeed there is a small problem with the grammar of strings provided in the default example.
Here is the syntax of strings:

lexical syntax
“\”" StringChar* “\”" -> STRING
~[\"\n] -> StringChar
“\\\"” -> StringChar
BackSlashChar -> StringChar
“\\” -> BackSlashChar
lexical restrictions
BackSlashChar -/- ["]

Take for example the input "\\" (one backslash between quotes). The problem is that it is a valid parse. The main rule "~[\"\n] -> StringChar" consumes backslashes, but only BackSlashChar should. In this case it was a visible error. But in other cases, like: "\\n", you will actually have an ambiguity. This is not normally visible because the imploder takes care of ambiguities at lexical level if the two tokens are the same, but it is present in the parse tree.

I propose this simple fix:

“\”" StringChar* “\”" -> STRING
~[\"\n\r\\] -> StringChar
[\\]~[\n\r] -> StringChar

The second rule disallows quotes and backslashes, and the second rule forces backslash to be followed by another character, other than newline.

On 13 July 2013 at 01:56 Gabriël Konat tagged parser

On 13 July 2013 at 01:57 Gabriël Konat tagged minor

On 13 July 2013 at 01:57 Gabriël Konat tagged 1.2

On 13 March 2014 at 08:53 Eelco Visser removed tag 1.2

Log in to post comments