forked from katzen-cafe/iowo
Compare commits
No commits in common. "ae60db77216343d7f259a733ccd2c1e53f95dd0c" and "ca84af4e1bd6b22e7e32c3f3864c4f2618c94a15" have entirely different histories.
ae60db7721
...
ca84af4e1b
2 changed files with 43 additions and 145 deletions
|
@ -17,8 +17,6 @@ use logos::{Logos, Source};
|
|||
use crate::tokens::Token;
|
||||
|
||||
pub mod ast;
|
||||
#[cfg(test)]
|
||||
mod tests;
|
||||
use self::ast::{Expr, File};
|
||||
|
||||
type Span = SimpleSpan;
|
||||
|
@ -91,3 +89,46 @@ fn expr_parser<'tokens, 'src: 'tokens, I: ValueInput<'tokens, Token = Token<'src
|
|||
decls: IndexMap::from_iter(decls),
|
||||
}))
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::parser::ast::{Expr, File};
|
||||
use crate::parser::parse;
|
||||
use crate::tokens::Token;
|
||||
use chumsky::input::Stream;
|
||||
use chumsky::prelude::*;
|
||||
use indexmap::IndexMap;
|
||||
use logos::Logos;
|
||||
|
||||
#[test]
|
||||
fn test_parse_node_with_params() {
|
||||
const INPUT: &str = "meow [ hello: $foo, world: @bar]";
|
||||
assert_eq!(
|
||||
parse(INPUT).unwrap(),
|
||||
File {
|
||||
decls: IndexMap::from_iter([(
|
||||
("main", (0..0).into()),
|
||||
(
|
||||
Expr::Node(
|
||||
("meow", (0..4).into()),
|
||||
Some((
|
||||
IndexMap::from_iter([
|
||||
(
|
||||
("hello", (7..12).into()),
|
||||
Expr::Var(("foo", (14..18).into()))
|
||||
),
|
||||
(
|
||||
("world", (20..25).into()),
|
||||
Expr::InputVar(("bar", (27..31).into()))
|
||||
)
|
||||
]),
|
||||
(5..32).into()
|
||||
))
|
||||
),
|
||||
(0..0).into()
|
||||
)
|
||||
)])
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,143 +0,0 @@
|
|||
use crate::parser::ast::{Expr, File};
|
||||
use crate::parser::parse;
|
||||
use crate::tokens::Token;
|
||||
use chumsky::input::Stream;
|
||||
use chumsky::prelude::*;
|
||||
use indexmap::IndexMap;
|
||||
use logos::Logos;
|
||||
|
||||
#[test]
|
||||
fn test_parse_node_with_params() {
|
||||
const INPUT: &str = "meow [ hello: $foo, world: @bar]";
|
||||
assert_eq!(
|
||||
parse(INPUT).unwrap(),
|
||||
File {
|
||||
decls: IndexMap::from_iter([(
|
||||
("main", (0..0).into()),
|
||||
(
|
||||
Expr::Node(
|
||||
("meow", (0..4).into()),
|
||||
Some((
|
||||
IndexMap::from_iter([
|
||||
(
|
||||
("hello", (7..12).into()),
|
||||
Expr::Var(("foo", (14..18).into()))
|
||||
),
|
||||
(
|
||||
("world", (20..25).into()),
|
||||
Expr::InputVar(("bar", (27..31).into()))
|
||||
)
|
||||
]),
|
||||
(5..32).into()
|
||||
))
|
||||
),
|
||||
(0..32).into()
|
||||
)
|
||||
)])
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
fn test_parse_multiple_top_level_complex() {
|
||||
const INPUT: &str = r#"def main = meow
|
||||
| uwu
|
||||
[ foo: @bar
|
||||
, hello: world @| test [ more: params ] | yay
|
||||
]
|
||||
!| awa
|
||||
@| nya
|
||||
| rawr;
|
||||
|
||||
def test = meow
|
||||
[ hello: $foo
|
||||
, world: @bar
|
||||
];
|
||||
"#;
|
||||
assert_eq!(
|
||||
parse(INPUT).unwrap(),
|
||||
File {
|
||||
decls: IndexMap::from_iter([
|
||||
(
|
||||
("main", (4..8).into()),
|
||||
(
|
||||
Expr::SimplePipe(
|
||||
Box::new(Expr::Node(("meow", (11..15).into()), None)),
|
||||
Box::new(Expr::NullPipe(
|
||||
Box::new(Expr::Node(
|
||||
("uwu", (20..23).into()),
|
||||
Some((
|
||||
IndexMap::from_iter([
|
||||
(
|
||||
("foo", (29..32).into()),
|
||||
Expr::InputVar(("bar", (34..38).into()))
|
||||
),
|
||||
(
|
||||
("hello", (44..49).into()),
|
||||
Expr::MappingPipe(
|
||||
Box::new(Expr::Node(
|
||||
("world", (51..56).into()),
|
||||
None
|
||||
)),
|
||||
Box::new(Expr::SimplePipe(
|
||||
Box::new(Expr::Node(
|
||||
("test", (60..64).into()),
|
||||
Some((
|
||||
IndexMap::from_iter([(
|
||||
("more", (67..71).into()),
|
||||
Expr::Node(
|
||||
("params", (73..79).into()),
|
||||
None
|
||||
)
|
||||
)]),
|
||||
(65..81).into()
|
||||
))
|
||||
)),
|
||||
Box::new(Expr::Node(
|
||||
("yay", (84..87).into()),
|
||||
None
|
||||
))
|
||||
))
|
||||
)
|
||||
)
|
||||
]),
|
||||
(27..92).into()
|
||||
))
|
||||
)),
|
||||
Box::new(Expr::MappingPipe(
|
||||
Box::new(Expr::Node(("awa", (97..100).into()), None)),
|
||||
Box::new(Expr::SimplePipe(
|
||||
Box::new(Expr::Node(("nya", (106..109).into()), None)),
|
||||
Box::new(Expr::Node(("rawr", (114..118).into()), None))
|
||||
))
|
||||
))
|
||||
))
|
||||
),
|
||||
(11..118).into()
|
||||
),
|
||||
),
|
||||
(
|
||||
("test", (125..129).into()),
|
||||
(
|
||||
Expr::Node(
|
||||
("meow", (132..136).into()),
|
||||
Some((
|
||||
IndexMap::from_iter([
|
||||
(
|
||||
("hello", (141..146).into()),
|
||||
Expr::Var(("foo", (148..152).into()))
|
||||
),
|
||||
(
|
||||
("world", (156..161).into()),
|
||||
Expr::InputVar(("bar", (163..167).into()))
|
||||
)
|
||||
]),
|
||||
(139..171).into()
|
||||
))
|
||||
),
|
||||
(132..171).into()
|
||||
)
|
||||
)
|
||||
])
|
||||
}
|
||||
);
|
||||
}
|
Loading…
Reference in a new issue