lezer-parser/lezer

Feature request: match quotes

pmg23 opened this issue · 1 comments

pmg23 commented

Hi

I'm using CodeMirror 6 with bracketMatching() and LanguageSupport using a custom Lezer parser. The custom grammar includes string literals delimited by double-quote characters, with support for escapes (\" and \\). I'd like it to be that when the cursor is at a quote delimiter (start or end) the matching delimiter is highlighted - in the same way that this works for the various types of brackets.

For example (screenshot from JetBrains Rider editing C#):
image

So far I have been unable to achieve this, either using @detectDelim (the ideal case) or by manual insertion of openedBy/closedBy node props in the grammar. (With the latter approach I can see the NodeProps metadata in the generated parser, but bracketMatching() doesn't work quite right.)

Please will you confirm if such behaviour is supported/possible in the present version? If so I wonder could you please update the example grammar to demonstrate it or the Lezer docs to explain how? If not, please could you consider this a feature request?

Best regards
Matt

matchbrackets won't help much here -- it assumes opening and closing brackets are distinguishable, and the brackets are separate tokens. But you should be able to write a custom extension that does this, probably by recognizing quoted tokens in the tree and highlighting their first and last characters (possibly checking if the closing character is there if you're tokenizing in an error-correcting way, for example by force-ending string tokens at line ends).