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

随声附和 提交于 2019-11-29 11:21:28

问题


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.


回答1:


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.




回答2:


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




回答3:


php PEG https://github.com/maetl/php-peg

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




回答4:


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




回答5:


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




回答6:


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




回答7:


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!



来源:https://stackoverflow.com/questions/79584/are-there-any-parsing-expression-grammar-peg-libraries-for-javascript-or-php

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!