library(continued)
library(continued)
is an extension of library(lineio)
. It defines
two commands for reading continued lines.
read_oper_continued_line(
-Line)
<
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.
read_unix_continued_line(
-Line)
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:\ :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=\EA:kd=\EB:kr=\EC:kl=\ED:kb=^H: dx|dw2|decwriter II:\ :cr=^M:do=^J:nl=^J:bl=^G:\ :kb=^h:le=^H:bs:co#132:hc:os: | ?- 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 A:kd=\EB:kr=\EC:kl=\ED:kb=^H:"
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.