gogrep
gogrep copied to clipboard
$?<name> to match a single optional node
Right now we only have $*<name>
to match optional parts.
Sometimes we want to match exactly 1 optional node inside a pattern. It's either nil or it matches exactly 1 node.
It could be used to match optional parts inside a pattern that are expected to represent a single expression (or none).
I don't think that we need more general {min,max}
form from regexps, but ?
seems useful.
My use case: "find f() function call that is not followed by a return statement".
It could be expressed via f(); $x
and then checking that $x
is a return statement. The only problem is that f()
could be the last statement inside a block.
We could solve that by using f(); $?x
query that should in theory match these cases without return as well.
Good idea - I agree this is useful.
I also agree that {min,max}
is probably too much for the dollar syntax. If someone needs that much power, they should just use #32.