Skip to content

Remapping | Is ** greedy or lazy? #173

Open

Description

@sloretz

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.

Activity

  1. added
    question
    on May 10, 2018
  2. SuperJappie08 commented on Sep 24, 2024

    @SuperJappie08

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

  3. Veng97 commented on Oct 18, 2024

    @Veng97

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    backlogquestion

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions