1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
|
.TH SH-SEXPRS 1
.SH NAME
sexprs, islist, els, text, textels, mktext, mklist, mktextlist \- parse and generate S-expressions
.SH SYNOPSIS
.B load sexprs
.B getsexprs
.I command
.br
.B islist
.I sexpr
.br
.B ${els
.IB sexpr }
.br
.B ${text
.IB sexpr }
.br
.B ${textels
.IB sexpr }
.br
.B ${mktext
.IB val }
.br
.B ${mklist
[
.IR val ...
.BR "" ] }
.br
.B ${mktextlist
[
.IR val ...
.BR "" ] }
.br
.SH DESCRIPTION
.B Sexprs
is a loadable module for
.IR sh (1)
that provides the facility to parse and generate
S-expressions (see
.IR sexprs (2)).
The following primitives are provided:
.TP 10
.B getsexprs
.B Getsexprs
works similiarly to
.B getlines
in
.IR sh-std (1).
It reads S-expressions from the standard input, and for expression read, it
invokes
.I command
with
.B $sexp
set to the text representation of that expression.
.B Getsexprs
recognises the usual loop
.B break
and
.B continue
exceptions.
.TP
.BI islist\ sexp
.B Islist
yields a nil (true) status if
.IR sexp ,
which must be a well-formed S-expression,
is a list element.
.TP
.BI ${els\ sexp }
If
.I sexp
is an S-expression containing a list,
then
.B els
returns a list of the S-expressions it contains.
It is an error if
.I sexp
is not a valid S-expression.
.TP
.BI ${text\ sexp }
If
.I sexp
is an S-expression containing a simple element,
then
.B text
returns the value of that element. If
.I sexp
is a list, the return value will be an empty string.
Note that elements
containing binary data will likely be corrupted
by conversion to utf-8.
It is an error if
.I sexp
is not a valid S-expression.
.TP
.BR ${textels\ sexp }
If
.I sexp
is an S-expression containing a list, then
.B textels
returns a list of the text values in that S-expression,
converted as with
.BR ${text} .
It is an error if
.I sexp
is not a valid S-expression.
.TP
.BR ${mktext\ val }
.B Mktext
returns a text representation of the S-expression
containing the simple value
.IR val .
.TP
.BR ${mklist\ \fR[\fPsexp\fR...]\fP }
.B Mklist
returns a text representation of the S-expression list
containing its arguments, which must be well-format
S-expressions.
.TP
.BR ${mktextlist\ \fR[\fPval\fR...]\fP }
.B Mktextlist
returns a text representation of the S-expression list
containing one simple element for each
.IR val .
.SH SOURCE
.B /appl/cmd/sh/sexprs.b
.SH SEE ALSO
.IR sh (1),
.IR sh-std (1),
.IR sexprs (2)
|