robrix / Madness

Recursive Descent Into Madness
MIT License
291 stars 17 forks source link

Logging combinator #45

Open robrix opened 9 years ago

robrix commented 9 years ago

For debugging. I wrote this one, which is pretty bad:

func log<T>(parser: Parser<T>.Function, message: String = "") -> Parser<T>.Function {
    return {
        println("parsing from \($0) \(message)")
        let result = parser($0)
        println("got \(result) \(message)")
        return result
    }
}

This should actually append into a logging context which is only printed when parsing fails.

It should also indent, and print the grammar (although that’s difficult at best).