TelluIoT / ThingML

The ThingML modelling language
https://github.com/TelluIoT/ThingML
Apache License 2.0
101 stars 32 forks source link

Issue backslash not removed from annotation #186

Closed madkira closed 6 years ago

madkira commented 7 years ago

The generator leaves backslashes \ on annotation

@c_header "
#define SIMPLE_CLICK \"Simple Click\""

should generate

#define SIMPLE_CLICK "Simple Clic"

but the result is

#define SIMPLE_CLICK \"Simple Click\"
jakhog commented 7 years ago

I checked, and the same happens for all string literals. E.g. if I make a property

property test : String = "\"Some string\""

It will generate this C-code:

t_var.Test_test_var = "\"Some string\"";

But in that case it actually makes sense, since we are adding the outer "" back.

So, maybe the actual fix would be to treat annotation values different from string literals? In a way, it isn't really a string literal...

jakhog commented 7 years ago

Or, another thought: We could (should?) unescape the string literals when we parse it (since the backslashes are not really a part of the actual string we want), and escape it back when we generate the code.

This might be even more correct, if you consider languages that doesn't use "" to express string literals. You could choose to use single quotes in e.g. JavaScript...

brice-morin commented 7 years ago

I know it has been some back and forth changes in the way we by default escape quotes in annotations, extern expressions and maybe string literal. I guess we should indeed treat string literals different from annotations. @ffleurey what is now the (un)escaping strategy in: