-
I'm getting segmentation faults (in Xcode 14.2) and EXC_BAD_ACCESS (in Xcode 14.3) running the ParserPrinter below. I'm sorry the "minimal example" is not more minimal, but all the ways I've tried to make it smaller remove the symptom (including removing code that isn't even called). This is with version 0.12.0 of the library. import Foundation
import Parsing
@main
struct Script {
static func main() throws {
let package = try setupPyFileP.parse(example)
print(package)
}
}
let example = """
setup(
name='md.widget',
version=version) # yapf: disable
"""
let doubleQuotedStringP: some ParserPrinter<Substring, Substring>
= ParsePrint(input: Substring.self) {
"\""
PrefixUpTo("\"")
"\""
}
let stringP: some ParserPrinter<Substring, Substring>
= ParsePrint {
// OneOf {
// singleQuotedStringP
doubleQuotedStringP
// }
}
struct PackageName {
let value: Substring
}
enum DoNotCare {
case string(Substring)
}
enum SetupArg {
case name(PackageName)
case doNotCare(Substring, DoNotCare)
}
// This isn't even *used* but if we remove it the parsing gets (much) further
let listWeDoNotCareP: some ParserPrinter<Substring, Substring>
= ParsePrint(input: Substring.self) {
"["
PrefixUpTo("]")
"]"
}
let nameArgP: some ParserPrinter<Substring, SetupArg>
= ParsePrint(.case(SetupArg.name)) {
"name="
doubleQuotedStringP.map(.memberwise(PackageName.init))
}
let doNotCareArgP: some ParserPrinter<Substring, SetupArg>
= ParsePrint(.case(SetupArg.doNotCare)) {
PrefixUpTo("=")
"="
doubleQuotedStringP.map(.case(DoNotCare.string))
}
let setupPyFileP: some ParserPrinter<Substring, (Substring, SetupArg, Substring)>
= ParsePrint(input: Substring.self) {
PrefixThrough("setup(")
OneOf {
nameArgP
doNotCareArgP
}
Rest()
} |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
I can't say I know why the parser is crashing, but I do know a fix. I think Swift has a hard time dealing with large, complex types held in variables, double so for file-scope variables, and triply so when mixed with struct DoubleQuoteString: ParserPrinter {
var body: some ParserPrinter<Substring, Substring> {
ParsePrint {
"\""
PrefixUpTo("\"")
"\""
}
}
} And then updated all instances of I would recommend updating all of your parsers to this style. They will compile much faster and hopefully avoid problems like this in the future. Also I am going to convert this to a discussion because I'm not sure there's anything we can do in the library, but it does make for a good discussion. |
Beta Was this translation helpful? Give feedback.
-
There's a second possible fix: take the variables out of file-scope. If I put them instead as locals inside a huge The |
Beta Was this translation helpful? Give feedback.
I can't say I know why the parser is crashing, but I do know a fix. I think Swift has a hard time dealing with large, complex types held in variables, double so for file-scope variables, and triply so when mixed with
some P
types. I converted a single one of your parsers to the more modernbody
style of parsing:And then updated all instances of
doubleQuoteString
withDoubleQuoteString()
and it started working. Well, the parser is failing, but at least it isn't crashing.I would recommend updating all of your parsers to …