Motoko Double Quote Char literal

Im trying to do a literal double quote value in motoko but im getting compiler parsing errors like everything after a double quote is a string, even if escaped with \

Tried '\"', '"', '""' with no luck
Currently im doing a hack: Text.toIter("\"").next()!

Is there a way to do this? whats the escape sequence?

2 Likes

'\"' should work just fine. What error are you seeing?

To wit: https://m7sm4-2iaaa-aaaab-qabra-cai.raw.ic0.app/?tag=3275917314

1 Like

@rossberg
The syntax parsing treats " as the start of a string it seems and doesnt get escaped
image

Also with a let:
image

Compiling also gets an error that matches what I see in VS Code

It just treats the next pieces of code as a string until it finds another double quote in the file

Using VS Code and moc v0.7.4

The syntax highlighting seems to be a problem with VS Code or the plugin specifically. This e.g. works fine in the playground.

As for the compiler error, can you show (a minimised version of) the source code of Texts.mo? The error mentions a token '/', which does not appear in your example.

As a workaround, you can also use a numeric escape which might not confuse the plugin.

[nix-shell:~/motoko/src]$ rlwrap moc
Motoko compiler (source 0.8.0-dirty)
> '\"';
'\"' : Char
> '\u{22}';
'\"' : Char
> 

('\22') also works but I’m not sure if that’s actually supposed to…

I can confirm that seems to be a bug with the plugin only, and doesn’t affect string literals, just char literals.

Eg.

(Char.fromText ("\""));

is coloured ok (that function doesn’t exist btw).

image

1 Like

This is fixed in version 0.8.2 of the extension. Cheers!

4 Likes