1
3
Fork
You've already forked dot-parser
3

Multiple Graphs with syntax error does not actually error #9

Closed
opened 2025年07月28日 15:14:51 +02:00 by lcnbr · 4 comments

When parsing multiple graphs (Thanks again!), the parser does not error on parsing errors if the first graph has no errors:

#[test]fn multiple(){assert_eq!(dot_parser::ast::Graphs::try_from("graph { A -> subgraph { B C } }\ngraph { A -> }").unwrap().graphs.len(),1);assert!(dot_parser::ast::Graph::try_from("graph { A -> }").is_err());}

this test passes when the first assert should not even get hit (it should raise an error) not just ignore the graph.

When parsing multiple graphs (Thanks again!), the parser does not error on parsing errors if the first graph has no errors: ```rust #[test] fn multiple() { assert_eq!( dot_parser::ast::Graphs::try_from("graph { A -> subgraph { B C } }\ngraph { A -> }") .unwrap() .graphs .len(), 1 ); assert!(dot_parser::ast::Graph::try_from("graph { A -> }").is_err()); } ``` this test passes when the first assert should not even get hit (it should raise an error) not just ignore the graph.

I'll have a look at that. The fix does not seem to difficult, but that will probably change the error type of TryFrom. I expect the error type will look like a 2-tuple with an index (of the first error) and the associated parser error.

I'll have a look at that. The fix does not seem to difficult, but that will probably change the error type of TryFrom. I expect the error type will look like a 2-tuple with an index (of the first error) and the associated parser error.
Author
Copy link

Ah nice thanks! Changing the error type is fine for me!

Ah nice thanks! Changing the error type is fine for me!

What I imagined above turned out not to work: the way the parser worked was matching as many graph strings as possible (and at least one), until a non-matching string was found. Thus, the absence of error for the second graph (it wouldn't match the spec) while the first graph would generate an error (since I forced parsing at least one graph).

Instead of the solution above, I forced the parser to match the whole provided string, instead of parsing as much as correct. It seem to work on the example you provided, saying than an identifier or subgraph is missing when matching the last closing curly bracket. The good news is that it doesn't change the signature of TryFrom, so it should work out of the box. I'll push an updated version on crates.io shortly.

What I imagined above turned out not to work: the way the parser worked was matching as many graph strings as possible (and at least one), until a non-matching string was found. Thus, the absence of error for the second graph (it wouldn't match the spec) while the first graph would generate an error (since I forced parsing at least one graph). Instead of the solution above, I forced the parser to match the whole provided string, instead of parsing as much as correct. It seem to work on the example you provided, saying than an identifier or subgraph is missing when matching the last closing curly bracket. The good news is that it doesn't change the signature of TryFrom, so it should work out of the box. I'll push an updated version on crates.io shortly.

It's now online, in v0.6.0. I'm closing the ticket, but don't hesitate to reopen if need be :-)

It's now online, in v0.6.0. I'm closing the ticket, but don't hesitate to reopen if need be :-)
Sign in to join this conversation.
No Branch/Tag specified
master
v0.2
v0.1
rust_ice
v0.1.3
v0.1.2
v0.1.1
v0.1.0
Labels
Clear labels
No items
No labels
Milestone
Clear milestone
No items
No milestone
Projects
Clear projects
No items
No project
Assignees
Clear assignees
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
bromind/dot-parser#9
Reference in a new issue
bromind/dot-parser
No description provided.
Delete branch "%!s()"

Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?