Top 1,000 Features Creators Events Podcasts Extensions Interviews Blog Explorer CSV

PEG.js

< >

PEG.js is an open source grammar language created in 2010 by David Majda.

#168on PLDB 14Years Old 72Repos
Download source code:
git clone https://github.com/pegjs/pegjs
Homepage · REPL · Source Code · Twitter

PEG.js is a simple parser generator for JavaScript that produces fast parsers with excellent error reporting. You can use it to process complex data or computer languages and build transformers, interpreters, compilers and other tools easily.


Example from the web:
start = additive additive = left:multiplicative "+" right:additive { return left + right; } / multiplicative multiplicative = left:primary "*" right:multiplicative { return left * right; } / primary primary = integer / "(" additive:additive ")" { return additive; } integer "integer" = digits:[0-9]+ { return parseInt(digits.join(""), 10); }

Language features

Feature Supported Example Token
Comments
// A comment
MultiLine Comments
/* A comment
*/
/* */
Line Comments
// A comment
//
Semantic Indentation X

View source

- Build the next great programming language · About · Resources · Acknowledgements · Part of the World Wide Scroll