That is what I meant, should have been clearer. Those reasons make sense. Thank you! -Zack
On Saturday, June 15, 2013 10:41:49 PM UTC-4, puzzler wrote: > > On Sat, Jun 15, 2013 at 7:21 PM, Zack Maril <thewi...@gmail.com<javascript:> > > wrote: > >> Why does instaparse not throw errors? Curious about the reasoning behind >> this design. >> -Zack >> > > I'm not sure what you mean. It does throw errors for certain kinds of > invalid grammars and other fatal problems. > > Perhaps what you're asking is why a string that doesn't fit the grammar > will return a failure object. There are several reasons: > 1. In my view, it's not really an error -- the parser should return some > kind of value that indicates that the string didn't match the parser, and > the value should contain information about why it didn't match the parser. > It's sort of like choosing to return NaN rather than throwing an error for > certain arithmetic ops. > 2. The failure object is a simple Clojure map that can be explored, > serialized, whatever. (I've chosen to print it somewhat like a thrown > error, but it is in fact a value). > 3. More consistent when you look at things like the total parse mode, > which need to indicate parse failure and return a valid parse > simultaneously. You can't do that if the only way to indicate failure is > by throwing an error. > 4. Makes it possible to chain the output of a parser directly to the > transform function. > 5. Makes it possible to do things like mapping a parser across a > collection of strings to parse. > -- -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en --- You received this message because you are subscribed to the Google Groups "Clojure" group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.