GithubHelp home page GithubHelp logo

Comments (4)

mpkorstanje avatar mpkorstanje commented on August 19, 2024

Currently you can not assign special meaning to groups because every possible regex generated by a Cucumber expression is also a regular valid regular regex that may be provided by a user.

For example the regex:

A(?<Special-String> non-optional) pattern

Would be capturing when used with Cucumber, but non capturing in the Language Server. And while it is unlikely a user may have guessed Special-String, it is an indication that this abstraction is leaking.

Now I'm not opposed to adding named group support to the tree regex. These names could be used when generating step definitions based of regular regexes for example.

However the proposed Special-String should not be used in production code. So consider generating a different regex patterns when transforming the AST to a Cucumber expression while using the langue server.

This may require some refactoring.

from cucumber-expressions.

aslakhellesoy avatar aslakhellesoy commented on August 19, 2024

I wrote in cucumber/language-service#57 that we could change TreeRegexp. After thinking about it a bit more, I think the correct place to do this is in rewriteOptional:

We could pass a makeOptionalGroup: (regex: string, count: number) => string constructor argument to CucumberExpression (defaulting to this:

(regex, count) => `(?:${regex})?`

That way, the language server could pass its own:

(regex, count) => `(?<optional-${count}>${regex})`

from cucumber-expressions.

mpkorstanje avatar mpkorstanje commented on August 19, 2024

That interface is very language server specific.

For example:

  • count is not a concept that occurs in cucumber expressions. It exists only for the language server.
  • This only and specifically replaces optionals.

Ideally we define the Cucumber expression API in its own domain terms.

So I think some refactoring is in order.

from cucumber-expressions.

mpkorstanje avatar mpkorstanje commented on August 19, 2024

It does come to mind that currently we also assume that all capture groups are parameters. If you write optionals as capturing then match won't work anymore.

Maybe you can extract the code that rewrites the AST, add support for named groups to tree-regex and then use those in a class that is not CucumberExpression.

from cucumber-expressions.

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.