Reading Continued Lines -- library(continued)

library(continued) is an extension of library(lineio). It defines two commands for reading continued lines.

reads a line of text, using a convention rather like that of BCPL: an input line that ends with <op, newline> where op is a left parenthesis (, left bracket [, left brace {, or a binary infix character from the set
          + * - / # = < > ^ | & : ,

is taken to be continued; the op character is included in the combined Line, but the newline is not included.

          | ?- compile([library(printchars),library(continued)]).
                    . . .
          | ?- read_oper_continued_line(Line).
          |: command /option1=value1,
          |:    /option2=value2
          Line = "command /option1=value1,   /option2=value2"
          | ?- read_oper_continued_line(Line).
          |: Not continued!
          Line = "Not continued!"
          | ?- read_oper_continued_line(Line).
          |: x^2+
          |: 2*x+
          |: 1
          Line = "x^2+2*x+1"

It is likely that this will not be exactly the set of characters you want to act as continuation indicators, and you may want some op characters retained and others discarded. That is why we make the source code available: this file is intended mainly as an example.

uses the UNIX convention (understood by sh, csh, cc, and several other programs) that a line terminated by a <backslash, newline> pair is continued, and the backslash and newline do not appear in the combined Line. For example,
          | ?- read_unix_continued_line(Line).
          |: ab\
          |: cde\
          |: f
          Line = "abcdef"

The following example is an extract from /etc/termcap:

          | ?- unix(system('cat termcap-extract')).
          dw|vt52|dec vt52:\
              :le=^H:bs:cd=\EJ:ce=\EK:cl=\EH\EJ:cm=\EY%+ %+ :\
          dx|dw2|decwriter II:\
          | ?- see('termcap-extract'),
          |    read_unix_continued_line(Line),
          |    seen.
          Line = "dw|vt52|dec vt52:    :cr=^M:do=^J:nl=^J:bl=^G:
              :le=^H:bs:cd=\EJ:ce=\EK:cl=\EH\EJ:cm=\EY%+ %+ :
           :co#80:li#24:nd=\EC:ta=^I:pt:sr=\EI:up=\EA:    :ku=\E

Note that only the backslashes at the ends of the lines have been discarded, and that the spaces at the beginning of the following lines have been retained.