All Projects → prataprc → Goparsec

prataprc / Goparsec

Licence: other
Parser combinator in Go. If there are any cross platform issues or backward compatibility issues, please reach out.

Programming Languages

go
31211 projects - #10 most used programming language
golang
3204 projects

Projects that are alternatives of or similar to Goparsec

Swiftparsec
A parser combinator library written in the Swift programming language.
Stars: ✭ 192 (-3.03%)
Mutual labels:  parser-combinators, parser
Nom
Rust parser combinator framework
Stars: ✭ 5,987 (+2923.74%)
Mutual labels:  parser-combinators, parser
Parsica
Parsica - PHP Parser Combinators - The easiest way to build robust parsers.
Stars: ✭ 223 (+12.63%)
Mutual labels:  parser-combinators, parser
Baby
Create models from a JSON file, even a Baby can do it.
Stars: ✭ 214 (+8.08%)
Mutual labels:  parser-combinators, parser
Parsing With Haskell Parser Combinators
🔍 A step-by-step guide to parsing using Haskell parser combinators.
Stars: ✭ 72 (-63.64%)
Mutual labels:  parser-combinators, parser
Arcsecond
✨Zero Dependency Parser Combinator Library for JS Based on Haskell's Parsec
Stars: ✭ 317 (+60.1%)
Mutual labels:  parser-combinators, parser
Dev Blog
翻译、开发心得或学习笔记
Stars: ✭ 3,929 (+1884.34%)
Mutual labels:  parser-combinators, parser
Chthollylang
A simple implementation of Yet another script language Chtholly
Stars: ✭ 19 (-90.4%)
Mutual labels:  parser-combinators, parser
Parsley
An exceptionally fast parser combinator library for Scala
Stars: ✭ 31 (-84.34%)
Mutual labels:  parser-combinators, parser
Combine
A parser combinator library for Rust
Stars: ✭ 906 (+357.58%)
Mutual labels:  parser-combinators, parser
Parze
A clean, efficient parser combinator
Stars: ✭ 113 (-42.93%)
Mutual labels:  parser-combinators, parser
Cppcmb
A generic C++17 parser-combinator library with a natural grammar notation.
Stars: ✭ 108 (-45.45%)
Mutual labels:  parser-combinators, parser
Parjs
JavaScript parser-combinator library
Stars: ✭ 145 (-26.77%)
Mutual labels:  parser-combinators, parser
Parse Xml
A fast, safe, compliant XML parser for Node.js and browsers.
Stars: ✭ 184 (-7.07%)
Mutual labels:  parser
Sdk
Library for using Grafana' structures in Go programs and client for Grafana REST API.
Stars: ✭ 193 (-2.53%)
Mutual labels:  parser
Curl Trace Parser
Parser for output from Curl --trace option
Stars: ✭ 183 (-7.58%)
Mutual labels:  parser
Expressionevaluator
A Simple Math and Pseudo C# Expression Evaluator in One C# File. Can also execute small C# like scripts
Stars: ✭ 194 (-2.02%)
Mutual labels:  parser
Atldotnet
Fully managed, portable and easy-to-use C# library to read and edit audio data and metadata (tags) from various audio formats, playlists and CUE sheets
Stars: ✭ 180 (-9.09%)
Mutual labels:  parser
Snapdragon
snapdragon is an extremely pluggable, powerful and easy-to-use parser-renderer factory.
Stars: ✭ 180 (-9.09%)
Mutual labels:  parser
Pornhub Api
Unofficial API for PornHub.com in Python
Stars: ✭ 181 (-8.59%)
Mutual labels:  parser

Parser combinator library in Golang

Build Status Coverage Status GoDoc Sourcegraph Go Report Card

A library to construct top-down recursive backtracking parsers using parser-combinators. Before proceeding you might want to take at peep at theory of parser combinators. As for this package, it provides:

  • A standard set of combinators.
  • Regular expression based simple-scanner.
  • Standard set of tokenizers based on the simple-scanner.

To construct syntax-trees based on detailed grammar try with AST struct

  • Standard set of combinators are exported as methods to AST.
  • Generate dot-graph EG: dotfile for html.
  • Pretty print on the console.
  • Make debugging easier.

NOTE that AST object is a recent development and expect user to adapt to newer versions

Quick links

Combinators

Every combinator should confirm to the following signature,

    // ParsecNode type defines a node in the AST
    type ParsecNode interface{}

    // Parser function parses input text, higher order parsers are
    // constructed using combinators.
    type Parser func(Scanner) (ParsecNode, Scanner)

    // Nodify callback function to construct custom ParsecNode.
    type Nodify func([]ParsecNode) ParsecNode

Combinators take a variable number of parser functions and return a new parser function.

Using the builtin scanner

Builtin scanner library manages the input buffer and implements a cursor into the buffer. Create a new scanner instance,

    s := parsec.NewScanner(text)

The scanner library supplies method like Match(pattern), SkipAny(pattern) and Endof(), refer to for more information on each of these methods.

Panics and Recovery

Panics are to be expected when APIs are misused. Programmers might choose to ignore errors, but not panics. For example:

  • Kleene and Many combinators take one or two parsers as arguments. Less than one or more than two will throw a panic.
  • ManyUntil combinator take two or three parsers as arguments. Less than two or more than three will throw a panic.
  • Combinators accept Parser function or pointer to Parser function. Anything else will panic.
  • When using invalid regular expression to match a token.

Examples

  • expr/expr.go, implements a parsec grammar to parse arithmetic expressions.
  • json/json.go, implements a parsec grammar to parse JSON document.

Clone the repository run the benchmark suite

    $ cd expr/
    $ go test -test.bench=. -test.benchmem=true
    $ cd json/
    $ go test -test.bench=. -test.benchmem=true

To run the example program,

    # to parse expression
    $ go run tools/parsec/parsec.go -expr "10 + 29"

    # to parse JSON string
    $ go run tools/parsec/parsec.go -json '{ "key1" : [10, "hello", true, null, false] }'

Projects using goparsec

  • Monster, production system in golang.
  • GoLedger, ledger re-write in golang.

If your project is using goparsec you can raise an issue to list them under this section.

Articles

  • [Parsing by composing functions][article1-link]
  • [Parser composition for recursive grammar][article2-link]
  • [How to use the Maybe combinator][article3-link]

How to contribute

Issue Stats Issue Stats

  • Pick an issue, or create an new issue. Provide adequate documentation for the issue.
  • Assign the issue or get it assigned.
  • Work on the code, once finished, raise a pull request.
  • Goparsec is written in golang, hence expected to follow the global guidelines for writing go programs.
  • If the changeset is more than few lines, please generate a [report card][report-link].
  • As of now, branch master is the development branch.

article1-link article2-link article3-link [report-link]: https://goreportcard.com/report/github.com/prataprc/goparsec

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