Skip to content

Commit

Permalink
docs: modified/add README for better segregation
Browse files Browse the repository at this point in the history
  • Loading branch information
rootCircle committed Oct 19, 2024
1 parent fe8cde3 commit 0a43416
Show file tree
Hide file tree
Showing 11 changed files with 292 additions and 68 deletions.
41 changes: 25 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
# cpast - Code Testing and Analysis Tool
# cpast_mono - Code Testing and Analysis Tool

![Crates.io](https://img.shields.io/crates/d/cpast)
![Crates.io](https://img.shields.io/crates/v/cpast)
![GitHub repo size](https://img.shields.io/github/repo-size/rootCircle/cpast)
![Crates.io](https://img.shields.io/crates/l/cpast)
![docs.rs](https://img.shields.io/docsrs/cpast)
![GitHub Workflow Status (with event)](https://img.shields.io/github/actions/workflow/status/rootCircle/cpast/general.yml)
![GitHub Actions Workflow Status](https://img.shields.io/github/actions/workflow/status/rootCircle/cpast/audit.yml?label=audit)
[![codecov](https://codecov.io/github/rootCircle/cpast/graph/badge.svg?token=O9UJP30T89)](https://codecov.io/github/rootCircle/cpast)

> We are working on making cpast, more accessible and simple for all. If you have experience with python and/or writing prompts, consider contributing to [cpast\_llm](https://github.com/rootCircle/cpast_llm) repo.
## Introduction

Have you ever found yourself stuck in the middle of a coding contest, frustrated by a bug or an elusive edge case that just won’t reveal itself? Or maybe you’ve spent countless hours comparing outputs manually, only to find that the real problem was a tricky test case you hadn’t considered. Well, I’ve been there, and I have good news: there’s a solution that can change the way you approach competitive programming forever.
Expand All @@ -30,21 +25,21 @@ Here’s the best part: with cpast, all you need is your _solution file_ and the

## Getting Started

https://github.com/user-attachments/assets/3b7d5b88-5a2a-4d01-8d5b-31f86b9a96db

<https://github.com/user-attachments/assets/3b7d5b88-5a2a-4d01-8d5b-31f86b9a96db>

### Installation

For installation instructions, refer to [cpast README](./cpast/README.md#installation).
There are two ways to use cpast:

Install docker and (optionally) [mold](https://github.com/rui314/mold) linker for faster compilation times.
```bash
cargo install --version='~0.8' sqlx-cli --no-default-features --features rustls,postgres
./cpast_api/scripts/init_db.sh
./cpast_api/scripts/init_redis.sh
```
1. **Local Installation**: Install cpast locally and get it running on your machine.
For running cpast locally, refer to [cpast README](./cpast/README.md#installation).

2. **cpast_api**: Use cpast_api, which utilizes clex and ccode_runner in parallel for optimized performance and speed.
For running cpast API locally, refer to [cpast_api README](./cpast_api/README.md).

### Usage
For development it's recommended(optional) to install [mold](https://github.com/rui314/mold) linker for faster compilation times.

### CLI Usage

Here's a simple example of how to use `cpast`:

Expand Down Expand Up @@ -73,6 +68,20 @@ At the heart of cpast is **clex**, a powerful custom language generator that giv

For more information on the `clex` language and its usage, please refer to the [Grammar Rules for Clex Generator](./clex/docs/CLEX_LANG_SPECS.md).

## Workspace Meta

We welcome you to the cpast mono-repo, where you can find all the tools and components that make up the cpast ecosystem. Here’s a brief overview of the different components you’ll find in this workspace:

| Component | Description | Status |
|--------------|-------------------------------------------------------------------------------------------------------|-----------------------|
| cpast_api | Backend for cpast, handles server-side operations and API requests. | 🚧 Work in Progress |
| cpast | CLI interface for cpast, used locally to run tests and generate inputs. | ✅ Active |
| ccode_runner | Runs arbitrary program code on local devices/server side, compiles/interprets code, and sends output. | 🔄 Needs Change |
| cpastord | Integration of cpast for Discord, allowing users to run cpast commands within Discord. | ❌ Abandoned |
| clex | Parser and generator for the clex language, generates random input for programs based on clex syntax. | ✅ Active |
| cscrapper | Scrapes question descriptions from competitive programming sites like Codeforces and CodeChef. | 🔄 Needs Improvement |
| clex_llm | Generates clex language from input format, constraints, and problem descriptions using LLM. | 🤔 Under Consideration|

## Meta

* [cpast\_llm](https://github.com/rootCircle/cpast_llm)
74 changes: 74 additions & 0 deletions ccode_runner/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# ccode_runner

`ccode_runner` is a component designed to run arbitrary program code on local devices. It compiles or interprets code and sends the output, making it an essential part of the cpast ecosystem.

## Features

- **Multi-language Support**: Supports various programming languages including Rust, Python, C, C++, Java, Ruby, and JavaScript.
- **Compilation and Interpretation**: Handles both ahead-of-time compilation and just-in-time interpretation.
- **Optimized Execution**: Uses precompilation and caching to optimize execution times.

## Getting Started

### Prerequisites

Ensure you have the necessary compilers and interpreters installed for the languages you intend to use.

### Installation

Clone the repository and navigate to the `ccode_runner` directory:

```bash
git clone https://github.com/rootCircle/cpast.git
cd cpast/ccode_runner
```

### Usage

To use `ccode_runner`, you need to integrate it within your cpast testing workflow. Below is an example of how to use it:

```rust
use ccode_runner::lang_runner::program_store::ProgramStore;
use std::path::Path;

fn main() {
let correct_file = Path::new("path/to/correct_file.rs");
let test_file = Path::new("path/to/test_file.rs");
let do_force_compile = true;

let program_store = ProgramStore::new(correct_file, test_file, do_force_compile).unwrap();

let stdin_content = "input data";
let (is_different, correct_output, test_output) = program_store
.run_codes_and_compare_output(stdin_content)
.unwrap();

println!("Outputs are different: {}", is_different);
println!("Correct Output: {}", correct_output);
println!("Test Output: {}", test_output);
}
```

### Supported Languages

- **Rust**: `.rs`
- **Python**: `.py`
- **C**: `.c`
- **C++**: `.cpp`, `.cxx`, `.c++`, `.cc`, `.C`
- **Java**: `.java`
- **JavaScript**: `.js`
- **Ruby**: `.rb`

### Compilation and Execution

`ccode_runner` uses different strategies for different languages:

- **Ahead-of-Time Compilation**: For languages like C, C++, Rust, and Java.
- **Just-in-Time Interpretation**: For languages like Python, Ruby, and JavaScript.
- **Ahead-of-Time Interpreted**: For Java, which requires converting to intermediate bytecode before execution.

ccode_runner is well suited when repeated compilation might be required for one code like in case for cpast, it intelligently skips those cases for you, making it lot faster!

## Contributing

We welcome contributions! Please read our [Contributing Guidelines](../CONTRIBUTING.md) for more details.
2 changes: 1 addition & 1 deletion ccode_runner/src/lang_runner.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
pub mod program_store;
mod runner;
pub mod runner;
pub(crate) mod runner_error_types;
2 changes: 1 addition & 1 deletion ccode_runner/src/lang_runner/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const DEFAULT_PROGRAM_NAME: &str = "program";
const EMPTY_STRING: &str = "";

#[derive(Debug)]
pub(crate) enum LanguageName {
pub enum LanguageName {
Python,
Cpp,
C,
Expand Down
50 changes: 45 additions & 5 deletions clex/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# clex - Custom Language Generator

## Introduction

**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
Expand All @@ -11,14 +9,56 @@

## Getting Started

To use clex, you can integrate it within your cpast testing workflow. For detailed instructions, please refer to the usage section of the [cpast README](../cpast/README.md).
The best way to realize clex would be to use cpast CLI, instructions to setup it up is given in [cpast README](../cpast/README.md) 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](https://rustup.rs/).

### Installation

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

```toml
[dependencies]
clex = "0.1" // Adjust the version as necessary
```

### Usage

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

## Clex Language Specification
```rust
use clex::{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](./docs/CLEX_LANG_SPECS.md).

### Examples

- `N{2}`: Generates two random integers.
- `(N) (?:N){\\1}`: Generates a random integer, then the same number of additional integers.
- `(N) (?:S[\\1,])`: Generates a random integer, then a string of that length.
- `(N) (?:S[\\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

- [Language Specification](./docs/CLEX_LANG_SPECS.md)
- [Clex FAQs](./docs/CLEX_LANG_FAQs.md)

55 changes: 53 additions & 2 deletions clex_llm/README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,61 @@
# clex_llm

Use this to generate clex from input_format and constarints.
> [!NOTE]
> Builds are currently broken for android mobiles, but we have no intention as of now to support it at this moment.
## Run tests
> [!NOTE]
> See previous efforts at [cpast_llm](https://github.com/rootCircle/cpast_llm).
**clex_llm** is a tool designed to generate [Clex](../clex/README.md) language expressions from input formats and constraints using a language model. It simplifies the process of creating complex test cases by converting human-readable descriptions into formal Clex grammar representations.

## Features

- **Automated Clex Generation**: Automatically generate Clex expressions based on input formats and constraints.
- **Integration with Google Generative AI**: Utilizes Google Generative AI for generating accurate and efficient Clex expressions.

## Getting Started

### Prerequisites

Ensure you have Rust installed on your machine. You can install Rust using [rustup](https://rustup.rs/).

### Installation

Clone the repository and navigate to the `clex_llm` directory:

```bash
git clone https://github.com/rootCircle/cpast.git
cd cpast/clex_llm
```

### Usage

To use `clex_llm`, you need to set up your Google Generative AI API key and run the tests:

```bash
GEMINI_API_KEY="<api-key>" cargo test
```

###

Example

Here’s a complete example demonstrating how to use the `clex_llm` module:

```rust
use clex_llm::{create_generator, generate_clex_expression};

#[tokio::main]
async fn main() {
let api_key = "your_google_api_key";
let generator = create_generator(api_key).unwrap();

let input_format = "The first line contains an integer K, followed by K lines each containing a floating-point number P.";
let constraints = "1 ≤ K ≤ 50\n0.0 ≤ P ≤ 1000.0";

match generate_clex_expression(&generator, input_format, constraints).await {
Ok(expression) => println!("Generated Clex Expression: {}", expression),
Err(e) => eprintln!("Error generating Clex expression: {}", e),
}
}
```
8 changes: 5 additions & 3 deletions cpast/README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
# cpast - Code Testing and Analysis Tool
# cpast_cli - Code Testing and Analysis Tool

![Crates.io](https://img.shields.io/crates/d/cpast)
![Crates.io](https://img.shields.io/crates/v/cpast)
![GitHub repo size](https://img.shields.io/github/repo-size/rootCircle/cpast)
![Crates.io](https://img.shields.io/crates/l/cpast)
![docs.rs](https://img.shields.io/docsrs/cpast)

## Introduction

**cpast** is a game-changing tool designed specifically for competitive programmers and developers who want to enhance their coding efficiency. Written in Rust for speed and reliability, cpast simplifies the process of comparing outputs from different code files, allowing you to focus on solving problems effectively.
> [!WARNING]
> Builds are currently broken for android mobiles as we recently removed clipboard support feature! We are thinking more for the fix along the way
**cpast_cli**(from now on cpast) is a game-changing _CLI_ tool designed specifically for competitive programmers and developers who want to enhance their coding efficiency. Written in Rust for speed and reliability, cpast simplifies the process of comparing outputs from different code files, allowing you to focus on solving problems effectively.

### Installation

Expand Down
45 changes: 9 additions & 36 deletions cpast_api/README.md
Original file line number Diff line number Diff line change
@@ -1,33 +1,6 @@
# Zero To Production In Rust
# cpast_api

<div align="center"><a href="https://zero2prod.com" target="_blank"><img src="https://www.zero2prod.com/assets/img/zero2prod.png" width="75%" /></a></div>

[Zero To Production In Rust](https://zero2prod.com) is an opinionated introduction to backend development using Rust.

This repository serves as supplementary material for [the book](https://zero2prod.com/): it hosts several snapshots of the codebase for our email newsletter project as it evolves throughout the book.

## Chapter snapshots

The [`main`](https://github.com/LukeMathWalker/zero-to-production) branch shows the project at the end of the book.

You can browse the project at the end of previous chapters by switching to their dedicated branches:

- [Chapter 3, Part 0](https://github.com/LukeMathWalker/zero-to-production/tree/root-chapter-03-part0)
- [Chapter 3, Part 1](https://github.com/LukeMathWalker/zero-to-production/tree/root-chapter-03-part1)
- [Chapter 4](https://github.com/LukeMathWalker/zero-to-production/tree/root-chapter-04)
- [Chapter 5](https://github.com/LukeMathWalker/zero-to-production/tree/root-chapter-05)
- [Chapter 6, Part 0](https://github.com/LukeMathWalker/zero-to-production/tree/root-chapter-06-part0)
- [Chapter 6, Part 1](https://github.com/LukeMathWalker/zero-to-production/tree/root-chapter-06-part1)
- [Chapter 7, Part 0](https://github.com/LukeMathWalker/zero-to-production/tree/root-chapter-07-part0)
- [Chapter 7, Part 1](https://github.com/LukeMathWalker/zero-to-production/tree/root-chapter-07-part1)
- [Chapter 7, Part 2](https://github.com/LukeMathWalker/zero-to-production/tree/root-chapter-07-part2)
- [Chapter 8](https://github.com/LukeMathWalker/zero-to-production/tree/root-chapter-08)
- [Chapter 9](https://github.com/LukeMathWalker/zero-to-production/tree/root-chapter-09)
- [Chapter 10, Part 0](https://github.com/LukeMathWalker/zero-to-production/tree/root-chapter-10-part0)
- [Chapter 10, Part 1](https://github.com/LukeMathWalker/zero-to-production/tree/root-chapter-10-part1)
- [Chapter 10, Part 2](https://github.com/LukeMathWalker/zero-to-production/tree/root-chapter-10-part2)
- [Chapter 10, Part 3](https://github.com/LukeMathWalker/zero-to-production/tree/root-chapter-10-part3)
- [Chapter 11](https://github.com/LukeMathWalker/zero-to-production/tree/root-chapter-11)
> Based on [Zero To Production In Rust](https://zero2prod.com), which is an opinionated introduction to backend development using Rust. Highly recommended.
## Pre-requisites

Expand All @@ -45,8 +18,8 @@ cargo install -f cargo-binutils
rustup component add llvm-tools-preview
```

```
cargo install --version="~0.7" sqlx-cli --no-default-features --features rustls,postgres
```bash
cargo install --version="~0.8" sqlx-cli --no-default-features --features rustls,postgres
```

### Linux
Expand All @@ -58,8 +31,8 @@ sudo apt-get install lld clang libssl-dev postgresql-client
sudo pacman -S lld clang postgresql
```

```
cargo install --version="~0.7" sqlx-cli --no-default-features --features rustls,postgres
```bash
cargo install --version="~0.8" sqlx-cli --no-default-features --features rustls,postgres
```

### MacOS
Expand All @@ -68,8 +41,8 @@ cargo install --version="~0.7" sqlx-cli --no-default-features --features rustls,
brew install michaeleisel/zld/zld
```

```
cargo install --version="~0.7" sqlx-cli --no-default-features --features rustls,postgres
```bash
cargo install --version="~0.8" sqlx-cli --no-default-features --features rustls,postgres
```

## How to build
Expand All @@ -92,7 +65,7 @@ Launch `cargo`:
cargo build
```

You can now try with opening a browser on http://127.0.0.1:8000/login after
You can now try with opening a browser on <http://127.0.0.1:8000/login> after
having launch the web server with `cargo run`.

There is a default `admin` account with password
Expand Down
Loading

0 comments on commit 0a43416

Please sign in to comment.