33 releases

0.13.4 Jan 4, 2024
0.13.3 Sep 21, 2023
0.13.2 Aug 1, 2023
0.13.1 Jan 27, 2023
0.1.1 Dec 18, 2018

#68 in Parser tooling

Download history 882/week @ 2023-12-23 909/week @ 2023-12-30 1297/week @ 2024-01-06 696/week @ 2024-01-13 946/week @ 2024-01-20 817/week @ 2024-01-27 628/week @ 2024-02-03 576/week @ 2024-02-10 843/week @ 2024-02-17 722/week @ 2024-02-24 1094/week @ 2024-03-02 1837/week @ 2024-03-09 1096/week @ 2024-03-16 784/week @ 2024-03-23 1038/week @ 2024-03-30 722/week @ 2024-04-06

4,005 downloads per month
Used in 3 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

~5–16MB
~173K SLoC