svg-filters & basic parser #15

Merged
schrottkatze merged 67 commits from schrottkatze/iowo:svg-filters into main 2024-07-08 18:29:05 +00:00
5 changed files with 69 additions and 5 deletions
Showing only changes of commit 4df0118aa4 - Show all commits

7
Cargo.lock generated
View file

@ -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",

View file

@ -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

View file

@ -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);
}

View file

@ -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\"";
}
"#},
);
}

View file

@ -1,4 +1 @@
mat 2x2 [
1 2, 2;
3, 4
]
42