From e6a6865cb835ef26d0aed8583c113210cfa91fba Mon Sep 17 00:00:00 2001 From: Dark Date: Sat, 6 Jan 2024 19:46:45 -0500 Subject: [PATCH] make dtacheck usable as a library --- crates/dtacheck/src/lexer.rs | 1 + crates/dtacheck/src/lib.rs | 3 +++ crates/dtacheck/src/linter.rs | 10 ++++++---- crates/dtacheck/src/main.rs | 13 +++++-------- deny.toml | 2 +- 5 files changed, 16 insertions(+), 13 deletions(-) create mode 100644 crates/dtacheck/src/lib.rs diff --git a/crates/dtacheck/src/lexer.rs b/crates/dtacheck/src/lexer.rs index 577ac38..2852f6b 100644 --- a/crates/dtacheck/src/lexer.rs +++ b/crates/dtacheck/src/lexer.rs @@ -6,6 +6,7 @@ use logos::Lexer; use logos::Logos; // do no try and understand the regex in here +#[allow(missing_docs)] #[derive(Logos, Debug, PartialEq, IsVariant, Unwrap, Clone)] pub enum TokenKind { #[token("kDataUnhandled")] diff --git a/crates/dtacheck/src/lib.rs b/crates/dtacheck/src/lib.rs new file mode 100644 index 0000000..e4f1122 --- /dev/null +++ b/crates/dtacheck/src/lib.rs @@ -0,0 +1,3 @@ +pub mod lexer; +pub mod linter; +pub mod parser; diff --git a/crates/dtacheck/src/linter.rs b/crates/dtacheck/src/linter.rs index e3d59e5..5570cd5 100644 --- a/crates/dtacheck/src/linter.rs +++ b/crates/dtacheck/src/linter.rs @@ -159,7 +159,7 @@ fn generate_function_name(stmt: &[Node]) -> String { } // preprocesor directives -pub enum PreProcLint { +enum PreProcLint { Unmatched(Range), Extra(Range), } @@ -177,7 +177,7 @@ impl Lint for PreProcLint { } } -pub fn lint_preprocs(lints: &mut Vec>, tokens: &[Token]) { +fn lint_preprocs(lints: &mut Vec>, tokens: &[Token]) { let mut directive_stack: Vec<(Range, bool)> = Vec::new(); for token in tokens { match token.kind { @@ -193,12 +193,14 @@ pub fn lint_preprocs(lints: &mut Vec>, tokens: &[Token]) { } directive_stack.push((token.span.clone(), true)); } else { - lints.push(Box::new(PreProcLint::Extra(token.span.clone()))); + lints + .push(Box::new(PreProcLint::Extra(token.span.clone()))); } } TokenKind::EndIf => { if directive_stack.pop().is_none() { - lints.push(Box::new(PreProcLint::Extra(token.span.clone()))); + lints + .push(Box::new(PreProcLint::Extra(token.span.clone()))); } } _ => (), diff --git a/crates/dtacheck/src/main.rs b/crates/dtacheck/src/main.rs index ef0d17f..185a358 100644 --- a/crates/dtacheck/src/main.rs +++ b/crates/dtacheck/src/main.rs @@ -8,14 +8,11 @@ use codespan_reporting::term; use codespan_reporting::term::termcolor::ColorChoice; use codespan_reporting::term::termcolor::StandardStream; use codespan_reporting::term::Chars; - -use crate::linter::lint_file; -use crate::linter::Function; -use crate::linter::Lint; - -mod lexer; -mod linter; -mod parser; +use dtacheck::lexer; +use dtacheck::linter::lint_file; +use dtacheck::linter::Function; +use dtacheck::linter::Lint; +use dtacheck::parser; #[derive(ClapParser)] struct Args { diff --git a/deny.toml b/deny.toml index fcd1e2d..9fc12ca 100644 --- a/deny.toml +++ b/deny.toml @@ -1,6 +1,6 @@ [licenses] unlicensed = "deny" -copyleft = "warn" +copyleft = "deny" allow-osi-fsf-free = "osi" default = "deny"