GithubHelp home page GithubHelp logo

Comments (6)

kdorsel avatar kdorsel commented on June 10, 2024 1

Ok, I'll look at the two step solution and open up a PR.

from tcblack.

Roald87 avatar Roald87 commented on June 10, 2024

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:

  1. Replace \w+\(.*\) with \w+\([^)]\) then WriteContents: STRING(1) := ')'; passes, but fbSample : FB_Sample(nId_Init := 11, fIn_Init := 33.44) ; fails https://regex101.com/r/HN9oLJ/6.
  2. Replace \w+\(.*\) with \w+\(.?\) then WriteContents: STRING(1) := ')'; passes, but fbSample : 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.

kdorsel avatar kdorsel commented on June 10, 2024

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.

Roald87 avatar Roald87 commented on June 10, 2024

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:

  1. Add a failing test and run it.
  2. Use regex101.com and/or https://www.debuggex.com/ to find the right pattern with a few examples
  3. Run the tests again. If it fails go to two. Else 🥳

from tcblack.

kdorsel avatar kdorsel commented on June 10, 2024

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.

Roald87 avatar Roald87 commented on June 10, 2024

That seems like a good solution. Or else the regex will become very complex.

from tcblack.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.