Skip to content

Commit

Permalink
add scan return
Browse files Browse the repository at this point in the history
  • Loading branch information
Boshen committed Dec 18, 2024
1 parent ce93ae7 commit 9853f35
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
3 changes: 2 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ fn main() {
paths.par_iter().for_each(|path| {
let source_text = fs::read_to_string(path).unwrap();
let scanner = Scanner::new(path.to_path_buf(), source_text);
tx_error.send(scanner.scan(FEATURES)).unwrap();
let ret = scanner.scan(FEATURES);
tx_error.send(Some(ret.diagnostics)).unwrap();
});
tx_error.send(None).unwrap();
}
Expand Down
22 changes: 12 additions & 10 deletions src/scanner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,16 @@ pub struct Scanner {
source_text: String,
}

pub struct ScanReturn {
pub diagnostics: (PathBuf, Vec<Error>),
}

impl Scanner {
pub fn new(source_path: PathBuf, source_text: String) -> Self {
Self { source_path, source_text }
}

pub fn scan(&self, features: &[&dyn Feature]) -> Option<(PathBuf, Vec<Error>)> {
pub fn scan(&self, features: &[&dyn Feature]) -> ScanReturn {
let allocator = Allocator::default();
let source_type = SourceType::from_path(&self.source_path).unwrap();
let ret = Parser::new(&allocator, &self.source_text, source_type)
Expand All @@ -30,10 +34,6 @@ impl Scanner {
})
.parse();

if !ret.errors.is_empty() {
return None;
}

let semantic_ret = SemanticBuilder::new().build(&ret.program);
let mut ctx = Ctx::default();

Expand All @@ -43,10 +43,12 @@ impl Scanner {
}
}

Some(DiagnosticService::wrap_diagnostics(
&self.source_path,
&self.source_text,
ctx.diagnostics(),
))
ScanReturn {
diagnostics: DiagnosticService::wrap_diagnostics(
&self.source_path,
&self.source_text,
ctx.diagnostics(),
),
}
}
}

0 comments on commit 9853f35

Please sign in to comment.