Skip to content

Commit

Permalink
parser: add test for bool assign
Browse files Browse the repository at this point in the history
Signed-off-by: FedericoBruzzone <[email protected]>
  • Loading branch information
FedericoBruzzone committed Aug 20, 2024
1 parent c8f4810 commit 82091e6
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 6 deletions.
24 changes: 18 additions & 6 deletions src/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@ use crate::{
lexer::token::{Keyword, Literal, Token, TokenKind},
source::Source,
};
use std::iter::Peekable;
use tracing::info;

pub struct Parser<I: IntoIterator> {
lexer: Peekable<I::IntoIter>,
lexer: I::IntoIter,
curr_token: Option<Token>,
source: Source,
}
Expand All @@ -20,7 +19,7 @@ impl<I: IntoIterator<Item = Token>> Parser<I> {
info!("Created Parser");
let curr_token = lexer.next();
Parser {
lexer: lexer.peekable(),
lexer,
curr_token,
source,
}
Expand Down Expand Up @@ -185,6 +184,16 @@ impl<I: IntoIterator<Item = Token>> Parser<I> {
location: token.location,
}
}
Literal::Bool => {
let bool_ = match token.lexeme.parse::<bool>() {
Ok(bool_) => bool_,
Err(_) => todo!(), // Error of invalid bool
};
ast::Expr::Literal {
literal: ast::Literal::Bool(bool_),
location: token.location,
}
}
_ => todo!(),
},
_ => todo!(),
Expand All @@ -205,9 +214,12 @@ pub mod tests {
let fs_files = collect_fs_files("./testdata/native_types", true);
assert_eq!(fs_files.len(), 16);

let fs_files = fs_files
.iter()
.filter(|p| p.ends_with("id_int_assign.fs") || p.ends_with("id_float_assign.fs"));
let fs_files = fs_files.iter().filter(|p| {
p.ends_with("id_int_assign.fs")
|| p.ends_with("id_float_assign.fs")
|| p.ends_with("id_bool_true_assign.fs")
|| p.ends_with("id_bool_false_assign.fs")
});

for path in fs_files {
info!("file -> {:?}", path);
Expand Down
33 changes: 33 additions & 0 deletions testdata/native_types/id_bool_false_assign.ast.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"stmts": [
{
"Assign": {
"lhs": {
"Identifier": {
"name": "_x_bool",
"location": {
"file_path": "",
"line": 0,
"column_start": 0,
"column_end": 7
}
}
},
"type_": "Bool",
"rhs": {
"Literal": {
"literal": {
"Bool": false
},
"location": {
"file_path": "",
"line": 0,
"column_start": 16,
"column_end": 21
}
}
}
}
}
]
}
33 changes: 33 additions & 0 deletions testdata/native_types/id_bool_true_assign.ast.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"stmts": [
{
"Assign": {
"lhs": {
"Identifier": {
"name": "_x_bool",
"location": {
"file_path": "",
"line": 0,
"column_start": 0,
"column_end": 7
}
}
},
"type_": "Bool",
"rhs": {
"Literal": {
"literal": {
"Bool": true
},
"location": {
"file_path": "",
"line": 0,
"column_start": 16,
"column_end": 20
}
}
}
}
}
]
}

0 comments on commit 82091e6

Please sign in to comment.