37 releases

0.13.8 Nov 7, 2024
0.13.7 Jun 14, 2024
0.13.6 May 30, 2024
0.13.4 Jan 4, 2024
0.1.1 Dec 18, 2018

#89 in Parser tooling

Download history 1992/week @ 2024-08-03 1784/week @ 2024-08-10 1817/week @ 2024-08-17 1918/week @ 2024-08-24 1444/week @ 2024-08-31 1211/week @ 2024-09-07 1293/week @ 2024-09-14 1503/week @ 2024-09-21 1458/week @ 2024-09-28 1350/week @ 2024-10-05 2079/week @ 2024-10-12 1929/week @ 2024-10-19 1822/week @ 2024-10-26 1978/week @ 2024-11-02 1871/week @ 2024-11-09 1880/week @ 2024-11-16

7,976 downloads per month
Used in 10 crates (8 directly)

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

~5–14MB
~165K SLoC