Skip to content

Commit

Permalink
Fixed bugs, bumped ver
Browse files Browse the repository at this point in the history
  • Loading branch information
Divy1211 committed Nov 9, 2024
1 parent 3a6a4a7 commit 30c1d3c
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 12 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "xs-check"
version = "0.1.0"
version = "0.1.1"
authors = ["Alian713"]
edition = "2021"
description = "A linter for AoE2:DE's flavour of XS"
Expand Down
14 changes: 7 additions & 7 deletions src/lint/gen_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@ pub fn gen_info_from_path(
};
let filename = path.to_str().unwrap();

let errs = gen_info_from_src(
let (tc_errs, other_errs) = gen_info_from_src(
type_env, local_envs, groups,
&path, &src, ignores
);

gen_xs_errs(&errs, filename, &src, ignores);
gen_xs_errs(&tc_errs, filename, &src, ignores);

if errs.len() == 0 {
if tc_errs.len() == 0 && !other_errs {
println!("No errors found in file '{filename}'! Your code is free of the pitfalls of XS' quirks =)");
}
println!("Finished analysing '{filename}'.")
Expand All @@ -50,7 +50,7 @@ pub fn gen_info_from_src(
path: &PathBuf,
src: &str,
ignores: &HashSet<u32>,
) -> Vec<XSError> {
) -> (Vec<XSError>, bool) {
let (tokens, errs) = lexer()
.parse(src)
.into_output_errors();
Expand All @@ -59,7 +59,7 @@ pub fn gen_info_from_src(

let Some(mut tokens) = tokens else {
gen_errs("TokenizationError", &errs, path, src);
return tc_errs;
return (tc_errs, true);
};

tokens = tokens.into_iter()
Expand All @@ -73,10 +73,10 @@ pub fn gen_info_from_src(

let Some((ast, _span)) = ast else {
gen_errs("ParsingError", &errs, path, src);
return tc_errs;
return (tc_errs, true);
};

xs_tc(path, &ast, &mut None, type_env, local_envs, groups, &mut tc_errs, ignores);

tc_errs
(tc_errs, false)
}
6 changes: 3 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ fn main() {
Some(filepath) => { filepath }
None => { return; },
};

let mut type_env= HashMap::new();
let mut local_envs = HashMap::new();
let mut groups = HashSet::new();

let path = PathBuf::from(r"prelude.xs");
let prelude = include_str!(r"./prelude.xs");

gen_info_from_src(&mut type_env, &mut local_envs, &mut groups, &path, prelude, &ignores);

gen_info_from_path(&mut type_env, &mut local_envs, &mut groups, filepath, &ignores);
}
10 changes: 10 additions & 0 deletions src/static/type_check/expression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,17 @@ pub fn xs_tc_expr<'src>(
}

Expr::Neg(expr) => {
let (_, inner_span): &Spanned<Expr> = expr;
errs.extend(chk_num_lit(expr, true));

if inner_span.start - span.start > 1 {
errs.push(XSError::syntax(
span,
"Spaces are not allowed between unary negative ({0}) and {1} literals",
vec!["-", "int | float"]
))
}

xs_tc_expr(expr, local_env, type_env, errs)
}
Expr::Not(_) => {
Expand Down

0 comments on commit 30c1d3c

Please sign in to comment.