Crate cpast

source ·
Expand description

§cpast - Code Testing and Analysis Tool

cpast is a versatile code testing and analysis tool that empowers users in competitive programming and coding practice. It allows testing correct and incorrect code files against a custom language generator called clex. This crate supports various programming languages, such as Python, C++, C, Rust, Ruby, JavaScript, and Java, and enables users to specify the number of iterations for testing code against random input values.

§Main Modules

  • lang_runner: Module for language-runner-related functionalities and handling the storage and management of code programs.
  • utils: Utility module with miscellaneous functions.
  • clex_language: Module containing lexer, parser, generator, and abstract syntax tree (AST) for the custom language clex.


The crate provides solutions to common challenges faced by competitive programmers and coding enthusiasts, such as verifying code correctness, efficient testing under time constraints, and quick debugging to improve code performance.


To get started with cpast, users can use the provided functions:

  • compile_and_test: Compiles and tests code against a custom language generator.
  • get_tokens: Retrieves tokens from the custom language lexer.
  • get_ast: Obtains the Abstract Syntax Tree (AST) from the custom language parser.
  • generator: Generates code based on the custom language specification.


use cpast::{compile_and_test, get_tokens, get_ast, generator};

async fn compile() {
    compile_and_test("correct.cpp".to_string(), "".to_string(), "(N[1,10]) (?:N){\\1}".to_string(), 100, false, false).await.unwrap();

let tokens = get_tokens("(N) (?:N){\\1}".to_string());

let ast = get_ast("(N) (?:N){\\1}".to_string());

let generated_code = generator("(N) (?:N){\\1}".to_string());

For more details on usage and advanced features, refer to the README.


  • The clex_language module encompasses components related to the custom language generator, known as clex. It includes modules for Abstract Syntax Tree (AST) definition, lexer, parser, and the generator itself. The clex language is designed for defining input patterns and specifications for code testing and analysis.


  • Compile and test code against custom language generator.
  • Generate code based on the custom language specification.
  • Get the Abstract Syntax Tree (AST) from the custom language parser.
  • Get tokens from the custom language lexer.