microsoft / monaco-editor

A browser based code editor
https://microsoft.github.io/monaco-editor/
MIT License
40.23k stars 3.58k forks source link

C++ line continuation mark (\) should be ignored everywhere #1184

Open evakili opened 5 years ago

evakili commented 5 years ago

monaco-editor version: 0.15.1 Browser: Chrome (maybe others) OS: Windows

In C/C++ \ is used as line continuation mark so defining macros in multi-line is possible:

#define MACRO do { \
} while(false);

It is also possible to change a single line comment to multi-line with \:

// Multi \
   Line \
   Comment

As you see in above snippet, Github syntax highlighter accept this syntax in comments and colorize line 2 and 3 as comments, but Monaco does not:

image

This is somehow strange that the VSCode highlights it correctly but Monaco does not. image

alexdima commented 5 years ago

PR welcome. This is implemented here and I usually use the Monarch Playground to work on these things. Most likely, the single line comment case must become more involved, i.e. // should enter a new state, in the new state, similar to how multi-line strings are implemented.

Here you can find an example for strings which support \

evakili commented 5 years ago

I will be glad if I could provide a PR.

But it seems it's different than multi-line strings. \ is a continuation character at end of every line. So

int mai\
n(int arg\
c, char** ar\
gv) {
}

is weird but, is a valid C++ program (although made Github highlighter confused too :stuck_out_tongue_winking_eye:)!

Better to say all \\\w*\r?\n regex matches should be ignored.

alexdima commented 5 years ago

oh, I always used \ in pragma statements, and have seen folks using \ sometimes in single line comments. I didn't realize \ can be used anywhere.

evakili commented 5 years ago

Me too!

Albeit it could be fixed only for comments for now (by the solution you've said), and could be fixed for all cases. What's your opinion?