Generating Syntax Diagrams Using Tk (original) (raw)

Tcl/Tk saves the day!

SQLite users wanted syntax diagrams instead of BNF to describe the SQL language. Syntax diagrams look something like this:

http://www.sqlite.org/draft/images/syntax/create-table-stmt.gif

created from this:

create-table-stmt { stack {line CREATE {or {} TEMP TEMPORARY} TABLE {opt IF NOT EXISTS}} {line {optx /database-name .} /table-name} {or {line ( {loop column-def ,} {loop {} {, table-constraint}} ) {opt WITHOUT ROWID}} {line AS select-stmt} } }

The question become: how does one generate diagrams? A quick Tcl/Tk script did the job for me nicely. A high-level description of each diagram (in the form of a nested Tcl list, though really more of a lisp predicate) is entered and a Tk script renders the diagram on a canvas widget. The postscript method of the canvas widget is then used to create a postscript file of the diagram. Finally, the "convert" utility of ImageMagick is invoked (via the exec command) to convert the postscript into an antialias-ed GIF at the appropriate resolution.

Lars H: Is that "lisp predicate" an alias for data is code, I wonder? Checking the code, I see it isn't implemented that way, but it seems plausible that it could be…

Lars H: Hmm… When just jumping to that page, there aren't any [view] links on it — turns out one has to log in (as anonymous) to see them. And after logging in, I'm put in some sort of limbo, from which I have to manually jump back to the bubble-generator.tcl page. Only then can I [view] the code!