#parser #combinators #ll #language #combine

combine-language

Extra parser combinators, useful for parsing programming languages

15 releases (6 stable)

4.0.0 Dec 14, 2020
3.0.2 Mar 21, 2019
3.0.1 Aug 23, 2018
2.0.0 Oct 20, 2016
0.5.0 Jul 17, 2015

#4 in #combine

Download history 37/week @ 2022-10-07 9/week @ 2022-10-14 17/week @ 2022-10-21 37/week @ 2022-10-28 53/week @ 2022-11-04 34/week @ 2022-11-11 26/week @ 2022-11-18 29/week @ 2022-11-25 16/week @ 2022-12-02 56/week @ 2022-12-09 15/week @ 2022-12-16 27/week @ 2022-12-23 10/week @ 2022-12-30 14/week @ 2023-01-06 10/week @ 2023-01-13 29/week @ 2023-01-20

73 downloads per month

MIT license

44KB
1K SLoC

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, EasyParser, Parser};
use combine::parser::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), "")));
}

combine

Dependencies

~785KB
~17K SLoC