39 releases

0.13.10 Feb 28, 2025
0.13.8 Nov 7, 2024
0.13.7 Jun 14, 2024
0.13.4 Jan 4, 2024
0.1.1 Dec 18, 2018

#135 in Parser tooling

Download history 3077/week @ 2025-02-18 3615/week @ 2025-02-25 3913/week @ 2025-03-04 2807/week @ 2025-03-11 3757/week @ 2025-03-18 2970/week @ 2025-03-25 2365/week @ 2025-04-01 2853/week @ 2025-04-08 3034/week @ 2025-04-15 4579/week @ 2025-04-22 2452/week @ 2025-04-29 2915/week @ 2025-05-06 2321/week @ 2025-05-13 3755/week @ 2025-05-20 3057/week @ 2025-05-27 2574/week @ 2025-06-03

12,714 downloads per month
Used in 10 crates (8 directly)

Apache-2.0/MIT

510KB
12K SLoC

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::Lexemes for that input, as well as answer basic queries about cfgrammar::Spans (e.g. extracting substrings, calculating line and column numbers).


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 }

Dependencies

~5–14MB
~161K SLoC