Skip to content

Commit

Permalink
refactor: update macro documentation and rename AcquireCollector to A…
Browse files Browse the repository at this point in the history
…cquireParser
  • Loading branch information
kaorlol committed Dec 23, 2024
1 parent d6479f5 commit c4b8fee
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 14 deletions.
27 changes: 15 additions & 12 deletions src/macros.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
// Ignoring the full paths, i like using full paths for macros.

/// Make a lua function call:
/// -- path
/// Make a lua function call:\
/// ```lua
/// -- path.lua
/// (function(...) ... end)();
/// ```
#[macro_export]
macro_rules! make_function_call {
($path:expr, $ast:expr, $suffixes:expr) => {
Expand Down Expand Up @@ -42,7 +44,8 @@ macro_rules! make_function_call {
},
)))
.with_suffixes({
let new: Vec<full_moon::ast::Suffix> = vec![full_moon::ast::Suffix::Call(
let mut new_suffixes = Vec::new();
new_suffixes.push(full_moon::ast::Suffix::Call(
full_moon::ast::Call::AnonymousCall(full_moon::ast::FunctionArgs::Parentheses {
parentheses: full_moon::ast::span::ContainedSpan::new(
full_moon::tokenizer::TokenReference::symbol("(").unwrap(),
Expand Down Expand Up @@ -72,19 +75,20 @@ macro_rules! make_function_call {
}
},
),
// full_moon::tokenizer::TokenReference::symbol(")").unwrap(),
),
arguments: full_moon::ast::punctuated::Punctuated::new(),
}),
)]
.into_iter()
.chain($suffixes.into_iter())
.collect();
new
));
new_suffixes.extend($suffixes.into_iter());
new_suffixes
})
};
}

/// Gets the end position of a token,
/// if there is trailing whitespace it will return the end of position of the whitespace,
/// otherwise it will return the end position of the token.\
/// If the end position is not in the semicolons list, it will add a semicolon and a newline.
#[macro_export]
macro_rules! add_semicolon_if_needed {
($token_ref:expr, $semicolons:expr) => {
Expand All @@ -108,10 +112,9 @@ macro_rules! add_semicolon_if_needed {
}),
];

Some(trailing)
} else {
None
return Some(trailing);
}
None
})
};
}
4 changes: 2 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::time::Instant;
use darklua_core::{Configuration, GeneratorParameters, Options, Resources};

mod collector;
use collector::AcquireCollector;
use collector::AcquireParser;

mod log;
use full_moon::visitors::VisitorMut as _;
Expand Down Expand Up @@ -38,7 +38,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
info!("Parsing main.lua");
let time = Instant::now();
let ast = full_moon::parse(input.as_str()).unwrap();
let mut collector = AcquireCollector::new(args.root, args.input, args.output);
let mut collector = AcquireParser::new(args.root, args.input, args.output);
let bundled_ast = collector.visit_ast(ast);

info!(
Expand Down

0 comments on commit c4b8fee

Please sign in to comment.