Customer language parser, but very close to C++


We have a custom scripting language that closely resembles C++. We just upgraded from Codemirror 3 to 6 in our application, and consequently had to change from c-like to cpp to get stuff such as color highlighting and auto-indenting. Unfortunately, we see that since our language differs slightly from C++, the auto-indenting breaks down. Specifically, the following code fails:

Void foo() {
  Integer[] ints;


The fail is that after pressing enter after “ints;”, the cursor moves to column 0, not 2 on the next line.

Replacing “Integer” with “int” works, so I guess the problems is that Integer is an unknown type. But removing “” also makes it work. I do happen to have a EBNF of our custom language, but since it is very close to C++ I was hoping for a simpler solution. It does not have to be perfect. If I could get auto-indentation to mostly work, it would help a lot. Any advice or pointers on where to start will be highly appreciated!


The parsing is done by this parser. Lezer parsers don’t allow a lot of run-time configuration of parsing behavior, so probably your best bet, if you want to support C++ with some custom constructs, is to fork that and try to include those constructs in your adjusted grammar.

1 Like