Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

macro_rules repeater syntax highlight error #505

Open
A4-Tacks opened this issue Dec 11, 2023 · 1 comment
Open

macro_rules repeater syntax highlight error #505

A4-Tacks opened this issue Dec 11, 2023 · 1 comment

Comments

@A4-Tacks
Copy link

A4-Tacks commented Dec 11, 2023

file src/main.rs

fn main() {
    macro_rules! foo {
        ( a $(b)?) => { };
    }
    macro_rules! bar {
        ($(:)hello*) => {};
        ($(:)r#const*) => {};
        ($(:)<-*) => {};
        ($(:)impl*) => {};
        ($(:)$*) => {};
        ($(:)-*) => {};
        ($(:)...*) => {};
        ($(:)*=*) => {};
        ($(:)#*) => {};
        ($(:)||*) => {};
    }

    foo!(a);
    foo!(a b);

    bar!(: hello : hello :);
    bar!(: r#const : r#const :);
    bar!(: $ : $ :);
    bar!(: *= : *= :);
    bar!(: ... : ... :);
    bar!(: # : # :);
    bar!(: || : || :);
}

syntax/rust.vim.patch

70c70
< syn region rustMacroRepeat matchgroup=rustMacroRepeatDelimiters start="$(" end="),\=[*+]" contains=TOP
---
> syn region rustMacroRepeat matchgroup=rustMacroRepeatDelimiters start="$(" end=")\%(?\|\%(&\|&&\|&=\|@\|\^\|\^=\|:\|,\|\$\|\.\|\.\.\|\.\.\.\|\.\.=\|=\|==\|=>\|>=\|>\|<[-=]\=\|-\|-=\|!=\|!\||\||=\|||\|::\|%\|%=\|+=\|#\|->\|;\|<<\|<<=\|>>\|>>=\|/\|/=\|\*=\|\~\|_\|\%(r#\)\=\w\+\)\=[*+]\)\=" contains=TOP

?, optional group
+ or *, use any token separate, token list from syn crate

char str and other tokens are not commonly used and have more complex rules, so ignore them

@A4-Tacks
Copy link
Author

I don't seem to have found a good way to both omit trailing duplicates and pair parentheses, while ensuring performance when inputting parentheses in large text

The solution I am currently using will slow down when entering parentheses when there is a lot of text

syn region rustParen start="(" end=")" transparent

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant