All Projects → j-mie6 → Parsley

j-mie6 / Parsley

Licence: bsd-3-clause
An exceptionally fast parser combinator library for Scala

Programming Languages

scala
5932 projects

Projects that are alternatives of or similar to Parsley

Cppcmb
A generic C++17 parser-combinator library with a natural grammar notation.
Stars: ✭ 108 (+248.39%)
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 (+538.71%)
Mutual labels:  parser-combinators, parser
Parze
A clean, efficient parser combinator
Stars: ✭ 113 (+264.52%)
Mutual labels:  parser-combinators, parser
Parsing With Haskell Parser Combinators
🔍 A step-by-step guide to parsing using Haskell parser combinators.
Stars: ✭ 72 (+132.26%)
Mutual labels:  parser-combinators, parser
Dev Blog
翻译、开发心得或学习笔记
Stars: ✭ 3,929 (+12574.19%)
Mutual labels:  parser-combinators, parser
Parjs
JavaScript parser-combinator library
Stars: ✭ 145 (+367.74%)
Mutual labels:  parser-combinators, parser
Swiftparsec
A parser combinator library written in the Swift programming language.
Stars: ✭ 192 (+519.35%)
Mutual labels:  parser-combinators, parser
Baby
Create models from a JSON file, even a Baby can do it.
Stars: ✭ 214 (+590.32%)
Mutual labels:  parser-combinators, parser
Arcsecond
✨Zero Dependency Parser Combinator Library for JS Based on Haskell's Parsec
Stars: ✭ 317 (+922.58%)
Mutual labels:  parser-combinators, parser
Parsica
Parsica - PHP Parser Combinators - The easiest way to build robust parsers.
Stars: ✭ 223 (+619.35%)
Mutual labels:  parser-combinators, parser
Chthollylang
A simple implementation of Yet another script language Chtholly
Stars: ✭ 19 (-38.71%)
Mutual labels:  parser-combinators, parser
Nom
Rust parser combinator framework
Stars: ✭ 5,987 (+19212.9%)
Mutual labels:  parser-combinators, parser
Combine
A parser combinator library for Rust
Stars: ✭ 906 (+2822.58%)
Mutual labels:  parser-combinators, parser
Scalameta
Library to read, analyze, transform and generate Scala programs
Stars: ✭ 879 (+2735.48%)
Mutual labels:  parser
Anglesharp.css
👼 Library to enable support for cascading stylesheets in AngleSharp.
Stars: ✭ 27 (-12.9%)
Mutual labels:  parser
Ymlparser
YML (Yandex Market Language) parser
Stars: ✭ 14 (-54.84%)
Mutual labels:  parser
Xml Js
Converter utility between XML text and Javascript object / JSON text.
Stars: ✭ 874 (+2719.35%)
Mutual labels:  parser
Adenium
Adenium Normalizer
Stars: ✭ 29 (-6.45%)
Mutual labels:  parser
Comby
A tool for structural code search and replace that supports ~every language.
Stars: ✭ 912 (+2841.94%)
Mutual labels:  parser-combinators
Purepos
PurePos is an open source hybrid morphological tagger.
Stars: ✭ 12 (-61.29%)
Mutual labels:  parser

Parsley GitHub Workflow Status GitHub release GitHub license

What is Parsley?

Parsley is a very fast parser combinator library for Scala based on a Haskell-style Parsec API.

How do I use it? Scaladoc Maven Central Maven Central Maven Central Maven Central Maven Central

Parsley is distributed on Maven Central, and can be added to your project via:

libraryDependencies += "com.github.j-mie6" %% "parsley" % PARSLEY_VER

Documentation can be found here

Examples

import parsley.Parsley, Parsley._
import parsley.character.{char, string, digit}
import parsley.implicits.{charLift, stringLift}

val hello: Parsley[Unit] = void('h' *> ("ello" <|> "i") *> " world!")
hello.runParser("hello world!") // returns Success(())
hello.runParser("hi world!") // returns Success(())
hello.runParser("hey world!") // returns a Failure

val natural: Parsley[Int] = digit.foldLeft1(0)((n, d) => n * 10 + d.asDigit)
natural.runParser("0") // returns Success(0)
natural.runParser("123") // returns Success(123)

For more see the Wiki!

What are the differences to Haskell's Parsec?

Mostly, this library is quite similar. However, due to Scala's differences in operator characters a few operators are changed:

  • (<$>) is known as <#> or map
  • try is known as attempt
  • (<$) and ($>) are <# and #> respectively.

In addition, lift2 and lift3 are uncurried in this library: this is to provide better performance and easier usage with Scala's traditionally uncurried functions. There are also a few new operators in general to be found here!

How does it work?

Parsley represents parsers as an abstract-syntax tree AST, which is constructed lazily. As a result, Parsley is able to perform analysis and optimisations on your parsers, which helps reduce the burden on you, the programmer. This representation is then compiled into a light-weight stack-based instruction set designed to run fast on the JVM. This is what offers Parsley its competitive performance, but for best effect a parser should be compiled once and used many times (so-called hot execution).

To make recursive parsers work in this AST format, you must ensure that recursion is done by knot-tying: you should define all recursive parsers with val and introduce lazy val where necessary for the compiler to accept the definition.

Bug Reports Percentage of issues still open Maintainability Test Coverage

If you encounter a bug when using Parsley, try and minimise the example of the parser (and the input) that triggers the bug. If possible, make a self contained example: this will help me to identify the issue without too much issue.

References

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].