icerpc / slicec

The Slice compiler library
Apache License 2.0
13 stars 5 forks source link

Slice Lexer Aggressively Removes Backslashes in String Literals #658

Closed InsertCreativityHere closed 11 months ago

InsertCreativityHere commented 12 months ago

Currently, Slice supports backslashes in string literals to allow things like:

[deprecated("Use \"Bar\" instead")]
struct Foo {}

So the lexer knows to treat the inner quotation marks as text.

However, after parsing, we remove these backslashes by just doing replace('\\', "") (remove all backslashes). But this might remove backslashes the user put there intentionally.

For instance, this should reasonably be parsed down to \hello:

[deprecated("\\hello")]

Instead this will currently produce hello.


TL;DR we should change the backslash removal logic to only remove the first backslash of each pair of characters, instead of removing all backslashes.

Note string literals are currently only allowed for attribute arguments.