Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Update the parser to track multiple same-named groups #177

@keith-hall

Description

@keith-hall

We will need to update the parser to track when multiple groups are defined with the same name. This is so the caller can decide how to react when the same name is used to declare multiple groups. We need this to be able to match Oniguruma behavior:

  • with backrefs referring to a named group with more than one declaration

    When backreferencing with a name that is assigned to more than one group, the last group with the name is checked first, if not matched then the previous one with the name, and so on, until there is a match.

  • with subroutine calls referring to a named group with more than one declaration (to be a compile error)

    Calls with a name that is assigned to more than one group are not allowed.

For this issue we can just handle the changes to the parser, and resolve it to a single numbered group when compiling, to match the current behavior. This will keep the changes smaller - we can then work on updating the backref behavior to more closely match Oniguruma afterwards.

Possible approaches:

  • change the type of the named_groups on the Parser (less invasive)
  • or emit a separate Expr variant for named groups (more invasive)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions