Issues trying to convert my AdventOfCode code to use Parsers #264
-
Hey, I'm very new with Parsers in this use case. I've answered all the AoC days up to now using just raw Swift but wanted to convert what I've got to use Parsers. Anyway, I'm trying to do day one which has an input like...
Copying the style that Luke Redpath did here... #260 I tried to create a Parser like this...
But I'm getting an Error on the line If I change it to something like...
The error goes away. Do I need to provide the Thanks |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 2 replies
-
Hey @oliverfoggin! Sometimes, the compiler can have difficulties picking the private enum Parsers {
static let calories = Parse({ $0 }) {
Many {
Int.parser(of: Substring.self)
} separator: {
Whitespace(1, .vertical)
} terminator: {
Whitespace(1, .vertical)
}
}
}
BTW, the |
Beta Was this translation helpful? Give feedback.
-
你好,我已经收到你的邮件,我一定会仔细阅读,感谢你的来信,祝好!——by zlh
|
Beta Was this translation helpful? Give feedback.
-
这是来自QQ邮箱的假期自动回复邮件。
您好,我最近正在休假中,无法亲自回复您的邮件。我将在假期结束后,尽快给您回复。
|
Beta Was this translation helpful? Give feedback.
Hey @oliverfoggin! Sometimes, the compiler can have difficulties picking the
Input
type. In your case, you can nudge it in the right direction using theof:
argument ofInt.parser
:SubString.self
is already the default of this parameter, but it is not enough in this configuration for the compiler apparently.The radix defines the "base" that is used, and allows to parse the hexadecimal "5F" as "95" in base 10 for example. In your case, you can keep the default value of…