mirror of
https://forge.katzen.cafe/katzen-cafe/iowo.git
synced 2024-11-25 06:48:43 +01:00
lang: first test and stuff
This commit is contained in:
parent
ba0da33509
commit
4df0118aa4
7
Cargo.lock
generated
7
Cargo.lock
generated
|
@ -504,6 +504,12 @@ dependencies = [
|
|||
"hashbrown",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "indoc"
|
||||
version = "2.0.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b248f5224d1d606005e02c97f5aa4e88eeb230488bcc03bc9ca4d7991399f2b5"
|
||||
|
||||
[[package]]
|
||||
name = "ir"
|
||||
version = "0.1.0"
|
||||
|
@ -538,6 +544,7 @@ dependencies = [
|
|||
"ego-tree",
|
||||
"enumset",
|
||||
"indexmap",
|
||||
"indoc",
|
||||
"logos",
|
||||
"petgraph",
|
||||
"rowan",
|
||||
|
|
|
@ -15,6 +15,7 @@ ego-tree = "0.6.2"
|
|||
rowan = "0.15.15"
|
||||
drop_bomb = "0.1.5"
|
||||
enumset = "1.1.3"
|
||||
indoc = "2"
|
||||
|
||||
[lints]
|
||||
workspace = true
|
||||
|
|
|
@ -1,6 +1,13 @@
|
|||
use std::fmt::Debug;
|
||||
|
||||
use crate::parser::syntax_kind::SyntaxKind::*;
|
||||
|
||||
use super::Parser;
|
||||
use super::{
|
||||
input::Input,
|
||||
output::Output,
|
||||
syntax_kind::{self, lex},
|
||||
Parser,
|
||||
};
|
||||
|
||||
mod expression;
|
||||
|
||||
|
@ -12,3 +19,16 @@ pub fn source_file(p: &mut Parser) {
|
|||
|
||||
root.complete(p, ROOT);
|
||||
}
|
||||
|
||||
fn check_parser(input: &str, parser_fn: fn(&mut Parser), output: &str) {
|
||||
let toks = lex(input);
|
||||
let mut parser = Parser::new(Input::new(&toks));
|
||||
|
||||
parser_fn(&mut parser);
|
||||
|
||||
let p_out = dbg!(parser.finish());
|
||||
let o = Output::from_parser_output(toks, p_out);
|
||||
|
||||
let s = format!("{o:?}");
|
||||
assert_eq!(&s, output);
|
||||
}
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
use enumset::enum_set;
|
||||
use indoc::indoc;
|
||||
|
||||
use crate::parser::{
|
||||
grammar::check_parser,
|
||||
syntax_kind::{SyntaxKind::*, TokenSet},
|
||||
CompletedMarker, Parser,
|
||||
};
|
||||
|
@ -18,3 +20,40 @@ pub fn literal(p: &mut Parser) -> Option<CompletedMarker> {
|
|||
|
||||
Some(lit.complete(p, LITERAL))
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_parse_lst_lit() {
|
||||
check_parser(
|
||||
"42",
|
||||
|p| {
|
||||
literal(p);
|
||||
},
|
||||
indoc! {r#"
|
||||
LITERAL {
|
||||
INT_NUM "42";
|
||||
}
|
||||
"#},
|
||||
);
|
||||
check_parser(
|
||||
"3.14",
|
||||
|p| {
|
||||
literal(p);
|
||||
},
|
||||
indoc! {r#"
|
||||
LITERAL {
|
||||
FLOAT_NUM "3.14";
|
||||
}
|
||||
"#},
|
||||
);
|
||||
check_parser(
|
||||
r#""Meow""#,
|
||||
|p| {
|
||||
literal(p);
|
||||
},
|
||||
indoc! {r#"
|
||||
LITERAL {
|
||||
STRING "\"Meow\"";
|
||||
}
|
||||
"#},
|
||||
);
|
||||
}
|
||||
|
|
|
@ -1,4 +1 @@
|
|||
mat 2x2 [
|
||||
1 2, 2;
|
||||
3, 4
|
||||
]
|
||||
42
|
||||
|
|
Loading…
Reference in a new issue