DEV Community ๐Ÿ‘ฉโ€๐Ÿ’ป๐Ÿ‘จโ€๐Ÿ’ป

DEV Community ๐Ÿ‘ฉโ€๐Ÿ’ป๐Ÿ‘จโ€๐Ÿ’ป is a community of 963,673 amazing developers

We're a place where coders share, stay up-to-date and grow their careers.

Create account Log in
Lรขm
Lรขm

Posted on

Parsimmon Cheat Sheet

Reference

Formatting

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

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)
Enter fullscreen mode Exit fullscreen mode

Atoms

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

P.whitespace
P.optWhitespace
P.eof
Enter fullscreen mode Exit fullscreen mode

Top comments (0)

๐ŸŒš Friends don't let friends browse without dark mode.

Just kidding, it's a personal preference. But you can change your theme, font, etc. in your settings.

The more you know. ๐ŸŒˆ