Skip to content

Commit

Permalink
Merge pull request #7 from TheNathannator/arson-update
Browse files Browse the repository at this point in the history
[dtacheck] Update arson-parse to latest commit
  • Loading branch information
DarkRTA authored Dec 12, 2024
2 parents 54b166f + 23ab945 commit 2f61873
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 21 deletions.
8 changes: 6 additions & 2 deletions crates/dtacheck/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ publish = false
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
arson = { git = "https://github.com/hmxmilohax/arson", version = "0.1.0", rev = "c0c102c86f3734d41623b2fd4bfc78bf74302500" }
clap = { version = "4.4.12", features = ["derive"] }
codespan-reporting = "0.11.1"

[dependencies.arson-parse]
version = "0.1.0"
git = "https://github.com/hmxmilohax/arson"
rev = "7b65f20fc2f409d1bfedb4b0bdfbe581c8e6e969"
features = ["reporting"]
30 changes: 16 additions & 14 deletions crates/dtacheck/src/linter.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
use std::collections::HashMap;
use std::ops::Range;

use arson::parse::parser as arson_parse;
use arson_parse::{Expression, ExpressionKind};
use arson_parse::reporting as codespan_reporting;
use arson_parse::Expression;
use arson_parse::ExpressionValue;
use codespan_reporting::diagnostic::Diagnostic;
use codespan_reporting::diagnostic::Label;

pub trait Lint {
fn to_codespan(&self, id: usize) -> Diagnostic<usize>;
}

impl<'src> Lint for arson_parse::ParseError<'src> {
impl<'src> Lint for arson_parse::Diagnostic {
fn to_codespan(&self, id: usize) -> Diagnostic<usize> {
self.to_diagnostic(id)
self.to_codespan(id)
}
}

Expand All @@ -28,18 +29,19 @@ fn lint_node(
funcs: &Function,
) {
for node in ast {
match &node.kind {
ExpressionKind::Array(array) | ExpressionKind::Property(array) => {
match &node.value {
ExpressionValue::Array(array)
| ExpressionValue::Property(array) => {
lint_node(lints, &array, funcs)
}
ExpressionKind::Define(_, array) => {
ExpressionValue::Define(_, array) => {
lint_node(lints, &array.exprs, funcs)
}
ExpressionKind::Command(array) => {
ExpressionValue::Command(array) => {
lint_node(lints, array, funcs);

let has_preprocessor_directive = array.iter().any(|e| {
matches!(e.kind, ExpressionKind::Conditional { .. })
matches!(e.value, ExpressionValue::Conditional { .. })
});

if !has_preprocessor_directive {
Expand Down Expand Up @@ -118,7 +120,7 @@ impl Function {
return (self, depth);
};

let ExpressionKind::Symbol(sym) = node.kind else {
let ExpressionValue::Symbol(sym) = node.value else {
return (self, depth);
};

Expand Down Expand Up @@ -164,8 +166,8 @@ fn lint_fn_args(
fn generate_function_name(stmt: &[Expression]) -> String {
let list: Vec<&str> = stmt
.iter()
.map(|x| match x.kind {
ExpressionKind::Symbol(sym) => Some(sym),
.map(|x| match x.value {
ExpressionValue::Symbol(sym) => Some(sym),
_ => None,
})
.take_while(Option::is_some)
Expand Down Expand Up @@ -200,7 +202,7 @@ fn lint_switch_fallthrough(
return;
}

let ExpressionKind::Symbol(sym) = stmt[0].kind else {
let ExpressionValue::Symbol(sym) = stmt[0].value else {
return;
};

Expand All @@ -212,7 +214,7 @@ fn lint_switch_fallthrough(
return;
};

if matches!(last_node.kind, ExpressionKind::Array(_)) {
if matches!(last_node.value, ExpressionValue::Array(_)) {
let pos = span.end - 1;
lints.push(Box::new(SwitchFallthroughLint(span, pos..pos)))
}
Expand Down
7 changes: 2 additions & 5 deletions crates/dtacheck/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ use std::fs;
use std::path::Path;
use std::path::PathBuf;

use arson::parse::lexer;
use arson::parse::parser;
use arson_parse::reporting as codespan_reporting;
use clap::Parser as ClapParser;
use codespan_reporting::files::SimpleFiles;
use codespan_reporting::term;
Expand All @@ -12,7 +11,6 @@ use codespan_reporting::term::termcolor::StandardStream;
use codespan_reporting::term::Chars;
use dtacheck::linter::lint_file;
use dtacheck::linter::Function;
use dtacheck::linter::Lint;

#[derive(ClapParser)]
struct Args {
Expand Down Expand Up @@ -53,8 +51,7 @@ fn main() {
let mut files = SimpleFiles::new();
let file_id = files.add(args.file.to_str().unwrap(), &data);

let tokens = lexer::lex(&data);
let (ast, diagnostics) = match parser::parse(tokens) {
let (ast, diagnostics) = match arson_parse::parse_text(&data) {
Ok(ast) => (ast, Vec::new()),
Err(errors) => (Vec::new(), errors),
};
Expand Down

0 comments on commit 2f61873

Please sign in to comment.