XTRAN Example — Text Input with Continuations

Scenario -- you are writing XTRAN rules (which we call "meta-code") that process text files, but those files have line continuations in them.

XTRAN itself to the rescue!

There are two main conventions used to indicate line continuations in text files:

The following example uses an XTRAN rules file comprising 141 non-comment lines of "meta-code" that allows you to read a text file with either type of continuation convention.  When you initialize for input, you can specify either an EOL continuation flag or a BOL continuation header, and the rules then handle continuations for you as you do text input.

The rules took 1¾ hours to write and 1¼ hours to debug.  (That's right, only 3 hours total!)

(Note, by the way, that XTRAN automatically handles continuations in computer languages it parses.  This example is about XTRAN rules that read text files.)

We show two scenarios below, one for each continuation convention.  In each scenario, we use our line continuation facility to read a text file, with continuations handled by that facility.  Both scenarios simply copy the files, to show how the continuations were handled.

How can such powerful and generalized text manipulation be automated in 3 hours and only 141 code lines of XTRAN rules?  Because there is so much capability already available as part of XTRAN's rules language.  These rules take advantage of the following functionality:

The input to and output from XTRAN are untouched.




Process Flowchart

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

data flowchart

Scenario 1 — End-of-line continuation flags

In this scenario, the text input file indicates continuation with a ? at the end of a continued line.



Input to XTRAN:

Line 1, not continued
Line 2, continued?
 - more line 2, continued ?
 - more line 2, not continued
Line 3, not continued
Line 4, continued?
 - more line 4, not continued
Line 5, not continued
Line 6, not continued



Output from XTRAN:

Line 1, not continued
Line 2, continued - more line 2, continued - more line 2, not continued
Line 3, not continued
Line 4, continued - more line 4, not continued
Line 5, not continued
Line 6, not continued



Scenario 2 — Beginning-of-line continuation headers

In this scenario, the text input file indicates continuation with four spaces at the beginning of a continuation line.



Input to XTRAN:

Line 1, not continued
Line 2, continued
     - more line 2, continued
     - more line 2, not continued
Line 3, not continued
Line 4, continued
     - more line 4, not continued
Line 5, not continued
Line 6, not continued



Output from XTRAN:

Line 1, not continued
Line 2, continued - more line 2, continued - more line 2, not continued
Line 3, not continued
Line 4, continued - more line 4, not continued
Line 5, not continued
Line 6, not continued