Comments (6)
Ok, I'll look at the two step solution and open up a PR.
from tcblack.
Thanks for reporting! I earlier already noticed strange behavior when there is a closing bracket in the string ')'
. You can see the failing ones and a few working ones here https://regex101.com/r/HN9oLJ/3
I tried the following to fix it, but it fails on different ones:
- Replace
\w+\(.*\)
with\w+\([^)]\)
thenWriteContents: STRING(1) := ')';
passes, butfbSample : FB_Sample(nId_Init := 11, fIn_Init := 33.44) ;
fails https://regex101.com/r/HN9oLJ/6. - Replace
\w+\(.*\)
with\w+\(.?\)
thenWriteContents: STRING(1) := ')';
passes, butfbSample : FB_Sample(nId_Init := 11, fIn_Init := 33.44) ;
also fails https://regex101.com/r/HN9oLJ/7.
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.
from tcblack.
Ok, this was an interesting one!
This seems to work. Add a negative look ahead/behind for the quotes
(?<!['"])
and (?!["'])
and also using the negative lookahead for the semi colon (?:;(?!.*;))
. This will still fail is there's a semi colon in the comment.
I also removed the (?s)
single line modifier. I'm not too sure the purpose of this one... But if needed the negative look ahead just needs to be modified to not match new lines with the dot.
https://regex101.com/r/HN9oLJ/8
This is my attempt to solve the semi colon in the comment, but still needs some work...
https://regex101.com/r/HN9oLJ/9
Any other edge cases will surely pop up as needed 😆
from tcblack.
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:
- Add a failing test and run it.
- Use regex101.com and/or https://www.debuggex.com/ to find the right pattern with a few examples
- Run the tests again. If it fails go to two. Else 🥳
from tcblack.
I think this might be easier to do in two steps. The first step would be to check for a string like initializing. Either '
or "
. If found remove it and apply the current regex to part it out. The string check would have to make sure that any FB initializing with string values don't get caught.
Because the major issue I see right now is supporting those special characters inside a string. )
and ;
.
https://regex101.com/r/EzvPSi/2
from tcblack.
That seems like a good solution. Or else the regex will become very complex.
from tcblack.
Related Issues (20)
- Do not remove spaces from strings in FB_init of a function block
- How to insert a tab in windows command prompt when you want to use tabs for indentation
- Visual Studio Development Tools Environment (DTE) build method is slower than devenv solution HOT 2
- GUI/Integration into Visual Studio for TcBlack HOT 3
- Add undo functionality to TcBlackExtension HOT 2
- Replace complex regex in Tokenize
- File shouldn't have to be saved before doing a format
- TcBlackCore can not be build HOT 5
- VSIX support for VS2019 HOT 2
- Only run pipeline when there are changes in src folder HOT 1
- Pipeline should notify in case of static code analyses warnings HOT 1
- Seperate pipeline into a build and test part
- Remove assembly signing HOT 5
- Also include TcBlackExtension in build pipeline
- VAR CONSTANT, VAR PERSISTENT and VAR RETAIN not recognized
- Use 2 spaces between code and comment HOT 1
- Assignment := is placed after array of pointers
- Extra AT inserted for AT%Q* if there is no space behind AT
- Add auto formatter for C# code HOT 2
- Use external parser
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from tcblack.