I wrote a BNF DSL with Java vargs that can also parse text (works for mostly simple things now), if you have seen the query DSL I wrote for DAO is is somewhat similar in concept. You define the rules which are stateless, they create a context and parse the text. My eventual goal is to use the BNF DSL metadata to code generate a parser. The idea being you can define a parser on the fly using the BNF DSL, but this type of reuse has overhead so you can also use the rules, feed it into the new template engine I wrote, and generate a much faster parser if performance is critical. Then you just use the code generated parser instead of the on the fly BNF DSL parser. So the BNF DSL can parse text or work as the seed syntax tree to generate a fast parser. I have no idea why I am doing this. Other than it was really fun. It is all text based now, but I can see working on a BNF DSL for binary data for things like protocols and such. One reason I am doing this for sure is the dreaded one off. I am so sick of writing parser by hand and being one off or having some weird edge case.
I started this because I wrote a template language based on Python's template language, but in Java as part of my effort to make Java more fluent like Python. I added a loop, because every time I use on of these template, I was always think, why does it not have a simple loop concept. Well once I had the loop, it seems like I need an *if* concept, then of course I need an expression language. I started to hack the expression language together and was like damnit this the 20th time I have done this... wouldn't it be nice to have a BNF DSL and I can declare my syntax and get a starting parser.... blah blah blah... SQUIRREL!
Earlier this year, I wrote my own JSON parser in Java. I wanted something small, fast and light that did not have 50,000 bells and whistles and one I could hack with. Also earlier this year, I forked a websocket project and added protocol negotiation to it (an optional feature), mainly to better understand websockets.
No comments:
Post a Comment