Live data from Hacker News

What the heck is a parser-combinator?

kimpel.com

1–10 of 74 posts

Re: What the heck is a parser-combinator?

#3
Gotta love Parsec for Haskell and pyparsing for Python. Some other awesome parsing libs:

PEGTL - C++ Parsing Expression Grammar Template Library https://github.com/taocpp/PEGTL

Parboiled - Java & Scala PEG Library https://github.com/sirthias/parboiled

Nom - Rust parser combinator framework https://github.com/Geal/nom

Nearley - JavaScript parser toolkit https://github.com/Hardmath123/nearley

Neotoma - Erlang library and packrat parser-generator for PEGs https://github.com/seancribbs/neotoma

Re: What the heck is a parser-combinator?

#6
post #3

Gotta love Parsec for Haskell and pyparsing for Python. Some other awesome parsing libs: PEGTL - C++ Parsing Expression Grammar Template Library https://github.com/taocpp/PEGTL Parboiled - Java & Scala PEG Library https://github.com/sirthias/parboiled Nom - Rust parser combinator framework https://github.com/Geal/nom Nearley - JavaScript parser toolkit https://github.com/Hardmath123/nearley Neotoma - Erlang library a…

I've used Nom to parse a couple RFC-based protocols now, and I'm amazed at how easy and performant the result ends up being.

There's a great walk-through of using it here, including fuzzing your parsers to make sure they're solid. https://github.com/Geal/langsec-2017-hackathon-code

Re: What the heck is a parser-combinator?

#9
Consider the most basic parsers you might want. For instance, a parser that only succeeds if it matches a string exactly, a parser that matches any single character and always succeeds, a parser that matches nothing and returns some constant, a parser that always fails. They're all simple and stupid and let's give them names:

    string("foobar") : Parser
    char : Parser
    always(x: A): Parser
    never: Parser
These are parser combinators. They form the atoms at the foundation of a language for constructing parsers. For instance, we can imagine two parsers happening in sequence

    then(a: Parser, b: Parser): Parser

    then(char, char): Parser
Or more fancily, a two parsers happening in sequence, but the second parser being defined using the output of the first. This creates context sensitivity

    thenDependent(a: Parser, b: A -> Parser): Parser
We're constructing a fundamental language for building parsers up from our atoms to larger and larger things. All we need now is a way to "run" them

    run(p: Parser): String -> Option
Tada---parser combinators!

Re: What the heck is a parser-combinator?

#10
post #3

Gotta love Parsec for Haskell and pyparsing for Python. Some other awesome parsing libs: PEGTL - C++ Parsing Expression Grammar Template Library https://github.com/taocpp/PEGTL Parboiled - Java & Scala PEG Library https://github.com/sirthias/parboiled Nom - Rust parser combinator framework https://github.com/Geal/nom Nearley - JavaScript parser toolkit https://github.com/Hardmath123/nearley Neotoma - Erlang library a…

I haven't tried pyparsing, but I enjoyed implementing a simple DSL with funcparserlib having no previous experience with parser combinators: https://github.com/vlasovskikh/funcparserlib

The library has a well-written tutorial that doesn't require previous knowledge about parser combinators.

Post reply on HN