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

Fixes ordered_elements implementation #225

Merged
merged 4 commits into from
Oct 26, 2024

Conversation

popematt
Copy link
Contributor

Issue #, if available:

Fix #56
Fix #221
Fix #105

Description of changes:

Complete rewrite of the state machine for ordered elements. This fixes all the correctness issues with ordered_elements; now all of the ion-schema-tests cases for ordered_elements are enabled and passing. It also brings improved violation messaging for the ordered_elements constraint—although not quite as nice as amazon-ion/ion-schema-kotlin#228 because the source ISL isn't available by the time we're constructing the ordered elements NFA, and I didn't want to tackle that as part of this PR since I think the violations may end up being refactored before v1.0.0 anyway.

That being said, I did go and update the implementation of Display for Violation because it was printing stuff on one line in a completely unusable way. The new implementation is a little bit more like ion-schema-kotlin in that it prints a multi-line tree of violations.


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

Copy link
Contributor

@zslayton zslayton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! My comments are mostly comment clarifications.

ion-schema/src/ordered_elements_nfa.rs Outdated Show resolved Hide resolved
ion-schema/src/ordered_elements_nfa.rs Show resolved Hide resolved
ion-schema/src/ordered_elements_nfa.rs Show resolved Hide resolved
ion-schema/src/ordered_elements_nfa.rs Outdated Show resolved Hide resolved
ion-schema/src/ordered_elements_nfa.rs Outdated Show resolved Hide resolved
ion-schema/src/ordered_elements_nfa.rs Outdated Show resolved Hide resolved
ion-schema/src/ordered_elements_nfa.rs Outdated Show resolved Hide resolved
Comment on lines 169 to 170
// Need to clone the range because strangely &RangeInclusive doesn't
// implement Copy or IntoIterator.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Happily, this weirdness is getting addressed in edition 2024.

ion-schema/src/ordered_elements_nfa.rs Outdated Show resolved Hide resolved
ion-schema/src/violation.rs Outdated Show resolved Hide resolved
Copy link
Contributor

@zslayton zslayton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One thing to consider RE: indentation before you merge.

Comment on lines 97 to 99
let one_indent = " ";
// TODO: Consider extracting this into a static or thread local variable.
let mut indentation = vec![one_indent.to_string()];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This works, but why have a Vec of indentation Strings instead of a single String that you add spacing to as the stack gets deeper?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lol, it's because I've been using too much Java recently, and I forgot that strings can be mutated in Rust. I'll fix it.

@popematt popematt merged commit 727d3d2 into amazon-ion:main Oct 26, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants