Discussion about this post

User's avatar
Paul Tarvydas's avatar

A Grammar defines the inhaling step. It does pattern matching on the input and creates a tree (a CST - Concrete Syntax Tree) while Rewrite defines the exhaling step and defines /what/ to do with the matches (captured data stored in nodes of the CST). At present, OhmJS (my favourite grammar tool) uses a small DSL to define the grammar side of things, but, punts to full-blown Javascript to do the rewrite side of things. I've defined a small DSL to handle the rewrite side of things. In the past, I've called it by various names, like Glue, Grasem, RWR, etc. When doing the rewriting, the main thing that matters is text manipulation, so the Rewrite nano-DSL deals only with strings and string interpolation. All of the other stuff offered by JS can simply be ignored. This makes things much simpler and reduces cognitive load, allowing you to solve tougher problems instead of a bunch of niggly problems. Even though this might sound like an over-simplification, I've been using this idea for years and have found that it is very powerful, powerful enough to define new very-high-level languages, JSON file manipulators, etc. I document the details of the nano-DSL for rewriting in another article "Experiments With Text to Text Transpilation".

Aside: if you squint just right, you will notice that REGEX is a pair of nano-DSLs - one for pattern matching and one for rewriting the matched stuff. The REGEX syntax is more compact, but Ohm+Rewrite is more powerful and more readable.

Rajiv Abraham's avatar

What does the rewrite window contain?

1 more comment...

No posts

Ready for more?