parsley


License

License

GroupId

GroupId

com.github.j-mie6
ArtifactId

ArtifactId

parsley_0.27
Last Version

Last Version

3.1.0
Release Date

Release Date

Type

Type

jar
Description

Description

parsley
parsley
Project URL

Project URL

https://github.com/j-mie6/parsley
Project Organization

Project Organization

com.github.j-mie6
Source Code Management

Source Code Management

https://github.com/j-mie6/Parsley

Download parsley_0.27

How to add to project

<!-- https://jarcasting.com/artifacts/com.github.j-mie6/parsley_0.27/ -->
<dependency>
    <groupId>com.github.j-mie6</groupId>
    <artifactId>parsley_0.27</artifactId>
    <version>3.1.0</version>
</dependency>
// https://jarcasting.com/artifacts/com.github.j-mie6/parsley_0.27/
implementation 'com.github.j-mie6:parsley_0.27:3.1.0'
// https://jarcasting.com/artifacts/com.github.j-mie6/parsley_0.27/
implementation ("com.github.j-mie6:parsley_0.27:3.1.0")
'com.github.j-mie6:parsley_0.27:jar:3.1.0'
<dependency org="com.github.j-mie6" name="parsley_0.27" rev="3.1.0">
  <artifact name="parsley_0.27" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.github.j-mie6', module='parsley_0.27', version='3.1.0')
)
libraryDependencies += "com.github.j-mie6" % "parsley_0.27" % "3.1.0"
[com.github.j-mie6/parsley_0.27 "3.1.0"]

Dependencies

compile (1)

Group / Artifact Type Version
ch.epfl.lamp : dotty-library_0.27 jar 0.27.0-RC1

test (1)

Group / Artifact Type Version
org.scalatest : scalatest_0.27 jar 3.2.2

Project Modules

There are no modules declared in this project.

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.character.{charLift, stringLift}

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

val natural: Parsley[Int] = digit.foldLeft1(0)((n, d) => n * 10 + d.asDigit)
natural.parse("0") // returns Success(0)
natural.parse("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

Versions

Version
3.1.0
3.0.1
3.0.0
2.8.7
2.8.6
2.8.5
2.8.4
2.8.3
2.8.2
2.8.1
2.8.0
2.7.0
2.6.2
2.6.1
2.6.0
2.5.0
2.4.4
2.4.3
2.4.2
2.4.1
2.4.0
2.3.0
2.2.2
2.2.1
2.2.0
2.1.0
2.0.1
1.6.0
1.5.1
1.5.0