Expand description
Clex - Custom Language Generator
This module provides functionality to work with a custom language generator designed for creating test patterns. It includes methods for tokenizing, parsing, and generating code based on the custom language specification.
§Main Modules
clex_language: Module containing lexer, parser, generator, and abstract syntax tree (AST) for the custom languageclex.
§Usage
To use the clex_gen module, add it as a dependency in your Cargo.toml:
[dependencies]
clex_gen = "0.1"Import the module in your Rust code:
use clex_gen::{get_tokens, get_ast, generator};§Example
Here’s a complete example demonstrating how to use the functions provided by the clex 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);§Modules
This module consists of the following sub-modules:
lexer: Responsible for tokenizing the input language.parser: Handles the parsing of tokens to generate the Abstract Syntax Tree (AST).generator: Generates test patterns based on the parsed language specifications.
Modules§
- clex_
language - The
clex_languagemodule encompasses components related to the custom language generator, known asclex. It includes modules for Abstract Syntax Tree (AST) definition, lexer, parser, and the generator itself. Theclexlanguage is designed for defining input patterns and specifications for code testing and analysis.
Structs§
- Clex
Error - Error type that includes source context for better error messages
Functions§
- generator
- Generate code based on the custom language specification.
- get_ast
- Get the Abstract Syntax Tree (AST) from the custom language parser.
- get_
tokens - Get tokens from the custom language lexer.