parlex-gen 0.1.4

Lexer generator ALEX and parser generator ASLR
docs.rs failed to build parlex-gen-0.1.4
Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
Visit the last successful build: parlex-gen-0.3.0

parlex-gen

Crates.io Documentation License: LGPL-3.0-or-later Rust

Lexer and parser generator tools for Rust.

Overview

parlex-gen provides two code generation tools:

  • alex: Regex-based lexer generator for creating tokenizers from lexical specifications
  • aslr: SLR parser generator for building parsers from grammar definitions

Both generators produce code that uses the parlex runtime library.

Features

  • Generate regex-based lexers with alex
  • Generate SLR parsers with aslr

Installation

Add this to your Cargo.toml:

[build-dependencies]
parlex-gen = "0.1"

You'll also need the runtime library:

[dependencies]
parlex = "0.1"

Usage

Lexer Generation with alex

Create a lexer specification file and use alex to generate a lexer:

// In your build.rs
use parlex_gen::alex;

fn main() {
    let manifest_dir = std::env::var("CARGO_MANIFEST_DIR").unwrap();
    let out_dir = PathBuf::from(std::env::var("OUT_DIR").unwrap());
    let input_file = PathBuf::from(&manifest_dir).join("src/lexer.alex");
    println!("cargo:rerun-if-changed={}", input_file.display());
    println!("cargo:warning=ALEX Input file is {}", input_file.display());
    println!(
        "cargo:warning=ALEX Output directory is {}",
        out_dir.display()
    );
    // Generate lexer from specification
    alex::generate(&input_file, &out_dir, "lexer_data", false).unwrap();
}

Parser Generation with aslr

Create a grammar file and use aslr to generate an SLR parser:

// In your build.rs
use parlex_gen::aslr;

fn main() {
    let manifest_dir = std::env::var("CARGO_MANIFEST_DIR").unwrap();
    let input_file = PathBuf::from(&manifest_dir).join("src/parser.g");
    println!("cargo:rerun-if-changed={}", input_file.display());
    println!("cargo:warning=ASLR Input file is {}", input_file.display());
    println!(
        "cargo:warning=ASLR Output directory is {}",
        out_dir.display()
    );
    // Generate parser from specification
    parlex_gen::aslr::generate(&input_file, &out_dir, "parser_data", false).unwrap();
}

Architecture

The generation process follows these steps:

  1. Specification: Define your lexer rules or grammar
  2. Generation: Run alex and/or aslr to generate Rust code
  3. Integration: The generated code uses parlex traits and data structures
  4. Customization: Build your custom lexer/parser using the generated code and parlex

Documentation

For detailed API documentation and examples, visit docs.rs/parlex-gen.

License

Copyright (c) 2005–2025 IKH Software, Inc.

Released under the terms of the GNU Lesser General Public License, version 3.0 or (at your option) any later version (LGPL-3.0-or-later).

See Also