Skip to content

Feature Request: Flattening single-child branches operator #49

@adzierzanowski

Description

@adzierzanowski

I very much like Owl but there's a single feature I miss. In Lark python parsing library there's a neat ? operator which replaces a node in resulting tree with its child if there's only one.

So for example a parser with the following grammar (using ? as in Lark)

program = stmt*
stmt =
   'print' expr : print
?expr =
   [ '(' expr ')' ] : parens
   identifier : variable
   number : literal
 .operators prefix
   '-' : negative
 .operators infix left
   '+' : plus
   '-' : minus

would produce

program (0 - 7)
  stmt : PRINT (0 - 7)
    number - 1.000000 (6 - 7)

instead of

program (0 - 7)
  stmt : PRINT (0 - 7)
    expr : LITERAL (6 - 7)
      number - 1.000000 (6 - 7)

Is such feature possible in the future or is it out of scope of the project?

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