Skip to content
This repository was archived by the owner on Jun 9, 2021. It is now read-only.
This repository was archived by the owner on Jun 9, 2021. It is now read-only.

$?<name> to match a single optional node #52

@quasilyte

Description

@quasilyte

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions