Extending existing language grammar

Hello,
I need to extend an existing codemirror grammar (in my case SQL but in the future it can be other languages as well) so it keeps original language syntax highlighting and autocomplete and add custom ones on top. I figure one way would be to fork codemirror-lang-sql repo and do all changes there manually but was wondering what would be a proper way of doing this.

Thanks in advance!

Add extra grammar or add extra autocomplete?

For grammar, you’ll need to fork codemirror-lang-sql.

If you want to add more autocomplete stuff, you can do so by adding an an autocompletion source to the “language data” like in codemirror-lang-sql. The returned value from this is “just” an extension that you can add to your list of extension.

Thanks @Michiel
I need both but extra grammar problem is what concerns me the most since adding support for custom grammar in other languages in the future would require more forks. So there is no way of extending the grammar using extensions or something similar?

No. LR parsers are compiled in a way that doesn’t allow extension at runtime. It would be possible to define a system of adding and replacing rules in a grammar, but my experience with that kind of system is that it leads to more fragile, interdependent messes than just forking the grammar description.