XTRAN Example — Translate HP (Digital, Compaq) Runoff to Rich Text Format (RTF)

The following example uses a set of XTRAN rules comprising just under 400 non-comment lines of "meta-code" (XTRAN's rules language) to translate Runoff to Rich Text Format (RTF).  Runoff is a document markup language that is an ancestor of Unix's Nroff and is commonly found on HP (Digital, Compaq) computers.  RTF is a document markup language used by, among others, Microsoft applications.

This example shows XTRAN's power as a text manipulator.  The rules read a Runoff source file, translate the Runoff commands and in-text formatting to their RTF equivalents, and write out the resulting RTF file.  The version of XTRAN used was built with only a rules language parser and no code renderers, since the only language it must parse is its own rules language, and it produces nothing but text.  The parsing of the Runoff commands and text, and the generation of the RTF commands and text, are done completely in meta-code.

The rules fetch the values of environment variables to determine the document's author and owner.  They implement a substantial subset of Runoff's commands, and are easily extensible to add more.



Process Flowchart

Here is a flowchart for this process, in which the elements are color coded:

process flowchart

Input to XTRAN (Runoff):

.C;Centered text
.S
This is an ^&underlined\& word in a sentence by itself.
.S
This is another sentence by itself; it has an _# escaped sharp.
.BR
This follows a hard line break; it has an _\ escaped backslash.
.PG
This follows a hard page break; it has {curly} brackets.  It
continues as a long paragraph, requiring automatic wrapping etc.  It
continues as a long paragraph, requiring automatic wrapping etc.  It
continues as a long paragraph, requiring automatic wrapping etc.  It
continues as a long paragraph, requiring automatic wrapping etc.  It
continues as a long paragraph, requiring automatic wrapping etc.  It
continues as a long paragraph, requiring automatic wrapping
etc.  This line ends with period, so it should get 2 spaces after it.
This line ends with "?" so it should get 2 spaces after it?  This line ends
with ";" so it shouldn't get 2 spaces after it; it continues as a long
paragraph, requiring automatic wrapping etc.
.S
This sentence has a hyphenation char=acter between "char" and
"acter".  It continues as a long paragraph, requiring automatic
wrapping etc.  It continues as a long paragraph, requiring automatic
wrapping etc.
.S
.NF
This paragraph is with "fill"
turned off.
.S
So is this paragraph, which
consists of 2 lines.
.S
.F
This paragraph was originally
2 lines, but "fill" is turned on.
.S
.NJ
This sentence is the start of a long paragraph,
which goes on and on and on and on and on and on and on and on and on and on
and on and on and on and
on and on and on and on.  It has very ragged lines, and it has "justify"
turned off but "fill" turned on.
.S
.J
This sentence is the start of a long paragraph,
which goes on and on and on and on and on and on and on and on and on and on
and on and on and on and
on and on and on and on.  It has very ragged lines, and it has "justify"
turned back on; "fill" is still turned on.
.S
This is the final sentence.

Output from XTRAN (RTF, as rendered by Microsoft Word):

Centered text

This is an underlined word in a sentence by itself.

This is another sentence by itself; it has an # escaped sharp.
This follows a hard line break; it has an \ escaped backslash.

<Page break>

This follows a hard page break; it has {curly} brackets.  It continues as a long paragraph, requiring automatic wrapping etc.  It continues as a long paragraph, requiring automatic wrapping etc.  It continues as a long paragraph, requiring automatic wrapping etc.  It continues as a long paragraph, requiring automatic wrapping etc.  It continues as a long paragraph, requiring automatic wrapping etc.  It continues as a long paragraph, requiring automatic wrapping etc.  This line ends with period, so it should get 2 spaces after it.  This line ends with "?" so it should get 2 spaces after it? This line ends with ";" so it shouldn't get 2 spaces after it; it continues as a long paragraph, requiring automatic wrapping etc.

This sentence has a hyphenation character between "char" and "acter".  It continues as a long paragraph, requiring automatic wrapping etc.  It continues as a long paragraph, requiring automatic wrapping etc.

This paragraph is with "fill"
turned off.

So is this paragraph, which
consists of 2 lines.

This paragraph was originally 2 lines, but "fill" is turned on.

This sentence is the start of a long paragraph, which goes on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on.  It has very ragged lines, and it has "justify" turned off but "fill" turned on.

This sentence is the start of a long paragraph, which goes on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on and on.  It has very ragged lines, and it has "justify" turned back on; "fill" is still turned on.

This is the final sentence.