Skip to content

Commit

Permalink
trying to figure out what's going wrong
Browse files Browse the repository at this point in the history
  • Loading branch information
zkat committed Aug 1, 2024
1 parent 9002425 commit 45bd6b6
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 85 deletions.
2 changes: 1 addition & 1 deletion src/entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ impl FromStr for KdlEntry {

fn from_str(s: &str) -> Result<Self, Self::Err> {
let (maybe_val, errs) = v2_parser::try_parse(v2_parser::padded_node_entry, s);
if let Some(Some(v)) = maybe_val {
if let (Some(Some(v)), true) = (maybe_val, errs.is_empty()) {
Ok(v)
} else {
Err(v2_parser::failure_from_errs(errs, s))
Expand Down
2 changes: 1 addition & 1 deletion src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ pub enum KdlErrorKind {

/// Generic unspecified error. If this is returned, the call site should
/// be annotated with context, if possible.
#[error("An unspecified error occurred.")]
#[error("An unspecified parse error occurred.")]
#[diagnostic(code(kdl::other))]
Other,
}
Expand Down
50 changes: 29 additions & 21 deletions src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -496,8 +496,8 @@ impl FromStr for KdlNode {
type Err = KdlParseFailure;

fn from_str(input: &str) -> Result<Self, Self::Err> {
let (maybe_val, errs) = v2_parser::try_parse(v2_parser::padded_node, input);
if let Some(v) = maybe_val {
let (maybe_val, errs) = dbg!(v2_parser::try_parse(v2_parser::padded_node, input));
if let (Some(v), true) = (maybe_val, errs.is_empty()) {
Ok(v)
} else {
Err(v2_parser::failure_from_errs(errs, input))
Expand Down Expand Up @@ -628,6 +628,8 @@ mod test {
}"#
.parse()?;
let mut right_node: KdlNode = "node param_name=103.0 { nested 1 2 3; }".parse()?;
dbg!(&left_node);
dbg!(&right_node);
assert_ne!(left_node, right_node);
left_node.clear_format_recursive();
right_node.clear_format_recursive();
Expand All @@ -637,27 +639,33 @@ mod test {

#[test]
fn parsing() -> miette::Result<()> {
let node: KdlNode = "\n\t (\"ty\")\"node\" 0xDEADbeef;\n".parse()?;
assert_eq!(node.ty(), Some(&"\"ty\"".parse()?));
assert_eq!(node.name(), &"\"node\"".parse()?);
assert_eq!(node.entry(0), Some(&" 0xDEADbeef".parse()?));
assert_eq!(
node.format(),
Some(&KdlNodeFormat {
leading: "\n\t ".into(),
trailing: ";\n".into(),
before_ty_name: "".into(),
after_ty_name: "".into(),
after_ty: "".into(),
before_children: "".into(),
})
);
// let node: KdlNode = "\n\t (\"ty\")\"node\" 0xDEADbeef;\n".parse()?;
// assert_eq!(node.ty(), Some(&"\"ty\"".parse()?));
// assert_eq!(node.name(), &"\"node\"".parse()?);
// assert_eq!(node.entry(0), Some(&" 0xDEADbeef".parse()?));
// assert_eq!(
// node.format(),
// Some(&KdlNodeFormat {
// leading: "\n\t ".into(),
// trailing: ";\n".into(),
// before_ty_name: "".into(),
// after_ty_name: "".into(),
// after_ty: "".into(),
// before_children: "".into(),
// })
// );

let node: KdlNode = r#"node "test" {
link "blah" anything=self
}
r#"
node "test" {
link "blah" anything="self"
}"#
more stuff
"#
.parse::<KdlNode>()?;
dbg!(&node);
assert_eq!(node.entry(0), Some(&" \"test\"".parse()?));
assert_eq!(node.children().unwrap().len(), 1);

Ok(())
}

Expand Down
Loading

0 comments on commit 45bd6b6

Please sign in to comment.