peggyjs / peggy

Peggy: Parser generator for JavaScript
https://peggyjs.org/
MIT License
914 stars 65 forks source link

Make rule name available inside action blocks #540

Open frostburn opened 1 month ago

frostburn commented 1 month ago

It would be nice if Rule.name and maybe even Rule.displayName were available inside action blocks.

Use case:

FooLiteral
  = "foo" {
    return {
       type: ruleName, // type: "FooLiteral"
       location: location(),
    };
  }

Here ruleName is a block scope constant, but it could also be a callable i.e. ruleName() if that's easier to implement.