-
-
Notifications
You must be signed in to change notification settings - Fork 10
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
Regex for variable definition fails on string which includes semi colon or closing bracket #35
Comments
Thanks for reporting! I earlier already noticed strange behavior when there is a closing bracket in the string I tried the following to fix it, but it fails on different ones:
I also tried with your negative lookahead but that also doesn't lead to the desired result https://regex101.com/r/HN9oLJ/4 It's a though one. |
Ok, this was an interesting one! This seems to work. Add a negative look ahead/behind for the quotes I also removed the This is my attempt to solve the semi colon in the comment, but still needs some work... Any other edge cases will surely pop up as needed 😆 |
Yeah its a tricky one 😁 . That's why the tests are so convenient. It often happens that a small change of the regex pattern can have very large consequences for other variable declarations. What I usually do is:
|
I think this might be easier to do in two steps. The first step would be to check for a string like initializing. Either Because the major issue I see right now is supporting those special characters inside a string. |
That seems like a good solution. Or else the regex will become very complex. |
Ok, I'll look at the two step solution and open up a PR. |
Losing the initialization portion if there's a semicolon inside the string
My initial idea was negative lookahead in the Tokenize method.
TcBlack/src/TcBlack/VariableDeclaration.cs
Line 77 in 8440ab0
(?:;(?!.*;))
This negative lookahead would fail if there's a semi colon in the comment portion of the line also.
But that gives me even weirder results with the assignment operator now showing up.
The text was updated successfully, but these errors were encountered: