All Projects → gkappler → CombinedParsers.jl

gkappler / CombinedParsers.jl

Licence: MIT license
Compiled parser combinators and regular expressions in pure julia

Programming Languages

julia
2034 projects

Projects that are alternatives of or similar to CombinedParsers.jl

Combine
A parser combinator library for Elixir projects
Stars: ✭ 174 (+128.95%)
Mutual labels:  parser-combinators
autumn
A Java parser combinator library written with an unmatched feature set.
Stars: ✭ 112 (+47.37%)
Mutual labels:  parser-combinators
SuperCombinators
[Deprecated] A Swift parser combinator framework
Stars: ✭ 19 (-75%)
Mutual labels:  parser-combinators
Swiftparsec
A parser combinator library written in the Swift programming language.
Stars: ✭ 192 (+152.63%)
Mutual labels:  parser-combinators
Parsica
Parsica - PHP Parser Combinators - The easiest way to build robust parsers.
Stars: ✭ 223 (+193.42%)
Mutual labels:  parser-combinators
Syntax
Write value-driven parsers quickly in Swift with an intuitive SwiftUI-like DSL
Stars: ✭ 134 (+76.32%)
Mutual labels:  parser-combinators
Parjs
JavaScript parser-combinator library
Stars: ✭ 145 (+90.79%)
Mutual labels:  parser-combinators
Ramble
A R parser based on combinatory parsers.
Stars: ✭ 19 (-75%)
Mutual labels:  parser-combinators
Funcparserlib
Recursive descent parsing library for Python based on functional combinators
Stars: ✭ 250 (+228.95%)
Mutual labels:  parser-combinators
jasentaa
A parser combinator library for Clojure and ClojureScript
Stars: ✭ 53 (-30.26%)
Mutual labels:  parser-combinators
Goparsec
Parser combinator in Go. If there are any cross platform issues or backward compatibility issues, please reach out.
Stars: ✭ 198 (+160.53%)
Mutual labels:  parser-combinators
Baby
Create models from a JSON file, even a Baby can do it.
Stars: ✭ 214 (+181.58%)
Mutual labels:  parser-combinators
Kt2Dart
🔦 [Deprecated] Transpile Kotlin codes into Dart, Make Flutter Great Again
Stars: ✭ 84 (+10.53%)
Mutual labels:  parser-combinators
Fireward
A concise and readable language for Firestore security rules, similar to Firebase Bolt.
Stars: ✭ 174 (+128.95%)
Mutual labels:  parser-combinators
metal
A Java library for parsing binary data formats, using declarative descriptions.
Stars: ✭ 13 (-82.89%)
Mutual labels:  parser-combinators
Parseback
A Scala implementation of parsing with derivatives
Stars: ✭ 168 (+121.05%)
Mutual labels:  parser-combinators
XParsec
extensible, type-and-source-polymorphic, non-linear applicative parser combinator library for F# 3.0 and 4.0
Stars: ✭ 40 (-47.37%)
Mutual labels:  parser-combinators
parser-lang
A parser combinator library with declarative superpowers
Stars: ✭ 25 (-67.11%)
Mutual labels:  parser-combinators
ParsecSharp
The faster monadic parser combinator library for C#
Stars: ✭ 23 (-69.74%)
Mutual labels:  parser-combinators
mecha
A parser combinator library for Zig
Stars: ✭ 220 (+189.47%)
Mutual labels:  parser-combinators

CombinedParsers in pure Julia

Dev Build Status Codecov A package for combining parsers and transforming strings into julia types.

Compose parsers parsimoneously within a functional parser combinator paradigm, utilize Julia's type inference for transformations, log conveniently for debugging, and let Julia compile your parser for performance.

The CombinedParsers design

  • is fast due to Julia parametric types, and compiler optimizations with generated functions,
  • parsing result transformations infer the domain data types,
  • is composable and optimizable with Julia method dispatch,
  • provides flexible public API for parsing, matching, iteration
  • can be defined with PCRE and EBNF syntax.

Getting started

CombinedParsers.jl is a registered package. Install with

] add CombinedParsers

Example: rational numbers arithmetics

This example demonstrates reading of arithmetical terms for rational numbers. Reflecting operator precedence, term are subterms, interleaved by */, and subterms are Either integer numbers

@syntax subterm = Either{Rational{Int}}([NumericParser(Int)]; convert=true)

or a subterm can also be an additive term in parentheses:

@syntax for parentheses in subterm
    mult = evaluate |> join(subterm, CharIn("*/"), infix=:prefix )
    @syntax term = evaluate |> join(mult,    CharIn("+-"), infix=:prefix )
    Sequence(2,'(',term,')')
end

This CombinedParser definition in 5,5 lines registers a @term_string macro for parsing and evaluating rational arithmetics:

julia> term"4*10+2"
42//1

Is every rational answer ultimately the inverse of a universal question in life?

Details in the full documentation example.

Acknowledgements

This package leverages Julia's compiler and superior type system to parsing.

I am thankful for contributions and inspiration from many great packages:

TextParse.jl

A bunch of fast text parsing tools, used in CSV.jl

CombinedParsers composes with fast TextParse.jl both ways because CombinedParser <: TextParse.AbstractToken and by providing a method for TextParse.tryparsenext, (leveraging the supreme Julia compiler, type and package architecture).

  • If you seek support with a CSV example, please contact me (e.g. address text field parsing).

Inspirations

  • The work was strongly inspired by the great Scala fastparse package, and also the elm parser.
  • Parsers.jl, a collection of parsers for date and primitive types, inspired the parse methods.
  • Automa.jl, a Julia package for text validation, parsing, and tokenizing based on state machine compiler. The package compiles deterministic finite automata. (Currently there is no inter-operation possible, because in Automa processing of parsed tokens is done with actions).
  • ParserCombinator.jl was a great inspiration. Yet I decided for a new design with a focus on transformations and type inference with parametric types, instead of basing this work off ParserCombinator, written before 2016 (and fixed for Julia 1.0 in 2018). CombinedParsers integrates into the Julia 1.0 Iteration API, small Union{Nothing,T} where T types instead of using Nullables, compiler optimizations and generated functions. I want to provide benchmarks comparisons with ParserCombinator.jl.

Next Steps

  • Syntax freeze -- your comments are appreciated!
  • decide for a error tracing strategy, backtracking. If you want to collaborate on stepping & debugging, please reach out to me.
  • Performance optimizations
  • streaming
  • test coverage underestimated (PCRE tests are not included in travis)
  • Code Style: Blue

Contributing and Questions

Contributions and feedback are very welcome, especially regarding brief syntax and constructor dispatch. Please open an issue if you encounter any problems or would just like to ask a question, or contact me at [email protected].

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