Skip to content
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

Remapping | Is ** greedy or lazy? #173

Open
sloretz opened this issue May 1, 2018 · 2 comments
Open

Remapping | Is ** greedy or lazy? #173

sloretz opened this issue May 1, 2018 · 2 comments
Labels
backlog question Further information is requested

Comments

@sloretz
Copy link
Contributor

sloretz commented May 1, 2018

The remapping design doc does not state whether ** is greedy or lazy. This can change the outcome of some remap rules.

Example:

  • rule /**/foo/**:=/\1/\2
  • name /foo/bar/foo/bar

If ** is greedy the output name is /foo/bar.

If ** is lazy the output name is /bar/foo/bar

Arguments for Greedy

Name matching with wild cards is similar to regular expression matching.
In perl syntax the quantifiers *, +, ? are greedy by default.
Since so many regular expression libraries have been based off this syntax, a user might expect ** to be greedy too.

Arguments for lazy

A lazy operator can reduce the amount of backtracking an implementation has to do while matching.
If given rule /**/foo/bar/baz:=... and name /foo/bar/baz a greedy ** would backtrack after every token, while a lazy ** would result in no backtracking at all.

Proposal

** should be greedy by default. In most cases remapping will only happen at startup, so the performance does not matter.

If the performance of backtracking becomes an issue then the syntax could be amended to allow changing the greediness. Perl does this with ? where * is greedy while *? is lazy. Ex: ** could be greedy while **? is lazy.

@sloretz sloretz added the question Further information is requested label May 10, 2018
@SuperJappie08
Copy link

SuperJappie08 commented Sep 24, 2024

@sloretz, The proposal seems rather useful and reasonable.
What needs to happen to make this change?
(Since it seems rather stale now)

@Veng97
Copy link

Veng97 commented Oct 18, 2024

The day the wildcard operator becomes available i will be a happy developer

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backlog question Further information is requested
Projects
None yet
Development

No branches or pull requests

4 participants