All Projects → pest-parser → Pest

pest-parser / Pest

Licence: other
The Elegant Parser

Programming Languages

rust
11053 projects

Projects that are alternatives of or similar to Pest

ParsecSharp
The faster monadic parser combinator library for C#
Stars: ✭ 23 (-99.17%)
Mutual labels:  parsing, peg
ohm-editor
An IDE for the Ohm language (JavaScript edition)
Stars: ✭ 78 (-97.2%)
Mutual labels:  parsing, peg
arborist
Arborist is a PEG parser that supports left-associative left recursion
Stars: ✭ 17 (-99.39%)
Mutual labels:  parsing, peg
Ohm
A library and language for building parsers, interpreters, compilers, etc.
Stars: ✭ 3,938 (+41.5%)
Mutual labels:  peg, parsing
Rust Peg
Parsing Expression Grammar (PEG) parser generator for Rust
Stars: ✭ 836 (-69.96%)
Mutual labels:  peg, parsing
pyrser
A PEG Parsing Tool
Stars: ✭ 32 (-98.85%)
Mutual labels:  parsing, peg
cppcombinator
parser combinator and AST generator in c++17
Stars: ✭ 20 (-99.28%)
Mutual labels:  parsing, peg
parson
Yet another PEG parser combinator library and DSL
Stars: ✭ 52 (-98.13%)
Mutual labels:  parsing, peg
Cpp Peglib
A single file C++ header-only PEG (Parsing Expression Grammars) library
Stars: ✭ 435 (-84.37%)
Mutual labels:  peg, parsing
Pom
PEG parser combinators using operator overloading without macros.
Stars: ✭ 310 (-88.86%)
Mutual labels:  peg, parsing
pe
Fastest general-purpose parsing library for Python with a familiar API
Stars: ✭ 21 (-99.25%)
Mutual labels:  parsing, peg
3bmd
markdown processor in CL using esrap parser
Stars: ✭ 58 (-97.92%)
Mutual labels:  peg, parsing
latex2unicode
Convert LaTeX markup to Unicode (in Scala and Java)
Stars: ✭ 28 (-98.99%)
Mutual labels:  parsing, peg
Lug
Parsing expression grammar (PEG) embedded domain specific language and parsing machine for C++17
Stars: ✭ 44 (-98.42%)
Mutual labels:  peg, parsing
Pegtl
Parsing Expression Grammar Template Library
Stars: ✭ 1,295 (-53.47%)
Mutual labels:  peg, parsing
Pizza Sync
Pizza-Sync is a web app built on the frontend with angular, ngrx and on the backend with Nest. It let you and your friends/colleagues choose a pizza before placing a group order. Built using https://github.com/maxime1992/angular-ngrx-starter
Stars: ✭ 158 (-94.32%)
Mutual labels:  parsing
Combine
A parser combinator library for Elixir projects
Stars: ✭ 174 (-93.75%)
Mutual labels:  parsing
Cyberchef
The Cyber Swiss Army Knife - a web app for encryption, encoding, compression and data analysis
Stars: ✭ 13,674 (+391.34%)
Mutual labels:  parsing
Rats
Movie Ratings Synchronization with Python
Stars: ✭ 156 (-94.39%)
Mutual labels:  parsing
Deep Generative Models For Natural Language Processing
DGMs for NLP. A roadmap.
Stars: ✭ 185 (-93.35%)
Mutual labels:  parsing

pest. The Elegant Parser

Join the chat at https://gitter.im/dragostis/pest Book Docs

Build Status codecov Fuzzit Status Crates.io Crates.io

pest is a general purpose parser written in Rust with a focus on accessibility, correctness, and performance. It uses parsing expression grammars (or PEG) as input, which are similar in spirit to regular expressions, but which offer the enhanced expressivity needed to parse complex languages.

Getting started

The recommended way to start parsing with pest is to read the official book.

Other helpful resources:

  • API reference on docs.rs
  • play with grammars and share them on our fiddle
  • leave feedback, ask questions, or greet us on Gitter

Example

The following is an example of a grammar for a list of alpha-numeric identifiers where the first identifier does not start with a digit:

alpha = { 'a'..'z' | 'A'..'Z' }
digit = { '0'..'9' }

ident = { (alpha | digit)+ }

ident_list = _{ !digit ~ ident ~ (" " ~ ident)+ }
          // ^
          // ident_list rule is silent which means it produces no tokens

Grammars are saved in separate .pest files which are never mixed with procedural code. This results in an always up-to-date formalization of a language that is easy to read and maintain.

Meaningful error reporting

Based on the grammar definition, the parser also includes automatic error reporting. For the example above, the input "123" will result in:

thread 'main' panicked at ' --> 1:1
  |
1 | 123
  | ^---
  |
  = unexpected digit', src/main.rs:12

while "ab *" will result in:

thread 'main' panicked at ' --> 1:1
  |
1 | ab *
  |    ^---
  |
  = expected ident', src/main.rs:12

Pairs API

The grammar can be used to derive a Parser implementation automatically. Parsing returns an iterator of nested token pairs:

extern crate pest;
#[macro_use]
extern crate pest_derive;

use pest::Parser;

#[derive(Parser)]
#[grammar = "ident.pest"]
struct IdentParser;

fn main() {
    let pairs = IdentParser::parse(Rule::ident_list, "a1 b2").unwrap_or_else(|e| panic!("{}", e));

    // Because ident_list is silent, the iterator will contain idents
    for pair in pairs {
        // A pair is a combination of the rule which matched and a span of input
        println!("Rule:    {:?}", pair.as_rule());
        println!("Span:    {:?}", pair.as_span());
        println!("Text:    {}", pair.as_str());

        // A pair can be converted to an iterator of the tokens which make it up:
        for inner_pair in pair.into_inner() {
            match inner_pair.as_rule() {
                Rule::alpha => println!("Letter:  {}", inner_pair.as_str()),
                Rule::digit => println!("Digit:   {}", inner_pair.as_str()),
                _ => unreachable!()
            };
        }
    }
}

This produces the following output:

Rule:    ident
Span:    Span { start: 0, end: 2 }
Text:    a1
Letter:  a
Digit:   1
Rule:    ident
Span:    Span { start: 3, end: 5 }
Text:    b2
Letter:  b
Digit:   2

Other features

  • Precedence climbing
  • Input handling
  • Custom errors
  • Runs on stable Rust

Projects using pest

Special thanks

A special round of applause goes to prof. Marius Minea for his guidance and all pest contributors, some of which being none other than my friends.

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