Skip to content

Commit

Permalink
fully document
Browse files Browse the repository at this point in the history
  • Loading branch information
ahqsoftwares committed Feb 3, 2025
1 parent 74425c1 commit 6d887e9
Show file tree
Hide file tree
Showing 9 changed files with 293 additions and 191 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -419,10 +419,12 @@ jobs:
with:
asset_path: ./leadman/build
asset_name: build
overwrite: true
upload_url: ${{ needs.tag.outputs.upload }}

- name: Undraft release
uses: actions/github-script@v7
continue-on-error: true
with:
script: |
github.rest.repos.updateRelease({
Expand Down
4 changes: 4 additions & 0 deletions interpreter/src/macros/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ macro_rules! hashmap {

#[macro_export]
macro_rules! parse {
($file:ident + $heap:ident + $args:ident:) => {};

($file:ident + $heap:ident + $args:ident: $($x:tt $y:ident),*) => {
#[allow(unused_variables)]
let [_, $($y),*] = &$args[..] else {
Expand Down Expand Up @@ -115,6 +117,8 @@ macro_rules! modify {
let Some($y) = $heap.get_mut($y) else {
interpreter::error("Invalid Format or Varible not found!", $file);
};
let $y = $y as *mut _;
let $y = unsafe { &mut *$y };
};

($file:ident + $heap:ident: > $y:ident) => {
Expand Down
1 change: 1 addition & 0 deletions lead/src/app/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ pub async fn run(args: &[String], chalk: &mut Chalk) {
chalk.blue().print(&format!("{pkg_name} "));

println!(" tried to get full heap access\n ❌ Access Denied, Exiting");
std::process::exit(1);
}
}
}
Expand Down
4 changes: 3 additions & 1 deletion lead/test/app.pb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

*run test/index

$a: malloc bool true
$a: malloc string "12"

str::to_int $a ->$a

hello init ->$a
2 changes: 1 addition & 1 deletion lead_docs_cli/src/viewer/select.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ pub fn show_doc(c: &mut Cursive) {
let doc = doc.get(name).unwrap();
let doc = doc.get(unsafe { &*page.to_show_doc.as_ref().unwrap().0 }).unwrap();

let parsed = parse(doc.replace("\n\n", "\n").replace("\n", "\n\n"));
let parsed = parse(*doc);

c.add_layer(
Dialog::around(
Expand Down
81 changes: 74 additions & 7 deletions macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ struct Usage {

impl Usage {
fn r#str(self) -> String {
format!("### {}\n```{}```", self.desc, self.code)
format!("## Usage {}\n\n```\n{}\n```", self.desc, self.code)
}
}

Expand All @@ -37,7 +37,7 @@ impl Documentation {
let fmtheader = if self.usage.is_empty() {
""
} else {
"## Format:"
"## Format:\n\n"
};

let format = self.usage.into_iter().map(|x| x.r#str()).collect::<Vec<_>>().join("\n\n");
Expand All @@ -47,6 +47,7 @@ impl Documentation {
};

format!("{}
%sig%
{fmtheader}
{format}
Expand All @@ -68,7 +69,7 @@ pub fn define(args: TokenStream, input: TokenStream) -> TokenStream {
return TokenStream::new();
};

let doc = doc.to_fn();
let mut doc: String = doc.to_fn();

let input = parse_macro_input!(input as ItemFn);

Expand All @@ -88,6 +89,8 @@ pub fn define(args: TokenStream, input: TokenStream) -> TokenStream {

let inputs = sig.inputs;

let mut sig_d = String::from("# Function Params\n\n```\n");

inputs.iter().enumerate().for_each(|(i, s)| {
match s {
FnArg::Typed(s) => {
Expand All @@ -102,10 +105,30 @@ pub fn define(args: TokenStream, input: TokenStream) -> TokenStream {
}

match typ.as_str() {
"BufValue" => parse_mut.push_str(" -> "),
"& BufValue" => parse_mut.push_str(" & "),
"& mut BufValue" => parse_mut.push_str(" mut "),
"& str" => parse_mut.push_str(" str "),
"BufValue" => {
parse_mut.push_str(" -> ");
sig_d.push_str("->$");
sig_d.push_str(&ident);
sig_d.push_str(" ");
},
"& BufValue" => {
parse_mut.push_str(" & ");
sig_d.push_str("$");
sig_d.push_str(&ident);
sig_d.push_str(" ");
},
"& mut BufValue" => {
parse_mut.push_str(" mut ");
sig_d.push_str("->&$");
sig_d.push_str(&ident);
sig_d.push_str(" ");
},
"& str" => {
parse_mut.push_str(" str ");
sig_d.push_str("<");
sig_d.push_str(&ident);
sig_d.push_str("> ");
},
s => s
.span()
.unwrap()
Expand All @@ -124,8 +147,14 @@ pub fn define(args: TokenStream, input: TokenStream) -> TokenStream {
}
});

sig_d.push_str("\n```");

parse_mut.push_str(");");

if &parse_mut == "interpreter::parse!(file + heap + args:);" {
parse_mut = String::from("");
}

let parse_mut = TokenStream2::from_str(&parse_mut).unwrap();

let new = Ident::new(&format!("_call_{}", sig.ident), sig.ident.span());
Expand Down Expand Up @@ -166,6 +195,43 @@ pub fn define(args: TokenStream, input: TokenStream) -> TokenStream {

let out = sig.output;

if params.is_empty() {
doc = doc.replace("%sig%", "");
return quote! {
#[allow(non_upper_case_globals)]
#vis static #new_doc: &'static str = #doc;

#[allow(unused)]
#vis fn #ident(args: &Vec<*const str>, mut heap: interpreter::types::HeapWrapper, file: &String, _opt: &mut interpreter::types::Options) {
let __option_code_result = #new(args, heap, file, _opt);
#other_tokens
}

#[allow(unused)]
#vis fn #new(args: &Vec<*const str>, mut heap: interpreter::types::HeapWrapper, file: &String, opt: &mut interpreter::types::Options) #out #block
}.into()
}

doc = doc.replace("%sig%", &sig_d);

if !params.to_string().contains("BufValue") {
return quote! {
#[allow(non_upper_case_globals)]
#vis static #new_doc: &'static str = #doc;

#[allow(unused)]
#vis fn #ident(args: &Vec<*const str>, mut heap: interpreter::types::HeapWrapper, file: &String, _opt: &mut interpreter::types::Options) {
#parse_mut

let __option_code_result = #new(#to_pass, file, heap);
#other_tokens
}

#[allow(unused)]
#vis fn #new(#params, file: &String, mut heap: interpreter::types::HeapWrapper) #out #block
}.into()
}

quote! {
#[allow(non_upper_case_globals)]
#vis static #new_doc: &'static str = #doc;
Expand All @@ -178,6 +244,7 @@ pub fn define(args: TokenStream, input: TokenStream) -> TokenStream {
#other_tokens
}

#[allow(unused)]
#vis fn #new(#params, file: &String) #out #block
}.into()
}
Expand Down
Loading

0 comments on commit 6d887e9

Please sign in to comment.