34 releases

0.13.5 May 4, 2024
0.13.4 Jan 4, 2024
0.13.3 Sep 21, 2023
0.13.1 Jan 27, 2023
0.1.1 Dec 18, 2018

#61 in Parser tooling

Download history 847/week @ 2024-01-26 660/week @ 2024-02-02 566/week @ 2024-02-09 802/week @ 2024-02-16 752/week @ 2024-02-23 1027/week @ 2024-03-01 1665/week @ 2024-03-08 1360/week @ 2024-03-15 756/week @ 2024-03-22 1022/week @ 2024-03-29 892/week @ 2024-04-05 893/week @ 2024-04-12 1049/week @ 2024-04-19 831/week @ 2024-04-26 1438/week @ 2024-05-03 1769/week @ 2024-05-10

5,212 downloads per month
Used in 5 crates

Apache-2.0/MIT

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

Dependencies

~4–14MB
~149K SLoC