Skip to content

Fix trivia in custom character classes #278

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

Merged
merged 2 commits into from
Apr 14, 2022

Conversation

hamishknight
Copy link
Contributor

@hamishknight hamishknight commented Apr 14, 2022

Fix trivia matching logic in custom character classes, rather than matching and not advancing the input, we should always return nil to never match against the trivia. Resolves #275.

Additionally, fix custom character class parsing logic such that trivia is suitably ignored for set operations and the case where the first semantic member is ].

Rather than matching and not advancing the input,
we should always return `nil` to never match
against the trivia.
Previously we would check for an empty array of
members when deciding whether an initial `]` is
literal, or if the operands of a set operation are
invalid. Switch to checking whether we have any
semantic members instead.
@hamishknight
Copy link
Contributor Author

@swift-ci please test

Copy link
Member

@natecook1000 natecook1000 left a comment

Choose a reason for hiding this comment

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

LGTM!

Comment on lines +1213 to +1222
firstMatchTest(#" \t "#, input: " \t ", match: " \t ")
firstMatchTest(#"(?xx) \t "#, input: " \t ", match: "\t")

firstMatchTest(#"[ \t]+"#, input: " \t ", match: " \t ")
firstMatchTest(#"(?xx)[ \t]+"#, input: " \t ", match: "\t")
firstMatchTest(#"(?xx)[ \t]+"#, input: " \t\t ", match: "\t\t")
firstMatchTest(#"(?xx)[ \t]+"#, input: " \t \t", match: "\t")

firstMatchTest("(?xx)[ a && ab ]+", input: " aaba ", match: "aa")
firstMatchTest("(?xx)[ ] a ]+", input: " a]]a ] ", match: "a]]a")
Copy link
Member

Choose a reason for hiding this comment

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

👍🏻

@hamishknight hamishknight merged commit 63ab0a9 into swiftlang:main Apr 14, 2022
@hamishknight hamishknight deleted the trivagone branch April 14, 2022 17:02
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.

Whitespace in CCCs in extended syntax causes trap when matching
2 participants