boschresearch / blech

Blech is a language for developing reactive, real-time critical embedded software.
Apache License 2.0
72 stars 6 forks source link

Escaping quotes in bindings does not work as expected #62

Closed FriedrichGretz closed 3 years ago

FriedrichGretz commented 3 years ago

Describe the bug

@[CFunction (binding = "print(\"bla?\\n\");", header = "main.h")]
extern function foobar()

generates code as expected when used in a Blech program. However when used in a Blech module, an invalid signature is generated because the quotes are not escaped:

@[CFunction(binding = "print("bla?\n");",
            header = "main.h")]
extern function foobar()

Also notice that the \n is now escaped only once and would result in an actual line break in the generated code.

Expected behaviour The expected behaviour is to copy the binding exactly as is to the signature.

Additional context Using multi-line strings in the binding """ has the same result.

schorg commented 3 years ago

Commit 51d42f35a79bd36b860208b45c7e8ff191bdec25 fixes this issue.

You have to use triple quotes (multi-line strings) to enter double quotes " in the C binding.

@[CFunction (binding = """print("bla?\n");""", 
             header = "main.h")]
extern function foobar()

The signature now contains the correct binding. The generated C macro in the .h-file is now correct.