On Tue, Jul 21, 2009 at 6:51 AM, Martijn Faassen<[email protected]> wrote: > > Hey, > > A bit late to respond, but thanks for this new interesting idea!
Thanks. There are a couple more interesting examples I came up with. The first is parsing and evaluating a C-style \-escaped string (used in JSON, Python, Protocol Buffers, etc.): http://code.google.com/p/json-pattern/source/browse/tests/examples_test.py There's a bit of unnecessary junk in that test, but the idea is that you can split it up into manageable expressions rather than write a huge regex, and you can also evaluate the escapes inline with filters. Compare with the Python stdlib, in tokenize.py, they use the "huge ungainly regex" approach. It might be faster too -- I have to time it -- because alternation in regexes (|) can cause unnecessary backtracking, and in this case you want to just look forward. As noted in the Friedl book on regexes, sometimes it's faster to split them up. The other one is more of a toy example, and RPN calculator: http://code.google.com/p/json-pattern/source/browse/tests/rpn_test.py I compared that with this: http://daniel.carrera.bz/2009/06/rpn-calculator-in-perl-6/ I think it's a lot more straightforward and elegant, but neither example is really all that impressive compared to the most straightforward possible Python implementation, which is like 10 lines : ) Andy --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "JSON Template" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/json-template?hl=en -~----------~----~----~----~------~----~------~--~---
