peg/leg — recursive-descent parser generators for C
peg and leg are tools for generating
recursive-descent parsers: programs that perform pattern matching on
text. They processes a Parsing Expression Grammar (PEG) [Ford 2004]
to produce a program that recognises legal sentences of that grammar.
peg processes PEGs written using the original syntax
described by Ford; leg processes PEGs written using slightly
different syntax and conventions that are intended to make it an
attractive replacement for parsers built with lex and
yacc. Unlike lex and yacc, peg
and leg support unlimited backtracking, provide ordered
choice as a means for disambiguation, and can combine scanning
(lexical analysis) and parsing (syntactic analysis) into a single
activity.
The current stable version is 0.1.19. Links are below.
The development version is 0.1.20 and is updated periodically.
If you want to help find bugs please try it out.
A tarball is linked in the version history.
Download the source code: peg-0.1.19.tar.gz
Browse the source code: peg-0.1.19
Read the manual page: peg.1.html
Enjoy the Emacs mode: leg-mode.el
peg is distributed under the MIT license. It will not infect
your project with a contagious
(削除) disease (削除ここまで) license if you
decide to modify it for your own use. The parsers that
peg and
leg create are unencumbered and you are free to use and/or
distribute them any way you like.
If you find bugs or have suggestions, please send them to piumarta
via gmail.
References
- [Ford 2004] Bryan Ford, Parsing Expression Grammars: A
Recognition-Based Syntactic Foundation. ACM SIGPLAN Symposium on
Principles of Programming Languages (POPL), 2004.
Version history
- 2023年11月19日 peg-0.1.20 (development, subject to change)
-
Experimental support for variables and semantic values in ‘inline actions’ executed
during recognition (separate from the parser actions that are run after the input is fully recognised).
Don't print #line directives for headers if -P was given and
pathnames on WIN32 have \ changed to / to keep #line directives happy
(thanks to Ben Hines for the problem report).
- 2023年03月06日 peg-0.1.19 (stable)
-
Experimental support for re-entrant parsing through yyparsefrom_r().
- 2016年07月22日 peg-0.1.18
-
Add -P option to disable #line directives.
Emit #line directives for all actions.
- 2016年07月14日 peg-0.1.17
-
Emit #line directives for header and trailer
in the generated source file.
- 2016年06月25日 peg-0.1.16
-
Add @{...} actions that are performed during matching.
- 2013年12月17日 peg-0.1.15
-
Calls to YY_FREE fixed (thanks to Andrew Dunham).
- 2013年12月01日 peg-0.1.14
-
Documentation typos fixed (thanks to Giulio Paci).
- 2013年08月16日 peg-0.1.13
-
Predicate actions can refer to yytext (thanks to Grégory Pakosz).
Hexadecimal character escapes are supported by leg (thanks to Hugo Etchegoyen).
- 2013年07月20日 peg-0.1.12
-
Use BSD-licensed getopt() in Windows build.
Verbose mode handles Variable nodes.
- 2013年06月03日 peg-0.1.11
-
Add error actions via "~" operator.
Support declaration of local variables at the top level of semantic actions.
Dynamically grow data structures to remove artificial limits on rule recursion (thanks to Alex Klinkhamer).
Many small changes to better support C++.
Add build files for Win32 and MacOS (thanks to Fyodor Sheremetyev).
Update manual page to describe new features.
- 2012年04月29日 peg-0.1.9
-
Move global state into a structure to facilitate reentrant and thread-safe parsers (thanks to Dmitry Lipovoi).
- 2012年03月29日 peg-0.1.8
-
Allow nested, matched braces within actions.
- 2011年11月25日 peg-0.1.7
-
Fix matching of 8-bit chars to allow utf-8 sequences in matching expressions (thanks to Grégory Pakosz).
- 2011年11月24日 peg-0.1.6
-
Allow octal escapes in character classes.
- 2011年11月24日 peg-0.1.5
-
Remove dwarf sym dirs when cleaning.
Fix size calculation when resizing text buffers.
Backslash can be escaped.
- 2009年08月26日 peg-0.1.4
-
Fix match of a single single quote character.
Rename getline -> nextline to avoid C namespace conflict.
- 2007年09月13日 peg-0.1.3
-
Allow matched braces inside leg actions.
Handle empty rules.
Handle empty grammars.
- 2007年08月31日 peg-0.1.2
-
Grow buffers while (not if) they are too small.
Remove dependencies on grammar files.
Add more basic examples.
- 2007年05月15日 peg-0.1.1
-
First public release.