mirror of
https://forge.katzen.cafe/katzen-cafe/iowo.git
synced 2024-12-05 02:38:45 +01:00
Compare commits
No commits in common. "662cb8ba0e7d1243307006cd77f2f952e4a38a41" and "958857cb58ffe1e2ca677908ee51101d022caf38" have entirely different histories.
662cb8ba0e
...
958857cb58
|
@ -1,17 +1,10 @@
|
|||
use array::array;
|
||||
use enumset::{enum_set, EnumSet};
|
||||
use pawarser::parser::ParserBuilder;
|
||||
|
||||
use crate::{
|
||||
syntax_error::SyntaxError,
|
||||
syntax_kind::{lex, SyntaxKind},
|
||||
};
|
||||
use crate::{syntax_error::SyntaxError, syntax_kind::SyntaxKind};
|
||||
|
||||
use self::object::object;
|
||||
|
||||
mod array;
|
||||
mod object;
|
||||
|
||||
pub(crate) type Parser<'src> = pawarser::Parser<'src, SyntaxKind, SyntaxError>;
|
||||
pub(crate) type CompletedMarker = pawarser::CompletedMarker<SyntaxKind, SyntaxError>;
|
||||
|
||||
|
@ -27,52 +20,5 @@ pub fn value(p: &mut Parser) -> bool {
|
|||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::{
|
||||
test_utils::{check_parser, gen_checks},
|
||||
value,
|
||||
};
|
||||
|
||||
#[test]
|
||||
fn value_lit() {
|
||||
gen_checks! {value;
|
||||
r#""helo world""# => r#"ROOT { STRING "\"helo world\""; }"#,
|
||||
"42" => r#"ROOT { NUMBER "42"; }"#,
|
||||
"null" => r#"ROOT { NULL "null"; }"#,
|
||||
"true" => r#"ROOT { BOOL "true"; }"#,
|
||||
"false" => r#"ROOT { BOOL "false"; }"#
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test_utils {
|
||||
use pawarser::parser::ParserBuilder;
|
||||
|
||||
use crate::syntax_kind::{lex, SyntaxKind};
|
||||
|
||||
use super::Parser;
|
||||
|
||||
macro_rules! gen_checks {
|
||||
($fn_to_test:ident; $($in:literal => $out:literal),+) => {
|
||||
$(crate::grammar::test_utils::check_parser($in, |p| { $fn_to_test(p); }, $out);)+
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) use gen_checks;
|
||||
|
||||
pub(super) fn check_parser(input: &str, parser_fn: fn(&mut Parser), expected_output: &str) {
|
||||
let toks = lex(input);
|
||||
let mut p: Parser = ParserBuilder::new(toks)
|
||||
.add_meaningless(SyntaxKind::WHITESPACE)
|
||||
.add_meaningless(SyntaxKind::NEWLINE)
|
||||
.build();
|
||||
|
||||
parser_fn(&mut p);
|
||||
|
||||
let out = p.finish();
|
||||
|
||||
assert_eq!(format!("{out:?}").trim_end(), expected_output);
|
||||
}
|
||||
}
|
||||
mod array;
|
||||
mod object;
|
||||
|
|
|
@ -23,10 +23,10 @@ pub(super) fn object(p: &mut Parser) -> Option<CompletedMarker> {
|
|||
}
|
||||
}
|
||||
|
||||
Some(if p.eat(SyntaxKind::BRACE_CLOSE) {
|
||||
obj_start.complete(p, SyntaxKind::OBJECT)
|
||||
} else {
|
||||
Some(if !p.eat(SyntaxKind::BRACE_CLOSE) {
|
||||
obj_start.error(p, SyntaxError::UnclosedObject)
|
||||
} else {
|
||||
obj_start.complete(p, SyntaxKind::OBJECT)
|
||||
})
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue