Skip to content

Add verbatim identifiers#112

Merged
DustinCampbell merged 2 commits intodotnet:masterfrom
Muchiachio:TM-25
May 2, 2018
Merged

Add verbatim identifiers#112
DustinCampbell merged 2 commits intodotnet:masterfrom
Muchiachio:TM-25

Conversation

@Muchiachio
Copy link
Copy Markdown
Contributor

Sorry for a long diff, but had to add a lot of tests to make sure everything works.
Resolves #25.
Fixes #46.

Copy link
Copy Markdown
Member

@DustinCampbell DustinCampbell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice, and thanks for all of the tests! I just had a few questions around some of the regex tweaks.

Comment thread src/csharp.tmLanguage.yml Outdated
captures:
'1': { name: storage.modifier.cs }
- match: \b([_[:alpha:]][_[:alnum:]]*)\b
- match: (@?\b[_[:alpha:]][_[:alnum:]]*)\b
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't @? and \b be swapped?

Comment thread src/csharp.tmLanguage.yml Outdated
end: (?<=\})|(?=;)
patterns:
- match: \b([_[:alpha:]][_[:alnum:]]*)\b
- match: (@?\b[_[:alpha:]][_[:alnum:]]*)\b
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't @? and \b be swapped here?

Comment thread src/csharp.tmLanguage.yml
)
)\s*
(?:\b(\g<identifier>)\b)?
(?:(\g<identifier>)\b)?
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you remove this \b?

Comment thread src/csharp.tmLanguage.yml Outdated
- match: |-
(?x) # e.g. x
\b([_[:alpha:]][_[:alnum:]]*)\b\s*
(@?\b[_[:alpha:]][_[:alnum:]]*)\b\s*
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should @? and \b be swapped?

Comment thread src/csharp.tmLanguage.yml Outdated
- match: |-
(?x) # e.g. x
\b([_[:alpha:]][_[:alnum:]]*)\b\s*
(@?\b[_[:alpha:]][_[:alnum:]]*)\b\s*
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should @? and \b be swapped?

Comment thread src/csharp.tmLanguage.yml Outdated
(?x)
\b(into)\b\s*
\b([_[:alpha:]][_[:alnum:]]*)\b\s*
(@?\b[_[:alpha:]][_[:alnum:]]*)\b\s*
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Confused by position of @? and \b'. Doesn't that defeat the purpose of \b'?

Comment thread src/csharp.tmLanguage.yml Outdated
(?x)
\b(into)\b\s*
\b([_[:alpha:]][_[:alnum:]]*)\b\s*
(@?\b[_[:alpha:]][_[:alnum:]]*)\b\s*
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto here

Comment thread src/csharp.tmLanguage.yml Outdated
(?x)
(?:\b(async)\b\s*)?
\b([_[:alpha:]][_[:alnum:]]*)\b\s*
(@?\b[_[:alpha:]][_[:alnum:]]*)\b\s*
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And here

Comment thread src/csharp.tmLanguage.yml
)
)?
\b(\g<identifier>)\b\s*
(\g<identifier>)\b\s*
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did the \b need to be removed here?

Comment thread src/csharp.tmLanguage.yml
)
)
(?:\b(?<tuple-name>\g<identifier>)\b)?
(?:(?<tuple-name>\g<identifier>)\b)?
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did the \b need to be removed here?

@Muchiachio
Copy link
Copy Markdown
Contributor Author

\b' swaps are needed, because @ is not considered as a part of a word and thus doesn't match a word boundary, so for example @my_var doesn't get matched with \b@my_var\b.

As for \b removals, it has a similar problem because of \b(\g<identifier>), it gets mapped to
\b(\g@?[_[:alpha:]][_[:alnum:]]*), which again can't be matched because of a leading @. Also all the patterns which used the removed \b are followed by leading words separated by space so they will have a correct leading boundary anyway, that's why I removed them.

I was also trying to replace those few <identifier> patterns with @?[_[:alpha:]][_[:alnum:]]*, but it didn't work for some reason.

@DustinCampbell
Copy link
Copy Markdown
Member

It does make sense that \b would get in the way once @ can appear at the front of an identifier match. But why the swaps? Wouldn't it be better to just remove the \b in those cases?

@Muchiachio
Copy link
Copy Markdown
Contributor Author

Muchiachio commented May 2, 2018

Yes, in this case they can be removed, just left them there because they were there, but they don't affect current tests. Should I remove them then?

@DustinCampbell
Copy link
Copy Markdown
Member

If you don't mind removing them, that'd be great.

@Muchiachio
Copy link
Copy Markdown
Contributor Author

Removed.

@DustinCampbell
Copy link
Copy Markdown
Member

Thanks!

@DustinCampbell DustinCampbell merged commit 2191d84 into dotnet:master May 2, 2018
DustinCampbell added a commit to DustinCampbell/vscode that referenced this pull request May 2, 2018
* Prefer multiplication over pointer types.
([csharp-tmLanguage#111](dotnet/csharp-tmLanguage#111))
* Add support for verbatim identifiers. ([csharp-tmLanguage#112](dotnet/csharp-tmLanguage#112))

All fixes contributed by [@Muchiachio](https://github.com/Muchiachio).
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

Successfully merging this pull request may close these issues.

2 participants