textmate / swift.tmbundle

TextMate support for Swift
72 stars 30 forks source link

Incorrect syntax highlighting #25

Closed revolter closed 7 years ago

revolter commented 7 years ago

This file has incorrect syntax highlighting after this line:

print("Message ID: \(userInfo["gcm.message_id"]!)")

This might be caused by the quotes inside the quotes.

jtbandes commented 7 years ago

Thanks for the report, I'll take a look.

@infininight This is why I wanted to use begin/end patterns :wink:

revolter commented 7 years ago

I am quite fond of regex, could you point me to the exact line that matches it?

jtbandes commented 7 years ago

It's here: https://github.com/textmate/swift.tmbundle/blob/4baaa8afd4ea001f3a7cfc02ca95fa9b9086c815/Syntaxes/Swift.tmLanguage#L4361-L4376

or in nicer form:

{   name = 'meta.embedded.line.swift';
    match = '(?x)
        (\\\()                          # Opening
        (
            (?<parens>
                (
                    [^()"]              # Anything except parens
                  | \(                  # Matched pairs of parens
                    \g<parens>          #  …that can be nested
                    \)
                  | "                   # Strings
                    ([^\\]|\\.)*        # Contents allowing for escapes
                    "
                )*
            )
        )
        ((\)))                          # Closing
    ';
    captures = {
        1 = { name = 'punctuation.section.embedded.begin.swift'; };
        2 = {
            name = 'source.swift';
            patterns = ( { include = '#root'; } );
        };
        5 = { name = 'punctuation.section.embedded.end.swift'; };
        6 = { name = 'source.swift'; };
    };
},

But personally, I don't think we should try to fix this regex match. I think we should replace it with begin/end patterns, as you can see in this older version of the grammar: https://github.com/textmate/swift.tmbundle/blob/662fd22bf8e6d2ed1dfcb5881c23838bad620404/Syntaxes/Swift.tmLanguage#L1436-L1481

{   name = 'meta.embedded.line.swift';
    begin = '\\\(';
    end = '\)';
    beginCaptures = { 0 = { name = 'punctuation.section.embedded.begin.swift'; }; };
    endCaptures = {
        0 = { name = 'punctuation.section.embedded.end.swift'; };
        1 = { name = 'source.swift'; };
    };
    contentName = 'source.swift';
    patterns = (
        {   include = '$self'; },
        {   comment = 'Nested parens';
            begin = '\(';
            end = '\)';
        },
    );
},
jtbandes commented 7 years ago

See also: https://manual.macromates.com/en/language_grammars

revolter commented 7 years ago

Thanks for the info, but sadly, that's too new/much for me and I can't help.

revolter commented 7 years ago

@jtbandes Any idea when will GitHub pull the latest version of this?

jtbandes commented 7 years ago

You can watch https://github.com/github/linguist to see when they update the grammars. It may be a bit of an unusual time for them since I believe the person who usually pulled the updates is no longer working at GitHub.

revolter commented 7 years ago

Seems like the releases were happening quite often. I'll just wait for the next one, thanks!

revolter commented 7 years ago

@jtbandes, Well, there were quite a bit of releases since then, and the latest one even says it updated grammars, but the syntax for that file is still problematic.

jtbandes commented 7 years ago

Yes, I've tried to contact them by commenting on those commits but haven't received any response so far. I don't believe their latest changes have actually taken effect (you can see hex literals are still broken); maybe due to caching or maybe they just haven't actually deployed the changes yet.

jtbandes commented 7 years ago

The changes are finally out :)

revolter commented 7 years ago

Awesome! Thanks for letting me know. "We can now close this issue" 😆

idrougge commented 7 years ago

Finally!