lezer-parser / lezer

Dev utils and issues for the Lezer core packages
33 stars 1 forks source link

Feature request: match quotes #20

Closed pmg23 closed 2 years ago

pmg23 commented 2 years ago

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

marijnh commented 2 years ago

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).