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

[SR-11875] Scanner get line comments wrong #54290

Closed
swift-ci opened this issue Nov 29, 2019 · 3 comments
Closed

[SR-11875] Scanner get line comments wrong #54290

swift-ci opened this issue Nov 29, 2019 · 3 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior.

Comments

@swift-ci
Copy link
Collaborator

Previous ID SR-11875
Radar rdar://problem/57549605
Original Reporter andreasw (JIRA User)
Type Bug
Status Closed
Resolution Invalid

Attachment: Download

Additional Detail from JIRA
Votes 0
Component/s
Labels Bug
Assignee None
Priority Medium

md5: 843cd1ad6699b31f603202163fa513ca

Issue Description:

I try to scan lines comments string with "#". If a newline immediately follows the hashmark it is not recognized. Please have a look at the attached files what is working and what is not (which I expect to work).

@beccadax
Copy link
Contributor

beccadax commented Dec 2, 2019

@swift-ci create

@beccadax
Copy link
Contributor

beccadax commented Dec 3, 2019

andreasw (JIRA User) I believe this is expected behavior; it's caused by the Scanner.charactersToBeSkipped property, which causes the Scanner to skip over certain characters before it starts scanning. By default, newlines are in the set of characters it skips. You may need to set that property to a different value to handle your use case correctly.

@swift-ci
Copy link
Collaborator Author

swift-ci commented Jun 8, 2020

Comment by Andreas Wendleder (JIRA)

This seems to work:

extension Scanner {
        func comment() {
               charactersToBeSkipped = CharacterSet.whitespaces
               print("hash: ", scanString("#") as Any)
               print("comment: ", scanUpToCharacters(from: CharacterSet.newlines) as Any)
               _ = scanCharacters(from: CharacterSet.newlines)
               print("x: ", scanString("x") as Any)
               charactersToBeSkipped = CharacterSet.whitespacesAndNewlines
        }
}

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior.
Projects
None yet
Development

No branches or pull requests

2 participants