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?


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

To wit:

1 Like

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

Also with a let:

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 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.


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

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


1 Like

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