Skip to content

Commit

Permalink
make dtacheck usable as a library
Browse files Browse the repository at this point in the history
  • Loading branch information
DarkRTA committed Jan 7, 2024
1 parent 1e230e3 commit e6a6865
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 13 deletions.
1 change: 1 addition & 0 deletions crates/dtacheck/src/lexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down
3 changes: 3 additions & 0 deletions crates/dtacheck/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pub mod lexer;
pub mod linter;
pub mod parser;
10 changes: 6 additions & 4 deletions crates/dtacheck/src/linter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ fn generate_function_name(stmt: &[Node]) -> String {
}

// preprocesor directives
pub enum PreProcLint {
enum PreProcLint {
Unmatched(Range<usize>),
Extra(Range<usize>),
}
Expand All @@ -177,7 +177,7 @@ impl Lint for PreProcLint {
}
}

pub fn lint_preprocs(lints: &mut Vec<Box<dyn Lint>>, tokens: &[Token]) {
fn lint_preprocs(lints: &mut Vec<Box<dyn Lint>>, tokens: &[Token]) {
let mut directive_stack: Vec<(Range<usize>, bool)> = Vec::new();
for token in tokens {
match token.kind {
Expand All @@ -193,12 +193,14 @@ pub fn lint_preprocs(lints: &mut Vec<Box<dyn Lint>>, 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())));
}
}
_ => (),
Expand Down
13 changes: 5 additions & 8 deletions crates/dtacheck/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion deny.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[licenses]
unlicensed = "deny"
copyleft = "warn"
copyleft = "deny"
allow-osi-fsf-free = "osi"
default = "deny"

Expand Down

0 comments on commit e6a6865

Please sign in to comment.