1 stable release

1.0.0 Nov 1, 2021

#284 in Parser tooling

MIT/Apache

12KB
244 lines

Condex


Extract tokens by simple condition expression.

CI Crates.io Licensed Twitter

| Docs | Latest Note |

[dependencies]
condex = "1.0.0"

Example


    #[derive(Debug, Clone, Copy, PartialEq)]
    enum Token {
        TagName,
        NameType,
        Value,
        AllInOne,
    }
    impl TokenKind for Token {}

    let mut builder = CondexBuilder::new(&[
        (Token::TagName, &["@-("]),
        (Token::NameType, &["[(,]  -  :  - [,=]"]),
        (Token::Value, &["=-[,)]"]),
        (Token::AllInOne, &["@-(", "[(,]  -  :  - [,=]", "=-[,)]"]),
    ]);

    let source = "@hello-man(name: type = value, name2: type2, name3: type3 = value3)";

    for (i, c) in source.char_indices() {
        builder.test(c, i);
    }
    let finals = builder.finalize_with_source(source);
    eprintln!("{:#?}", finals);
    

Dependencies

~1.5MB
~25K SLoC