I’ve just started experimenting with Codemirror, and it looks like a very well-written project.
Would it be possible with Lezer to create a language that could provide syntax highlighting for multiple different languages in the same text buffer based on specific line number blocks instead of content in the text? So instead of using something like
Could this be achieved with External Tokens?
You could probably do something like that with an external tokenizer plus a context to keep track of the current line number, but it’d be somewhat awkard. Where is the information about which language occurs on which line coming from?
Thanks for the info! I’ll try to describe what I want to do in more detail.
\n when copying and pasting text. Do you think this sounds like a better approach?
Another thing you could try is to have your block-structure metadata keep a flat syntax tree for the extent of the blocks (reusing nodes for unchanged blocks so that incremental parsing works), and make the top-level parser a kind of pseudo-parser that just returns this tree, using
parseMixed to run block-specific parsers for each part.
Yes, this is what I ended up doing (I think), and it seems to be working good so far. I’ve made a top level custom parser with a syntax for declaring blocks and their language, and I use
parseMixed to set the the language for each block. I then hide then replace the tokens that specifies blocks/language with a widget that hides the string.
Thanks a lot for you help!