ros2 / design

Design documentation for ROS 2.0 effort
http://design.ros2.org/
Apache License 2.0
224 stars 192 forks source link

Remapping | Is ** greedy or lazy? #173

Open sloretz opened 6 years ago

sloretz commented 6 years ago

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

Example:

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.

SuperJappie08 commented 2 months ago

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

Veng97 commented 1 month ago

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