Skip to content

Comment on A parser-combinator approach to parsing JSONparent

Comments

Each element of the returned list represents one way that the parser can "succeed". For example, if your parser is for the regexp "a+" and you give the string "aaabc", then the parser can return (("a" . "aabc") ("aa" . "abc") ("aaa" . "bc")] to say that it can interpret "aaabc" in 3 ways. You can transform this into the "longest" parse by filtering this list for the shortest "remaining string".

If your parser returns [] it means it cannot parse the string, so it all fits together. I don't know if I can find the time to rewrite the code to show you explicitly how this could help, but looking at Parsec (in Haskell) will give you a good idea of what I'm talking about

http://legacy.cs.uu.nl/daan/download/parsec/parsec.html

Very interesting! Would you use this for backtracking?

AboutSource Built by g1lg1l

Hackerly is an independent reader for Hacker News, built on the public HN API. Not affiliated with Y Combinator.