-
Notifications
You must be signed in to change notification settings - Fork 15
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
Relying on Parsers.xparse
behavior when a parse fails
#78
Comments
Sorry for the slow response. Yeah, that can be relied upon behavior, but note that if you pass |
Sure thing, thanks for the response. I've actually switched my parsing code to Go, where I've found ways to make everything much faster (some of which could have been done in Julia, but the faster startup time is a big boon as well, since it lets me build a fast command line tool that composes well with other UNIX utilities).
That sounds great, and like exactly what I was looking for! In Go I ended up with this inside a loop, which parses strings like // Parse the hour
hour := buf[i] - 'A'
// Parse the first digit of the number, which always follows a letter.
var count int64 = int64(buf[i] - '0')
i++
// Parse and accumulate any remaining digits onto count
for i < l {
digit := buf[i] - '0'
// '0'..'9' will have values 0..9, while A-Z will have higher values.
if digit < 10 {
count = count*10 + int64(digit)
} else {
break
}
i++
}
counts[hour] += count |
Cool; sounds great. |
I am working with strings interspersed with letters. I'd like to parse numbers up to either the next letter or the end of the string. I can do this with
xparse
:If a parse fails, the first tuple element
x
holds the result I'm looking for. However, it is not documented whether this is intentional behavior (that thex
is correct up to the moment of the parse failing).I'm curious – is this a sanctioned use of
Parsers.xparse
? The docs state that "x
is a value of typeT
, even if parsing does not succeed" but do not say that the answer is guaranteed to be correct.If it is guaranteed, I'd be happy to submit a docs PR. Thanks for your work on this package!
The text was updated successfully, but these errors were encountered: