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

Allow ? and * parameters to be omitted in tail position #815

Merged
merged 2 commits into from
Aug 15, 2024

Conversation

zslayton
Copy link
Contributor

Previously the text reader only allowed arguments that could use rest syntax to also be omitted altogether.

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

Copy link
Contributor Author

@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.

🗺️ PR Tour 🧭

Comment on lines -1245 to -1246
pub fn match_empty_arg_group(self) -> IonMatchResult<'top> {
recognize(pair(tag("(:"), whitespace_and_then(tag(")"))))(self)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

🗺️ The original impl was just returning the matched slice. Now there's a concrete type that represents an argument group, so we instantiate one of those and return it.

Comment on lines -2663 to +2672
($parser:ident $macro_src:literal $($expect:ident: [$($input:literal),+$(,)?]),+$(,)?) => {
mod $parser {
($mod_name:ident $parser:ident $macro_src:literal $($expect:ident: [$($input:literal),+$(,)?]),+$(,)?) => {
mod $mod_name {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

🗺️ This macro creates a module with a bunch of nested unit tests. However, the module name was also the name of the parser. This meant you couldn't write two sets of unit tests that used the same parser entry point. I added another parameter ($mod_name) to this macro to allow the module name to be specified separately.

@@ -2967,6 +2975,7 @@ mod tests {
}

matcher_tests_with_macro! {
parsing_sexps
Copy link
Contributor Author

Choose a reason for hiding this comment

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

🗺️ In the next few tests, I added a distinct module name.

@zslayton zslayton marked this pull request as ready for review August 15, 2024 21:06
allow_omitting_trailing_optionals
match_e_expression
"(macro foo (a b+ c? d*) null)"
expect_match: [
Copy link

Choose a reason for hiding this comment

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

Worth adding an expectation that the explicit empty argument group (:) also works?

expect_match: [
"(:foo 1 2)",
"(:foo 1 2 3)",
"(:foo 1 2 3 4)",
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
"(:foo 1 2 3 4)",
"(:foo 1 2 3 4)",
"(:foo 1 2 (: 3) 4)",
"(:foo 1 2 3 (: 4))",

...unless these are already covered elsewhere.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The text reader doesn't have non-empty arg group support yet.

"(:foo 1 2)",
"(:foo 1 2 3)",
"(:foo 1 2 3 4)",
"(:foo 1 2 3 4 5 6)", // implicit rest
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
"(:foo 1 2 3 4 5 6)", // implicit rest
"(:foo 1 2 3 4 5 6)", // implicit rest
"(:foo 1 2 (: 3) 4 5 6)", // implicit rest
"(:foo 1 2 3 (: 4 5 6))",

...unless these are already covered elsewhere.

],
expect_mismatch: [
"(:foo 1)",
"(:foo)",
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
"(:foo)",
"(:foo)",
"(:foo 1 2 3 4 (: 5) 6)", // final argument must be rest or expression group, but not a mix of both

...unless this is already covered elsewhere.

@zslayton zslayton merged commit 239d590 into main Aug 15, 2024
28 of 31 checks passed
@zslayton zslayton deleted the omit-tail-args branch August 15, 2024 21:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants