Skip to Main Content
Language Implementation Patterns
book

Language Implementation Patterns

by Terence Parr
December 2009
Intermediate to advanced content levelIntermediate to advanced
380 pages
9h 2m
English
Pragmatic Bookshelf
Content preview from Language Implementation Patterns

Generating Templates from a Simple Input Model

There are many cases where we have an internal data structure, such as a tree or network graph, that we’d like to visualize for documentation or debugging purposes. This is a perfect opportunity to flex our code generation muscles. We can generate graphical descriptions using the DOT DSL of Graphviz, an open source graph visualization tool.

As an example application, let’s visualize the link interconnections between web pages. It’ll teach us the basics of creating output templates from an input model. From a list of Link objects, we’ll generate a series of from->to edge definitions in a DOT file surrounded by some bookkeeping definitions.

 
digraph testgraph {
 
node [shape=plaintext, fontsize=12, ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Implementation Patterns

Implementation Patterns

Kent Beck

Publisher Resources

ISBN: 9781680500097Errata Page