1. 27
  1. 5

    For a bit of back story, this project is just a fork of https://www.piumarta.com/software/peg/

    The main reason the fork exists is I wanted to create a single file release that is easy to distribute as part of my own projects.

    1. 5

      Nice! I have my own fork of peg that

      • fixes some bugs
      • adds a few new features like case-insensitive string matching
      • allows the generated parser to be compiled as C++

      You might consider merging that into yours.

      1. 2

        Neat - we both thought there was something good in this project :)

      2. 3

        A bit OT but was just considering why it’s still enjoyable to write compilers/parsers in C, and it’s too bad Go doesn’t have unions or similar, because it’s just such a natural way to express nodes of your grammar as a union of distinct structs. Zig’s tagged unions are great for this. Go would be a killer compiler implementation language with them. Interfaces are a clunky substitute in this context.

        1. 2

          Type constraints can be unions in 1.18. My guess is eventually there will be union interface values as well. They just have to work out all the language implications first.

          1. 2

            I get some satisfaction knowing it is going to be fast and have few dependencies. You don’t even really need to call free() if you intend for it to be a short lived process so some of the weaknesses of C don’t apply.

            1. 1

              Aren’t interfaces the natural way to do this in Go?

              1. 1

                Yes, if you want to discriminate by type in a switch statement which node is being handled (during evaluation, pretty-printing, type checking, etc.), then interfaces are the way to go if you want to ensure “node”-ness - but it’s clunky (to add a method set (usually a no-op method or one returning the start-end token position of the language construct in question) to each node struct type) compared to the relative elegance of a tagged union in C, ala @ac’s union Node here: https://git.sr.ht/~ach/minipeg/blob/master/minipeg.c

                1. 1

                  For sufficiently small quantities of natural.

                  It works, but feels pretty clunky.

              2. 2

                I just have to shamelessly plug my own PEG work. You’ll see a META II implementation in Lua, and a more complete PEG parser generator in Haskell where most of the hard work is done by Parsec.

                I also Bootstrapped a more fully fledged PEG parser in Lua from META II, though that one is not published. And it’s quite messy too, with about 20 steps going from META II to full PEG (and 20 self hosting meta-compilers to validate each step). Maybe I’ll write a cleaner bootstrap process one day.

                1. 2

                  For those who like LALR parser generators there’s Lemon, the one used in SQLite.