clex_gen

Crates.ioclex_gen
lib.rsclex_gen
version0.3.4
created_at2025-02-22 00:24:43.673922+00
updated_at2025-08-10 21:34:23.123532+00
descriptionA generator for clex language
homepagehttps://rootcircle.github.io/blog/project/cpast.html
repositoryhttps://github.com/rootCircle/cpast_mono
max_upload_size
id1564949
size137,167
Lab Rat (rootCircle)

documentation

README

clex - Custom Language Generator

Crates.io Crates.io Crates.io docs.rs Crates.io Size Crates.io MSRV

[!NOTE] Since clex name was already reserved we moved to clex_gen for this generator.

clex is a powerful language generator designed specifically for creating random test cases. It allows you to automate the generation of complex input scenarios, enabling developers to stress-test their code effectively.

Features

  • Customizable Patterns: Define and automate input patterns using a specialized syntax.
  • Integration with cpast: Works seamlessly with the cpast tool for enhanced debugging and testing.

Getting Started

The best way to realize clex would be to use cpast CLI, instructions to setup it up is given in cpast README or you can use it as a lib as well.

Prerequisites

Ensure you have Rust installed on your machine. You can install Rust using rustup.

Installation

To install clex, add it as a dependency in your Cargo.toml:

[dependencies]
clex_gen = "0.1" 

Usage

Here’s a complete example demonstrating how to use the functions provided by the clex_gen module:

use clex_gen::{get_tokens, get_ast, generator};

// Get tokens from custom language
let tokens = get_tokens("(N) (?:N){\\1}".to_string()).unwrap();
println!("Tokens: {:?}", tokens);

// Get the Abstract Syntax Tree (AST)
let ast = get_ast("(N) (?:N){\\1}".to_string()).unwrap();
println!("AST: {:?}", ast);

// Generate code based on the custom language specification
let generated_code = generator("(N[1,10]) (?:N){\\1}".to_string()).unwrap();
println!("Generated Code: {}", generated_code);

Clex Language Specification

For more information on the clex language and its usage, refer to the Clex Language Specs.

Examples

  • N{2}: Generates two random integers.
  • (N) (?:N){\1}: Generates a random integer, then the same number of additional integers.
  • (N) (?:S[\1, \1,]): Generates a random integer, then a string of that length.
  • (N) (?:S[\1, \1,@CH_UPPER@]): Generates a random integer followed by a random string of uppercase letters, where the length of the string is equal to the generated integer.
  • N S C: Generates a random integer, string, and character.
  • F[-100,100]: Generates a random floating-point number between -100 and 100.
  • (N[1,100]) (?:N[1,1000]){\1} N[1,10000]: Captures a random integer between 1 and 100, then generates that many integers between 1 and 1000, followed by another integer between 1 and 10000.

Meta

Commit count: 246

cargo fmt