Chapter 45. Textual Polishing

Perform simple textual substitutions before more serious processing.

3 hours ago => 3.hours.ago

Internal DSLs are often easier to develop, particularly if you’re not comfortable with parsing. However, the resulting DSLs contain host language artifacts that can are awkward for nonprogrammers to read.

Textual Polishing uses a series of simple regular expression substitutions to smooth some of these out.

45.1 How It Works

Textual Polishing is a very simple technique. It involves running a series of text substitutions on the DSL script before it gets to the parser. A simple example is if readers find the use of dots for method calls off-putting. A simple substitution of dots for spaces can turn 3 hours ago into

Get Domain Specific Languages now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.