Skip to content

Commit

Permalink
expsqfc
Browse files Browse the repository at this point in the history
  • Loading branch information
BrettMayson committed Feb 13, 2024
1 parent 0773b76 commit 474a796
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 16 deletions.
16 changes: 13 additions & 3 deletions bin/src/commands/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ pub fn add_args(cmd: Command) -> Command {
.help("Do not rapify (cpp, rvmat)")
.action(ArgAction::SetTrue),
)
.arg(
clap::Arg::new("expsqfc")
.long("expsqfc")
.help("Use HEMTT's experimental SQF compiler")
.action(ArgAction::SetTrue),
)
}

#[must_use]
Expand Down Expand Up @@ -86,18 +92,22 @@ pub fn execute(matches: &ArgMatches) -> Result<Report, Error> {
pub fn executor(ctx: Context, matches: &ArgMatches) -> Executor {
let mut executor = Executor::new(ctx);

let expsqfc = matches.get_one::<bool>("expsqfc") == Some(&true);

executor.collapse(Collapse::No);

executor.add_module(Box::<Hooks>::default());
if matches.get_one::<bool>("no-rap") != Some(&true) {
executor.add_module(Box::<Rapifier>::default());
}
executor.add_module(Box::<SQFCompiler>::default());
executor.add_module(Box::new(SQFCompiler { compile: expsqfc }));
#[cfg(not(target_os = "macos"))]
if !expsqfc {
executor.add_module(Box::<ArmaScriptCompiler>::default());
}
if matches.get_one::<bool>("no-bin") != Some(&true) {
executor.add_module(Box::<Binarize>::default());
}
#[cfg(not(target_os = "macos"))]
executor.add_module(Box::<ArmaScriptCompiler>::default());
executor.add_module(Box::<Files>::default());

executor.init();
Expand Down
14 changes: 12 additions & 2 deletions bin/src/commands/dev.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ pub fn add_args(cmd: Command) -> Command {
.help("Include all optional addon folders")
.action(ArgAction::SetTrue),
)
.arg(
clap::Arg::new("expsqfc")
.long("expsqfc")
.help("Use HEMTT's experimental SQF compiler")
.action(ArgAction::SetTrue),
)
}

/// Execute the dev command
Expand Down Expand Up @@ -113,15 +119,19 @@ pub fn context(matches: &ArgMatches, launch_optionals: &[String]) -> Result<Exec
}
}

let expsqfc = matches.get_one::<bool>("expsqfc") == Some(&true);

let mut executor = Executor::new(ctx);

executor.collapse(Collapse::Yes);

executor.add_module(Box::<Hooks>::default());
executor.add_module(Box::<Rapifier>::default());
executor.add_module(Box::<SQFCompiler>::default());
executor.add_module(Box::new(SQFCompiler { compile: expsqfc }));
#[cfg(not(target_os = "macos"))]
executor.add_module(Box::<ArmaScriptCompiler>::default());
if !expsqfc {
executor.add_module(Box::<ArmaScriptCompiler>::default());
}
executor.add_module(Box::<Files>::default());
executor.add_module(Box::<FilePatching>::default());
if matches.get_one::<bool>("binarize") == Some(&true) {
Expand Down
20 changes: 16 additions & 4 deletions bin/src/modules/sqf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ use crate::{context::Context, error::Error, report::Report};
use super::Module;

#[derive(Default)]
pub struct SQFCompiler;
pub struct SQFCompiler {
pub compile: bool,
}

impl Module for SQFCompiler {
fn name(&self) -> &'static str {
Expand Down Expand Up @@ -47,14 +49,16 @@ impl Module for SQFCompiler {
}
match hemtt_sqf::parser::run(&database, &processed) {
Ok(sqf) => {
// let mut out = entry.with_extension("sqfc")?.create_file()?;
let (warnings, errors) =
analyze(&sqf, Some(ctx.config()), &processed, Some(addon), &database);
for warning in warnings {
report.warn(warning);
}
if errors.is_empty() {
// sqf.compile_to_writer(&processed, &mut out)?;
if self.compile {
let mut out = entry.with_extension("sqfc")?.create_file()?;
sqf.compile_to_writer(&processed, &mut out)?;
}
counter.fetch_add(1, Ordering::Relaxed);
}
for error in errors {
Expand Down Expand Up @@ -86,7 +90,15 @@ impl Module for SQFCompiler {
for new_report in reports {
report.merge(new_report);
}
info!("Validated {} sqf files", counter.load(Ordering::Relaxed));
info!(
"{} {} sqf files",
if self.compile {
"Compiled"
} else {
"Validated"
},
counter.load(Ordering::Relaxed)
);
Ok(report)
}
}
8 changes: 7 additions & 1 deletion libs/common/src/reporting/processed.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#[cfg(feature = "lsp")]
use std::collections::HashMap;
use std::{rc::Rc, sync::Arc};
use std::{ops::Range, rc::Rc, sync::Arc};

use crate::{
position::{LineCol, Position},
Expand Down Expand Up @@ -258,6 +258,12 @@ impl Processed {
pub const fn no_rapify(&self) -> bool {
self.no_rapify
}

#[must_use]
/// Return a string with the source from the span
pub fn extract(&self, span: Range<usize>) -> String {
self.output[span].to_string()
}
}

#[derive(Debug)]
Expand Down
19 changes: 13 additions & 6 deletions libs/sqf/src/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,16 +60,23 @@ where
I: IntoIterator<Item = (Token, Range<usize>)>,
{
let len = processed.as_str().len();
let statements = parser(database).parse(Stream::from_iter(len..len + 1, input.into_iter()))?;
let statements =
parser(database, processed).parse(Stream::from_iter(len..len + 1, input.into_iter()))?;
Ok(statements)
}

fn parser(database: &Database) -> impl Parser<Token, Statements, Error = Simple<Token>> + '_ {
statements(database).then_ignore(end())
fn parser<'a>(
database: &'a Database,
processed: &'a Processed,
) -> impl Parser<Token, Statements, Error = Simple<Token>> + 'a {
statements(database, processed).then_ignore(end())
}

#[allow(clippy::too_many_lines)]
fn statements(database: &Database) -> impl Parser<Token, Statements, Error = Simple<Token>> + '_ {
fn statements<'a>(
database: &'a Database,
processed: &'a Processed,
) -> impl Parser<Token, Statements, Error = Simple<Token>> + 'a {
recursive(|statements| {
let expression = recursive(|expression| {
let value = select! { |span|
Expand Down Expand Up @@ -218,9 +225,9 @@ fn statements(database: &Database) -> impl Parser<Token, Statements, Error = Sim
.or(expression.map_with_span(Statement::Expression))
.separated_by(just(Token::Control(Control::Terminator)))
.allow_trailing()
.map(|content| Statements {
.map_with_span(|content, span| Statements {
content,
source: String::new(),
source: processed.extract(span),
})
})
}
Expand Down

0 comments on commit 474a796

Please sign in to comment.