#parser #combinators #ll #language #combine

combine-language

Extra parser combinators, useful for parsing programming languages

14 releases (5 stable)

3.0.2 Mar 21, 2019
3.0.1 Aug 23, 2018
2.0.0 Oct 20, 2016
2.0.0-beta Jun 6, 2016
0.5.0 Jul 17, 2015

#108 in Parser tooling

Download history 36/week @ 2019-10-17 146/week @ 2019-10-24 32/week @ 2019-10-31 2/week @ 2019-11-07 21/week @ 2019-11-14 3/week @ 2019-11-21 33/week @ 2019-11-28 58/week @ 2019-12-05 152/week @ 2019-12-12 17/week @ 2019-12-26 2/week @ 2020-01-02 84/week @ 2020-01-09 61/week @ 2020-01-16

175 downloads per month

MIT license

43KB
964 lines

combine-language

Build Status Docs v2 Docs Gitter

This a crate providing an easy way of constructing parsers which can easily parse various programming languages. It has much of the same API as Text.Parsec.Token but are otherwise a bit different to fit in to the ownership model of rust. The crate is an extension of the combine crate.

Example

extern crate combine;
extern crate combine_language;
use combine::{satisfy, Parser};
use combine::char::{alpha_num, letter, string};
use combine_language::{Identifier, LanguageEnv, LanguageDef};
fn main() {
    let env = LanguageEnv::new(LanguageDef {
        ident: Identifier {
            start: letter(),
            rest: alpha_num(),
            reserved: ["if", "then", "else", "let", "in", "type"].iter()
                                                                 .map(|x| (*x).into())
                                                                 .collect(),
        },
        op: Identifier {
            start: satisfy(|c| "+-*/".chars().any(|x| x == c)),
            rest: satisfy(|c| "+-*/".chars().any(|x| x == c)),
            reserved: ["+", "-", "*", "/"].iter().map(|x| (*x).into()).collect()
        },
        comment_start: string("/*").map(|_| ()),
        comment_end: string("*/").map(|_| ()),
        comment_line: string("//").map(|_| ()),
    });
    let id = env.identifier();//An identifier parser
    let integer = env.integer();//An integer parser
    let result = (id, integer).easy_parse("this /* Skips comments */ 42");
    assert_eq!(result, Ok(((String::from("this"), 42), "")));
}

Links

combine

Dependencies

~1MB
~18K SLoC