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

Incorrect syntax highlighting #25

Closed
revolter opened this issue Nov 23, 2016 · 13 comments
Closed

Incorrect syntax highlighting #25

revolter opened this issue Nov 23, 2016 · 13 comments

Comments

@revolter
Copy link

revolter commented Nov 23, 2016

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
Copy link
Collaborator

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

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

@revolter
Copy link
Author

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

@jtbandes
Copy link
Collaborator

It's here:

<string>(?x)
(\\\() # Opening
(
(?&lt;parens&gt;
(
[^()"] # Anything except parens
| \( # Matched pairs of parens
\g&lt;parens&gt; # …that can be nested
\)
| " # Strings
([^\\]|\\.)* # Contents allowing for escapes
"
)*
)
)
((\))) # Closing

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:

<dict>
<key>begin</key>
<string>\\\(</string>
<key>beginCaptures</key>
<dict>
<key>0</key>
<dict>
<key>name</key>
<string>punctuation.section.embedded.begin.swift</string>
</dict>
</dict>
<key>contentName</key>
<string>source.swift</string>
<key>end</key>
<string>\)</string>
<key>endCaptures</key>
<dict>
<key>0</key>
<dict>
<key>name</key>
<string>punctuation.section.embedded.end.swift</string>
</dict>
<key>1</key>
<dict>
<key>name</key>
<string>source.swift</string>
</dict>
</dict>
<key>name</key>
<string>meta.embedded.line.swift</string>
<key>patterns</key>
<array>
<dict>
<key>include</key>
<string>$self</string>
</dict>
<dict>
<key>begin</key>
<string>\(</string>
<key>comment</key>
<string>Nested parens</string>
<key>end</key>
<string>\)</string>
</dict>
</array>
</dict>

{	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
Copy link
Collaborator

@revolter
Copy link
Author

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

@revolter
Copy link
Author

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

@jtbandes
Copy link
Collaborator

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
Copy link
Author

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

@revolter
Copy link
Author

@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
Copy link
Collaborator

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
Copy link
Collaborator

The changes are finally out :)

@revolter
Copy link
Author

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

@idrougge
Copy link

Finally!

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

3 participants