porcupine
porcupine copied to clipboard
tree-sitter highlighter: nested Rust macros
not_implemented!
macro does not highlight when it is inside tokio::select!
macro
The correct name for the macro is actually unimplemented!
but it highlights the same with the right name.
This will be tricky to fix. foo!()
parses as:
$ python3 scripts/tree-sitter-dump.py rust <(echo 'foo!()')
type=source_file text='foo!()\n'
type=macro_invocation text='foo!()'
field 'macro': type=identifier text='foo'
type=! text='!'
type=token_tree text='()'
type=( text='('
type=) text=')'
lol!{foo!()}
parses as:
type=source_file text='lol!{foo!()}\n'
type=macro_invocation text='lol!{foo!()}'
field 'macro': type=identifier text='lol'
type=! text='!'
type=token_tree text='{foo!()}'
type={ text='{'
type=identifier text='foo'
type=token_tree text='()'
type=( text='('
type=) text=')'
type=} text='}'
The parse tree doesn't even have anything for the second !
.
Presumably tree-sitter is trying to be "helpful" by not assuming much about macro bodies, as their specific syntax depends on which macro is being invoked. But it would be nice if it didn't just ignore !
magically.
another example:
lazy_static! {
static ref FILE_LOCK: tokio::sync::Mutex<&'static str> =
tokio::sync::Mutex::new("catris_high_scores.txt");
}
Currently this highlights pretty differently if you comment out the lazy_static! {
part, which makes the rest be inside a macro invocation.