Skip to content

Commit

Permalink
added doc-generator
Browse files Browse the repository at this point in the history
  • Loading branch information
Sakapoi committed Oct 30, 2023
1 parent dbb6cf0 commit d79b8ed
Show file tree
Hide file tree
Showing 25 changed files with 2,084 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ members = [
"tooling/bb_abstraction_leaks",
"tooling/lsp",
"tooling/debugger",
"tooling/doc_generator",
"tooling/nargo",
"tooling/nargo_fmt",
"tooling/nargo_cli",
Expand Down Expand Up @@ -56,6 +57,7 @@ nargo_cli = { path = "tooling/nargo_cli" }
nargo_toml = { path = "tooling/nargo_toml" }
noir_lsp = { path = "tooling/lsp" }
noir_debugger = { path = "tooling/debugger" }
doc_generator ={ path = "tooling/doc_generator"}
noirc_abi = { path = "tooling/noirc_abi" }
bb_abstraction_leaks = { path = "tooling/bb_abstraction_leaks" }
noirc_driver = { path = "compiler/noirc_driver" }
Expand Down
10 changes: 10 additions & 0 deletions tooling/doc_generator/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[package]
name = "doc-generator"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
askama = "0.12"
noirc_frontend = {git = "https://github.com/Sakapoi/noir_fork.git", branch = "doc_comments"}
31 changes: 31 additions & 0 deletions tooling/doc_generator/Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Noir doc generator

## General information

This program generates the documentation files for the Noir language. The input files with Noir code are placed in the `input_files` folder. When you run the program with `cargo run`, the documentation files in the `generated_doc` folder are generated.

## Screenshots

### Main page

![mainpage](Screenshots/Main_page.png)

### Code page

![codepage](Screenshots/Code_page.png)

### Function page

![functionpage](Screenshots/Function_page.png)

### Structure page

![structpage](Screenshots/Struct_page.png)

### Trait page

![traitpage](Screenshots/Trait_page.png)

### Search page

![searchpage](Screenshots/Search_page.png)
Binary file added tooling/doc_generator/Screenshots/Code_page.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tooling/doc_generator/Screenshots/Main_page.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tooling/doc_generator/Screenshots/Search_page.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tooling/doc_generator/Screenshots/Trait_page.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tooling/doc_generator/Screenshots/search.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 12 additions & 0 deletions tooling/doc_generator/input_files/another_module.nr
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
fn main1(x : Field, y : pub Field) {
assert(x != y);
}

struct MyStruct1 {
mana: i32,
name: String,
}

impl MyStruct1 {
fn new() {}
}
7 changes: 7 additions & 0 deletions tooling/doc_generator/input_files/function_example.nr
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
///doc comment
/*
This is a block comment describing a complex function.
*/
fn main(x : Field, y : pub Field) {
assert(x != y);
}
244 changes: 244 additions & 0 deletions tooling/doc_generator/input_files/prog.nr
Original file line number Diff line number Diff line change
@@ -0,0 +1,244 @@
//! Note the documentation for the primitives **str** and **[T]** (also
//! called 'slice'). Many method calls on **String** and **Vec<T>** are actually
//! calls to methods on **str** and **[T]** respectively, via **deref
//! coercions**.


///doc comment
/*
This is a block comment describing a complex function.
*/
fn main(x : Field, y : pub Field) {
assert(x != y);
}

///qwe
///rty
fn simple_fn(){}

///qwe
///rty
pub fn pub_fn(){}

//! Data available to helper can be found in [Helper](struct.Helper.html). And there are more
//! examples in [HelperDef](trait.HelperDef.html) page.
//!
//! You can learn more about helpers by looking into source code of built-in helpers.
//!
//! Like our JavaScript counterparts, handlebars allows user to define simple helpers with
//! a scripting language, [rhai](https://docs.rs/crate/rhai/). This can be enabled by
//! turning on `script_helper` feature flag.
/// struct
struct MyStruct {
mana: i32,
name: String,
}

///a
///lot
///of
/**
doc
comments
*/
fn another_fn(){}

pub struct AnotherStruct {
pub name: String,
pub number: i32,
}

impl MyStruct {
fn new() {}
}

impl<X: SampleUniform> MyStruct<X> {
/// Create a new `Uniform` instance which samples uniformly from the half
/// open range `[low, high)` (excluding `high`). Panics if `low >= high`.
pub fn new<B1, B2>(low: B1, high: B2) -> Uniform<X>
where
B1: SampleBorrow<X> + Sized,
B2: SampleBorrow<X> + Sized,
{
Uniform(X::Sampler::new(low, high))
}

/// Create a new `Uniform` instance which samples uniformly from the closed
/// range `[low, high]` (inclusive). Panics if `low > high`.
pub fn new_inclusive<B1, B2>(low: B1, high: B2) -> Uniform<X>
where
B1: SampleBorrow<X> + Sized,
B2: SampleBorrow<X> + Sized,
{
Uniform(X::Sampler::new_inclusive(low, high))
}
}

/// Range that supports generating a single sample efficiently.
///
/// Any type implementing this trait can be used to specify the sampled range
/// for `Rng::gen_range`.
pub trait SampleRange<T> {
/// Generate a sample from the given range.
fn sample_single<R: RngCore + ?Sized>(self, rng: &mut R) -> T;

/// Check whether the range is empty.
fn is_empty(&self) -> bool;
}

impl<T: SampleUniform + PartialOrd> SampleRange<T> for AnotherStruct<T> {
#[inline]
fn sample_single<R: RngCore + ?Sized>(self, rng: &mut R) -> T {
T::Sampler::sample_single(self.start, self.end, rng)
}

#[inline]
fn is_empty(&self) -> bool {
!(self.start < self.end)
}
}

/// this is a trait =-=
//! Helper trait handling actual uniform sampling.
//!
//! See the [module documentation] on how to implement [`Uniform`] range
//! sampling for a custom type.
//!
//! Implementation of [`sample_single`] is optional, and is only useful when
//! the implementation can be faster than `Self::new(low, high).sample(rng)`.
//!
//! [module documentation]: crate::distributions::uniform
//! [`sample_single`]: UniformSampler::sample_single
pub trait UniformSampler: Sized {
/// The type sampled by this implementation.
type X;

/// Construct self, with inclusive lower bound and exclusive upper bound
/// `[low, high)`.
///
/// Usually users should not call this directly but instead use
/// `Uniform::new`, which asserts that `low < high` before calling this.
fn new<B1, B2>(low: B1, high: B2) -> Self
where
B1: SampleBorrow<Self::X> + Sized,
B2: SampleBorrow<Self::X> + Sized;

/// Construct self, with inclusive bounds `[low, high]`.
///
/// Usually users should not call this directly but instead use
/// `Uniform::new_inclusive`, which asserts that `low <= high` before
/// calling this.
fn new_inclusive<B1, B2>(low: B1, high: B2) -> Self
where
B1: SampleBorrow<Self::X> + Sized,
B2: SampleBorrow<Self::X> + Sized;

/// Sample a value.
fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> Self::X;

/// Sample a single value uniformly from a range with inclusive lower bound
/// and exclusive upper bound `[low, high)`.
///
/// By default this is implemented using
/// `UniformSampler::new(low, high).sample(rng)`. However, for some types
/// more optimal implementations for single usage may be provided via this
/// method (which is the case for integers and floats).
/// Results may not be identical.
///
/// Note that to use this method in a generic context, the type needs to be
/// retrieved via `SampleUniform::Sampler` as follows:
/// ```
/// use rand::{thread_rng, distributions::uniform::{SampleUniform, UniformSampler}};
/// # #[allow(unused)]
/// fn sample_from_range<T: SampleUniform>(lb: T, ub: T) -> T {
/// let mut rng = thread_rng();
/// <T as SampleUniform>::Sampler::sample_single(lb, ub, &mut rng)
/// }
/// ```
fn sample_single<R: Rng + ?Sized, B1, B2>(low: B1, high: B2, rng: &mut R) -> Self::X
where
B1: SampleBorrow<Self::X> + Sized,
B2: SampleBorrow<Self::X> + Sized,
{
let uniform: Self = UniformSampler::new(low, high);
uniform.sample(rng)
}

fn new_fn() -> i32;

/// Sample a single value uniformly from a range with inclusive lower bound
/// and inclusive upper bound `[low, high]`.
///
/// By default this is implemented using
/// `UniformSampler::new_inclusive(low, high).sample(rng)`. However, for
/// some types more optimal implementations for single usage may be provided
/// via this method.
/// Results may not be identical.
fn sample_single_inclusive<R: Rng + ?Sized, B1, B2>(low: B1, high: B2, rng: &mut R)
-> Self::X
where B1: SampleBorrow<Self::X> + Sized,
B2: SampleBorrow<Self::X> + Sized
{
let uniform: Self = UniformSampler::new_inclusive(low, high);
uniform.sample(rng)
}
}

impl UniformSampler for UniformChar {
type X = char;

#[inline] // if the range is constant, this helps LLVM to do the
// calculations at compile-time.
fn new<B1, B2>(low_b: B1, high_b: B2) -> Self
where
B1: SampleBorrow<Self::X> + Sized,
B2: SampleBorrow<Self::X> + Sized,
{
let low = char_to_comp_u32(*low_b.borrow());
let high = char_to_comp_u32(*high_b.borrow());
let sampler = UniformInt::<u32>::new(low, high);
UniformChar { sampler }
}

#[inline] // if the range is constant, this helps LLVM to do the
// calculations at compile-time.
fn new_inclusive<B1, B2>(low_b: B1, high_b: B2) -> Self
where
B1: SampleBorrow<Self::X> + Sized,
B2: SampleBorrow<Self::X> + Sized,
{
let low = char_to_comp_u32(*low_b.borrow());
let high = char_to_comp_u32(*high_b.borrow());
let sampler = UniformInt::<u32>::new_inclusive(low, high);
UniformChar { sampler }
}

fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> Self::X {
let mut x = self.sampler.sample(rng);
if x >= CHAR_SURROGATE_START {
x += CHAR_SURROGATE_LEN;
}
// SAFETY: x must not be in surrogate range or greater than char::MAX.
// This relies on range constructors which accept char arguments.
// Validity of input char values is assumed.
unsafe { core::char::from_u32_unchecked(x) }
}
}

mod MyModule {
///module function
fn module_fn() {
let a = 100;
}

struct MyStruct {
mana: i32,
name: String,
}
}

mod another_module;

fn yes () {}
5 changes: 5 additions & 0 deletions tooling/doc_generator/input_files/struct_example.nr
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
///struct
struct MyStruct {
mana: i32,
name: String,
}
Loading

0 comments on commit d79b8ed

Please sign in to comment.