Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix parsing of inline nodes children #12

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 28 additions & 1 deletion kaydle-primitives/src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,12 @@ impl<'i> NodeList<'i> for Children<'i, '_> {
)
}

self.run_parser(parse_node_start(char('}').value(())))
let child_terminator = char('}')
stormshield-kg marked this conversation as resolved.
Show resolved Hide resolved
.value(())
.precedes(parse_node_space.opt())
.precedes(parse_node_terminator);

self.run_parser(parse_node_start(child_terminator))
.map(|opt_name| match opt_name {
// None here means that we successfully parsed the end-of-children. Inform the parent.
None => {
Expand Down Expand Up @@ -532,6 +537,12 @@ fn test_full_document_drain() {
items {
a /* An important note here */ "abc"
d "def"; g "ghi"
z { a; b { c; }; }
node {
child1 {
sub-child
}; child2
}
}
}
(annotated)node2
Expand All @@ -544,3 +555,19 @@ fn test_full_document_drain() {
let res: Result<DrainOutcome, nom::Err<()>> = processor.drain();
assert_eq!(res.expect("parse error"), DrainOutcome::NotEmpty);
}

#[test]
fn test_parse_child_error() {
let content = r##"
node {
child1 {
sub-child
} child2
}
"##;

assert!(matches!(
Document::new(content).drain(),
Err(nom::Err::Error(()))
));
}