Skip to content

Move away from custom regex-based parsing of PEG expressions #84

Description

@pmolodo

(Low priority... mostly wanted to record some findings in case we want to act on them later...)

Currently, our implementation of railroad diagrams relies on peg_to_peg.py, which converts from "classic ford-style flavor PEG grammar" to "pegen-flavor PEG grammar".

It then uses the pegen parser to generate an AST, and iterates that to generate the railroad diagrams.

However, the implementation of peg_to_peg.py relies on some custom regexes to convert between the two grammar flavors, which seems somewhat fragile + high maintenance.

As an alternative, we could either:

  • just write the rules with pegen flavor to begin with (see comment)
  • instead of relying on the pegen parser for generating railroad diagrams, use a different parser that understands "classic ford-style flavor PEG grammar" out-of-the-box - options include:
    • arpeggio with the "classic" PEG frontend
      • con: requires ALL rules to be terminated by ";"
    • the pe module
      • con: much less widely used, single dev
    • probably leaning toward arpeggio since it's much easier to fix the ";" termination now than it is to have to switch the parser later...

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions