martanne / vis

A vi-like editor based on Plan 9's structural regular expressions
Other
4.23k stars 256 forks source link

Lexer: String Interpolation #862

Closed jeremybobbin closed 1 year ago

jeremybobbin commented 4 years ago

Is there any way to syntax highlight inner expressions like ${0##*/} & $opt in this string?

echo "${0##*/}: invalid option '$opt'"

Or maybe the %s's in:

printf("%s: invalid option '%s'", argv[0], opt);

What would be the best way to do this sort of thing?

martanne commented 3 years ago

There are two possible approaches to this:

  1. Define a "sub" lexer for strings and try to integrate it using embed_lexer. I'm not sure whether that will actually work when the start and end rule are the same, though.

  2. Introduce some concept of "stacked lexing" where the initial (existing) lexer produces a token stream (type, range) which could be further tweaked in subsequent passes. In your case you could filter out all tokens of type string and analyze them further. It might also be useful for language independent things like highlighting trailing white spaces etc.

However, if you are looking for advanced/correct syntax highlighting it might make more sense to investigate integration with existing language aware solutions.

mcepl commented 1 year ago

@ninewise, this should probably be sent upstream to https://github.com/orbitalquark/scintillua/issues, right?

ninewise commented 1 year ago

Yes, closing this here. Please open a ticket at scintillua if this is still relevant.