Skip to content

Commit

Permalink
🚨 (parser): Fix lint warnings
Browse files Browse the repository at this point in the history
semver: chore
  • Loading branch information
Somfic committed Jun 17, 2024
1 parent 833f1ea commit 4facd7b
Show file tree
Hide file tree
Showing 4 changed files with 191 additions and 149 deletions.
5 changes: 3 additions & 2 deletions src/diagnostic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ impl<'a> Diagnostic<'a> {
&Config::default(),
files,
&self.clone().into(),
);
)
.unwrap();
}
}

Expand Down Expand Up @@ -67,7 +68,7 @@ impl<'a> Error<'a> {
}
}

pub(crate) fn transform_range(mut self, lexemes: &'a [Token<'a>]) -> Error {
pub(crate) fn transform_range(mut self, lexemes: &[Token<'a>]) -> Error<'a> {
self.range = self.range.to_source_code_range(lexemes);
self
}
Expand Down
29 changes: 17 additions & 12 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,7 @@
use anyhow::Result;
use codespan_reporting::{
diagnostic::Diagnostic,
term::{
self,
termcolor::{ColorChoice, StandardStream},
},
};
use core::result::Result::Ok;
use files::Files;
use parser::Grammar;
use scanner::token;

pub mod diagnostic;
pub mod files;
Expand All @@ -21,15 +13,15 @@ fn main() -> Result<()> {
files.insert(
"main",
"
12 + 12
12 + 12;
",
);

let scanner = scanner::Scanner::new(&files);
let lexemes = scanner.parse();
let tokens = scanner.parse();

let lexemes = match &lexemes {
Ok(lexemes) => lexemes,
let tokens = match &tokens {
Ok(tokens) => tokens,
Err(diagnostics) => {
diagnostics
.iter()
Expand All @@ -38,5 +30,18 @@ fn main() -> Result<()> {
}
};

let parser = parser::EarleyParser::new(Grammar::default());
let ast = parser.parse(tokens);

let _ast = match &ast {
Ok(ast) => ast,
Err(diagnostics) => {
diagnostics
.iter()
.for_each(|diagnostic| diagnostic.print(&files));
panic!("Failed to parse");
}
};

Ok(())
}
Loading

0 comments on commit 4facd7b

Please sign in to comment.