All Projects → Marwes → Combine

Marwes / Combine

Licence: mit
A parser combinator library for Rust

Programming Languages

rust
11053 projects

Projects that are alternatives of or similar to Combine

Parsing With Haskell Parser Combinators
🔍 A step-by-step guide to parsing using Haskell parser combinators.
Stars: ✭ 72 (-92.05%)
Mutual labels:  parser-combinators, parser
Chthollylang
A simple implementation of Yet another script language Chtholly
Stars: ✭ 19 (-97.9%)
Mutual labels:  parser-combinators, parser
Cppcmb
A generic C++17 parser-combinator library with a natural grammar notation.
Stars: ✭ 108 (-88.08%)
Mutual labels:  parser-combinators, parser
Parsley
An exceptionally fast parser combinator library for Scala
Stars: ✭ 31 (-96.58%)
Mutual labels:  parser-combinators, parser
Parsica
Parsica - PHP Parser Combinators - The easiest way to build robust parsers.
Stars: ✭ 223 (-75.39%)
Mutual labels:  parser-combinators, parser
Parze
A clean, efficient parser combinator
Stars: ✭ 113 (-87.53%)
Mutual labels:  parser-combinators, parser
Parjs
JavaScript parser-combinator library
Stars: ✭ 145 (-84%)
Mutual labels:  parser-combinators, parser
Swiftparsec
A parser combinator library written in the Swift programming language.
Stars: ✭ 192 (-78.81%)
Mutual labels:  parser-combinators, parser
Baby
Create models from a JSON file, even a Baby can do it.
Stars: ✭ 214 (-76.38%)
Mutual labels:  parser-combinators, parser
Goparsec
Parser combinator in Go. If there are any cross platform issues or backward compatibility issues, please reach out.
Stars: ✭ 198 (-78.15%)
Mutual labels:  parser-combinators, parser
Dev Blog
翻译、开发心得或学习笔记
Stars: ✭ 3,929 (+333.66%)
Mutual labels:  parser-combinators, parser
Arcsecond
✨Zero Dependency Parser Combinator Library for JS Based on Haskell's Parsec
Stars: ✭ 317 (-65.01%)
Mutual labels:  parser-combinators, parser
Nom
Rust parser combinator framework
Stars: ✭ 5,987 (+560.82%)
Mutual labels:  parser-combinators, parser
Php Parser
PHP parser written in Go
Stars: ✭ 787 (-13.13%)
Mutual labels:  parser
Bytecode
Fast, lightweight Java bytecode parsing and manipulation library.
Stars: ✭ 17 (-98.12%)
Mutual labels:  parser
Node Csv Parse
CSV parsing implementing the Node.js `stream.Transform` API
Stars: ✭ 768 (-15.23%)
Mutual labels:  parser
Dasel
Query, update and convert data structures from the command line. Comparable to jq/yq but supports JSON, TOML, YAML, XML and CSV with zero runtime dependencies.
Stars: ✭ 759 (-16.23%)
Mutual labels:  parser
Combo
A simple parser combinator library for Ocaml
Stars: ✭ 19 (-97.9%)
Mutual labels:  parser-combinators
Fuzi
A fast & lightweight XML & HTML parser in Swift with XPath & CSS support
Stars: ✭ 894 (-1.32%)
Mutual labels:  parser
Himalaya
JavaScript HTML to JSON Parser
Stars: ✭ 758 (-16.34%)
Mutual labels:  parser

combine

Build Status Docs v3 Docs Gitter

An implementation of parser combinators for Rust, inspired by the Haskell library Parsec. As in Parsec the parsers are LL(1) by default but they can opt-in to arbitrary lookahead using the attempt combinator.

Example

extern crate combine;
use combine::{many1, Parser, sep_by};
use combine::parser::char::{letter, space};

// Construct a parser that parses *many* (and at least *1) *letter*s
let word = many1(letter());

// Construct a parser that parses many *word*s where each word is *separated by* a (white)*space*
let mut parser = sep_by(word, space())
    // Combine can collect into any type implementing `Default + Extend` so we need to assist rustc
    // by telling it that `sep_by` should collect into a `Vec` and `many1` should collect to a `String`
    .map(|mut words: Vec<String>| words.pop());
let result = parser.parse("Pick up that word!");
// `parse` returns `Result` where `Ok` contains a tuple of the parsers output and any remaining input.
assert_eq!(result, Ok((Some("word".to_string()), "!")));

A tutorial as well as explanations on what goes on inside combine can be found in the wiki.

Larger examples can be found in the examples, tests and benches folders.

Links

Documentation and examples

crates.io

Features

  • Parse arbitrary streams - Combine can parse anything from &[u8] and &str to iterators and Read instances. If none of the builtin streams fit your use case you can even implement a couple traits your self to create your own custom stream!

  • zero-copy parsing - When parsing in memory data, combine can parse without copying. See the range module for parsers specialized for zero-copy parsing.

  • partial parsing - Combine parsers can be stopped at any point during parsing and later be resumed without losing any progress. This makes it possible to start parsing partial data coming from an io device such as a socket without worrying about if enough data is present to complete the parse. If more data is needed the parser will stop and may be resumed at the same point once more data is available. See the async example for an example and this post for an introduction.

About

A parser combinator is, broadly speaking, a function which takes several parsers as arguments and returns a new parser, created by combining those parsers. For instance, the many parser takes one parser, p, as input and returns a new parser which applies p zero or more times. Thanks to the modularity that parser combinators gives it is possible to define parsers for a wide range of tasks without needing to implement the low level plumbing while still having the full power of Rust when you need it.

The library adheres to semantic versioning.

If you end up trying it I welcome any feedback from your experience with it. I am usually reachable within a day by opening an issue, sending an email or posting a message on Gitter.

FAQ

Why does my errors contain inscrutable positions?

Since combine aims to crate parsers with little to no overhead, streams over &str and &[T] do not carry any extra position information, but instead, they only rely on comparing the pointer of the buffer to check which Stream is further ahead than another Stream. To retrieve a better position, either call translate_position on the PointerOffset which represents the position or wrap your stream with State.

How does it compare to nom?

https://github.com/Marwes/combine/issues/73 contains discussion and links to comparisons to nom.

Parsers written in combine

Formats and protocols

Miscellaneous

Extra

There is an additional crate which has parsers to lex and parse programming languages in combine-language.

You can find older versions of combine (parser-combinators) here.

Contributing

Current master is the 3.0.0 branch. If you want to submit a fix or feature to the 2.x version of combine then do so to the 2.x branch or submit the PR to master and request that it be backported.

The easiest way to contribute is to just open an issue about any problems you encounter using combine but if you are interested in adding something to the library here is a list of some of the easier things to work on to get started.

  • Add additional parsers If you have a suggestion for another parser just open an issue or a PR with an implementation.
  • Add additional examples More examples for using combine will always be useful!
  • Add and improve the docs Not the fanciest of work but one cannot overstate the importance of good documentation.
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].