talira

Packrat parser generator for Go from Parsing Expression Grammars

open sourceBSD-3-Clauseself-hostablefree

peg generates Go parsers from Parsing Expression Grammar files. You write a grammar in a .peg file, with Go code for the actions, and peg turns it into a Packrat parser: a recursive descent parser that backtracks and supports negative look-ahead, which regular expressions handle poorly. It runs as a Go tool dependency from go generate, and is a Go port of Ian Piumarta's peg/leg for C. Written by Andrew Snodgrass and BSD-3-Clause licensed.

Problems it solves

  • generate a parser in Go for my own small language or config format
  • write a grammar instead of hand-coding a recursive descent parser in Go
  • parse input that needs look-ahead that regular expressions can't express

Features

  • Generates Go parsers from .peg grammar files
  • Packrat parsing with backtracking and negative look-ahead
  • Go code actions inside the grammar
  • Runs as a go tool from go generate
  • Inline and switch code generation options

Capabilities

Has a command line toolplan not known