yetone / Parsec.js
A JavaScript parser combinator library inspired by Parsec of Haskell.
Stars: ✭ 12
Programming Languages
javascript
184084 projects - #8 most used programming language
haskell
3896 projects
Labels
Projects that are alternatives of or similar to Parsec.js
PigletC
A toy C-like language compiler for PigletVM
Stars: ✭ 51 (+325%)
Mutual labels: parser-combinators
Pom
PEG parser combinators using operator overloading without macros.
Stars: ✭ 310 (+2483.33%)
Mutual labels: parser-combinators
galileo
Scala Math - Numerical (Matlab-like) and Symbolic (Mathematica-like) tool
Stars: ✭ 62 (+416.67%)
Mutual labels: parser-combinators
design-patterns-for-parser-combinators
A Really Cool Calculator written in Haskell... or is it?
Stars: ✭ 29 (+141.67%)
Mutual labels: parser-combinators
leftry
Leftry - A left-recursion enabled recursive-descent parser combinator library for Lua.
Stars: ✭ 32 (+166.67%)
Mutual labels: parser-combinators
Chthollylang
A simple implementation of Yet another script language Chtholly
Stars: ✭ 19 (+58.33%)
Mutual labels: parser-combinators
Scala Parser Combinators
simple combinator-based parsing for Scala. formerly part of the Scala standard library, now a separate community-maintained module
Stars: ✭ 523 (+4258.33%)
Mutual labels: parser-combinators
parsita
The easiest way to parse text in Python
Stars: ✭ 73 (+508.33%)
Mutual labels: parser-combinators
chumsky
A parser library for humans with powerful error recovery.
Stars: ✭ 740 (+6066.67%)
Mutual labels: parser-combinators
Angstrom
Parser combinators built for speed and memory efficiency
Stars: ✭ 434 (+3516.67%)
Mutual labels: parser-combinators
parser-combinators
Lightweight package providing commonly useful parser combinators
Stars: ✭ 41 (+241.67%)
Mutual labels: parser-combinators
Arcsecond
✨Zero Dependency Parser Combinator Library for JS Based on Haskell's Parsec
Stars: ✭ 317 (+2541.67%)
Mutual labels: parser-combinators
Combo
A simple parser combinator library for Ocaml
Stars: ✭ 19 (+58.33%)
Mutual labels: parser-combinators
Pidgin
C#'s fastest parser combinator library
Stars: ✭ 469 (+3808.33%)
Mutual labels: parser-combinators
parsec.js
A JavaScript parser combinator library inspired by Parsec of Haskell.
Install:
npm install parsec.js
Examples:
import { regex, string, generate, or, plus, rshift, lshift } from 'parsec.js'
defineBinaryOperator('|', or)
defineBinaryOperator('+', plus)
defineBinaryOperator('>>', rshift)
defineBinaryOperator('<<', lshift)
const whitespace = regex('\\s*')
const lexeme = p => p << whitespace
const lbrace = lexeme(string('{'))
const rbrace = lexeme(string('}'))
const lbrack = lexeme(string('('))
const rbrack = lexeme(string(')'))
const negtive = lexeme(string('-'))
const reVarName = '[a-zA-Z_][a-zA-Z0-9_]*'
const id = lexeme(regex('\\$' + reVarName))
const attr = lexeme(regex(reVarName))
const value = id | lexeme(regex(reVarName))
const has = generate(function* has() {
yield lbrack
const _id = yield id
const _attr = yield attr
const _value = yield value
yield rbrack
return [_id, _attr, _value]
})
const oops = whitespace >> has
const s = oops.parse('($x y $z)')
console.log(s) // [ '$x', 'y', '$z' ]
More advanced sample: JSON parser
You can run: NODE_PATH=./lib babel-node examples/json.js to test this example.
Note that the project description data, including the texts, logos, images, and/or trademarks,
for each open source project belongs to its rightful owner.
If you wish to add or remove any projects, please contact us at [email protected].
