30 releases

0.13.1 Jan 27, 2023
0.12.0 Apr 14, 2022
0.11.1 Dec 7, 2021
0.11.0 Nov 18, 2021
0.1.1 Dec 18, 2018

#137 in Parser tooling

Download history 1317/week @ 2023-02-11 894/week @ 2023-02-18 846/week @ 2023-02-25 959/week @ 2023-03-04 888/week @ 2023-03-11 921/week @ 2023-03-18 995/week @ 2023-03-25 950/week @ 2023-04-01 915/week @ 2023-04-08 808/week @ 2023-04-15 693/week @ 2023-04-22 886/week @ 2023-04-29 1284/week @ 2023-05-06 692/week @ 2023-05-13 672/week @ 2023-05-20 629/week @ 2023-05-27

3,447 downloads per month
Used in 3 crates

Apache-2.0/MIT

490KB
11K SLoC

lrlex

lrlex is a partial replacement for lex / flex. It takes an input string and splits it into lexemes based on a .l file. Unfortunately, many real-world languages have corner cases which exceed the power that lrlex can provide. However, when it is suitable, it is a very convenient way of expressing lexing.

lrlex also has a simple command-line interface, allowing you to check whether your lexing rules are working as expected:

$ cat C.java
class C {
    int x = 0;
}
$ cargo run --lrlex java.l /tmp/C.java
    Finished dev [unoptimized + debuginfo] target(s) in 0.18s
     Running `target/debug/lrlex ../grammars/java7/java.l /tmp/C.java`
CLASS class
IDENTIFIER C
LBRACE {
INT int
IDENTIFIER x
EQ =
INTEGER_LITERAL 0
SEMICOLON ;
RBRACE }

lib.rs:

lrlex is a partial replacement for lex / flex. It takes in a .l file and statically compiles it to Rust code. The resulting [LRNonStreamingLexerDef] can then be given an input string, from which it instantiates an [LRNonStreamingLexer]. This provides an iterator which can produce the sequence of [lrpar::Lexeme]s for that input, as well as answer basic queries about [cfgrammar::Span]s (e.g. extracting substrings, calculating line and column numbers).

Dependencies

~3.5–9MB
~173K SLoC