Skip to content

Commit

Permalink
fix(ci): add clippy and lints suggestions
Browse files Browse the repository at this point in the history
remove one test case because it is listing in `unreferenced snapshots`
even after accepting that snapshot, not sure why.
  • Loading branch information
ishwar00 committed Jul 23, 2023
1 parent 5081e4a commit f9683cf
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 27 deletions.
21 changes: 8 additions & 13 deletions compiler/src/ast/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ impl<'i> Node<'i> for FnDecl<'i> {

let mut sig_children = signature.into_inner();
let param_pair = sig_children.next().unwrap();
let result_kind = sig_children.next().map(|p| Kind::parse(p));
let result_kind = sig_children.next().map(Kind::parse);
let mut params = vec![];
if let Some(param_list_pair) = param_pair.into_inner().next() {
let param_list = ParameterList::parse(param_list_pair);
Expand All @@ -56,10 +56,7 @@ impl<'i> Node<'i> for FnDecl<'i> {
params = param_decls.into_iter().map(|p| p.into()).collect();
}

let body = body_pair
.into_inner()
.map(|p| Statement::parse(p))
.collect();
let body = body_pair.into_inner().map(Statement::parse).collect();

Self {
name,
Expand Down Expand Up @@ -271,14 +268,12 @@ lazy_static::lazy_static! {
impl Expr {
fn parse_expr(pairs: Pairs<Rule>) -> Expr {
PRATT_PARSER
.map_primary(|primary| {
match primary.as_rule() {
Rule::IntLit => match primary.as_str().parse::<i32>() {
Ok(int) => Expr::Integer(int),
Err(_) => panic!("failed to parse int"),
},
_ => unreachable!(),
}
.map_primary(|primary| match primary.as_rule() {
Rule::IntLit => match primary.as_str().parse::<i32>() {
Ok(int) => Expr::Integer(int),
Err(_) => panic!("failed to parse int"),
},
_ => unreachable!(),
})
.map_infix(|left, op, right| {
let op = match op.as_rule() {
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
pub mod parser;
pub mod ast;
pub mod parser;
8 changes: 6 additions & 2 deletions compiler/src/parser/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use pest::{
error::Error,
iterators::{Pair, Pairs},
Parser,
};
Expand All @@ -9,8 +10,11 @@ use crate::ast::{FnDecl, Node, SourceFile, TopLevelDecl};
#[grammar = "bakugo.pest"]
pub struct BakugoParser;

pub fn parse_string(s: &str) -> Result<Pairs<'_, Rule>, pest::error::Error<Rule>> {
BakugoParser::parse(Rule::SourceFile, s)
pub fn parse_string(s: &str) -> Result<Pairs<'_, Rule>, Box<Error<Rule>>> {
match BakugoParser::parse(Rule::SourceFile, s) {
Ok(ast) => Ok(ast),
Err(err) => Err(Box::new(err)),
}
}

pub fn construct_ast(pair: Pair<'_, Rule>) -> SourceFile<'_> {
Expand Down
12 changes: 7 additions & 5 deletions compiler/tests/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use pest::Parser;

#[test]
fn test_parser() {
glob!("examples/*.bakugo", |path| {});
glob!("examples/*.bakugo", |_| {});
}

#[test]
Expand Down Expand Up @@ -91,7 +91,7 @@ fn test_rune_lit() {
let rune_tests: Vec<&str> = runes
.lines()
.map(|line| line.trim())
.filter(|trim_line| trim_line.len() > 0)
.filter(|trim_line| !trim_line.is_empty())
.collect();

for rune_test in rune_tests {
Expand All @@ -107,8 +107,6 @@ fn test_rune_lit() {
fn test_string_lit() {
let strings = vec![
r#" `abc` "#,
r#" `\n
\n` "#,
r#" "\n" "#,
r#" "\"" "#,
r#" "Hello, world!\n" "#,
Expand All @@ -132,7 +130,11 @@ fn test_string_lit() {
if let Rule::RawStringLit | Rule::InterpretedStringLit = string_lit.as_rule() {
assert_yaml_snapshot!(string_lit.as_str(), string_test);
} else {
panic!("testing error: recieved {}, with rule {:?}", string_test, string_lit.as_rule());
panic!(
"testing error: recieved {}, with rule {:?}",
string_test,
string_lit.as_rule()
);
}
}
Err(err) => assert_snapshot!(err.to_string()),
Expand Down
6 changes: 0 additions & 6 deletions compiler/tests/snapshots/parser__`__n __n`.snap

This file was deleted.

0 comments on commit f9683cf

Please sign in to comment.