Menu

gitpiper

Parsimmon Cheat Sheet in June 2024

Last Updated: 8 June 2024

README.md

const P = require('parsimmon')

P.regexp(/[a-z]+/)
.parse('hello')
//=> { status: true, value: ['hello'] }

Atoms

P.regexp(/[a-z]+/)
P.string('hello')
P.oneOf('abc')             // like P.regexp(/[abc]/)

P.whitespace
P.optWhitespace
P.eof

Combinators

P.seq(a, b, c)             // sequence of these
P.alt(a, b)                // any of these
P.sepBy(a, P.string(','))  // sequence of `a`, separated by ','
P.sepBy1(a, P.string(',')) // same, at least once

a.or(b)                    // like P.alt(a, b)
a.skip(b)                  // parses `b` but discards it

a.many()
a.times(3)
a.times(1, 4)              // 1 <= x <= 4
a.atMost(10)
a.atLeast(10)

Formatting

P.seq(P.number, P.oneOf('+-*/'), P.number)
.map(([left, oper, right]) => ({ oper, left, right }))

338+ more cheat sheets for you in June 2024

Subscribe to our Newsletter

Subscribe to get resources directly to your inbox. You won't receive any spam! ✌️

© 2024 GitPiper. All rights reserved

Rackpiper Technology Inc

Company

About UsBlogContact

Subscribe to our Newsletter

Subscribe to get resources directly to your inbox. You won't receive any spam! ✌️