Are there any Parsing Expression Grammar (PEG) libraries for Javascript or PHP?
Asked Answered
L

7

18

I find myself drawn to the Parsing Expression Grammar formalism for describing domain specific languages, but so far the implementation code I've found has been written in languages like Java and Haskell that aren't web server friendly in the shared hosting environment that my organization has to live with.

Does anyone know of any PEG libraries or PackRat Parser Generators for Javascript or PHP? Of course code generators in any languages that can produce Javascript or PHP source code would do the trick.

Lithia answered 17/9, 2008 at 3:15 Comment(0)
D
17

I have recently written PEG.js, PEG-based parser generator for JavaScript. It can be used from a command-line or you can try it from your browser.

Dinodinoflagellate answered 19/3, 2010 at 9:1 Comment(1)
PEG.js is not maintained anymore, but there is a fork called Peggy.Ambriz
N
10

There is in fact one for Javascript: OMeta. http://www.tinlizzie.org/ometa/

I also implemented a version of this in Python: http://github.com/python-parsley/parsley

Noletta answered 17/9, 2008 at 3:20 Comment(0)
A
4

There is php PEG (this is a maintained fork)

This post is really old but I found it through Google, and It should have been answered

Ambriz answered 15/3, 2011 at 22:29 Comment(0)
P
2

Language.js:

Language.js is an open source experimental new parser based on PEG (Parsing Expression Grammar), with the special addition of the "naughty OR" operator to handle errors in a unique new way. It makes use of memoization to achieve linear time parsing speed

Pintle answered 12/11, 2012 at 2:46 Comment(0)
P
1

There's also Kouprey for JavaScript, which is a very easy to use PEG generator/library.

Placeeda answered 1/9, 2009 at 19:22 Comment(0)
S
0

look at https://github.com/leblancmeneses/NPEG can easily be converted into php. Parse tree is created with anonymous functions.

Spree answered 25/10, 2008 at 7:20 Comment(0)
D
-3

Have you looked at ANTLR? It produces lexer and parser code, handles abstract syntax trees, lets you insert code the grammar to be injected into the lexer/parser code, and its available for a variety of languages!

Dactylic answered 17/9, 2008 at 3:21 Comment(1)
ANTLR does a lot of stuff, but it doesn't do PEGs.Noletta

© 2022 - 2024 — McMap. All rights reserved.