-
Notifications
You must be signed in to change notification settings - Fork 0
/
lfe_io.txt
142 lines (85 loc) · 4.71 KB
/
lfe_io.txt
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
132
133
134
135
136
137
138
139
140
141
142
lfe_io(3) lfe_io(3)
NAME
lfe_io - Lisp Flavoured Erlang (LFE) io functions
SYNOPSIS
This module provides a standard set of io functions for LFE. In the
following description, many functions have an optional parameter IoDe‐
vice. If included, it must be the pid of a process which handles the
IO protocols such as the IoDevice returned by file:open/2.
Two functions in this module are used to generate aesthetically attrac‐
tive representations of abstract forms, which are suitable for print‐
ing. These functions return (possibly deep) lists of characters and
generate an error if the form is wrong.
DATA TYPES
chars() = [char() | chars()]
filesexpr() = {Sexpr,Line}
This is the format returned by lfe_io:parse_file/1 and is used by the
compiler to give better error information.
EXPORTS
read([[IoDevice,] Prompt]) -> {ok,Sexpr} | {error,ErrorInfo} | eof
Read an s-expr from the standard input (IoDevice) with a prompt
(Prompt). Note that this is not line-oriented in that it stops as soon
as it has consumed enough characters.
read_line([[IoDevice,] Prompt]) -> {ok,Sexpr} | {error,ErrorInfo} | eof
Read an s-expr from the standard input (IoDevice) with a prompt
(Prompt). Note that this is line-oriented in that it reads whole lines
discarding left-over characters in the last line.
read_string(String) -> {ok,Sexpr} | {error,ErrorInfo}
Read an s-expr from String. Note that this only reads from String dis‐
carding left-over characters at the end of the string.
print([IoDevice,] Sexpr) -> ok
Print the s-expr Sexpr to the standard output (IoDevice).
print1(Sexpr) -> DeepCharList
Return the list of characters which represent the s-expr Sexpr.
prettyprint([IoDevice,] Sexpr) -> ok
Pretty print the s-expr Sexpr to the standard output (IoDevice).
prettyprint1(Sexpr) -> DeepCharList
prettyprint1(Sexpr, Depth) -> DeepCharList
prettyprint1(Sexpr, Depth, Indentation) -> DeepCharList
prettyprint1(Sexpr, Depth, Indentation, LineLength) -> DeepCharList
Return the list of characters which represents the prettyprinted s-expr
Sexpr. Default values for Depth is 30, Indentation is 0 and LineLength
is 80.
format([IoDevice,] Format, Args) -> ok
fwrite([IoDevice,] Format, Args) -> ok
format1(Format, Args) -> DeepCharList
fwrite1(Format, Args) -> DeepCharList
Print formatted output. The following commands are valid in the format
string:
· ~w, ~W - print LFE terms
· ~p, ~P - prettyprint LFE terms
· ~s - print a string
· ~e, ~f, ~g - print floats
· ~b, ~B - based integers
· ~x, ~X - based integers with a prefix
· ~+, ~# - based integers in vanilla erlang format
· ~c, ~n, ~i
Currently they behave as for vanilla erlang except that ~w, ~W, ~p, ~P
print the terms as LFE sexprs.
read_file(FileName) -> {ok,[Sexpr]} | {error,ErrorInfo}
Read the file Filename returning a list of s-exprs (as it should be).
parse_file(FileName) -> {ok,[FileSexpr]} | {error,ErrorInfo}
where
FileSexpr = filesexpr()
Read the file Filename returning a list of pairs containing s-expr and
line number of the start of the s-expr.
scan_sexpr(Cont, Chars [,Line]) -> {done,Ret,RestChars}|{more,Cont1}
This is a re-entrant call which scans tokens from the input and returns
a parsed sepxr. If there are enough characters to parse a sexpr or it
detects and error then it returns {done,...} otherwise it returns
{more,Cont} where Cont is used in the next call to scan_sexpr with more
characters to try and parse a sexpr. This is continued until a sexpr
has been parsed. Cont is initially [].
It is not designed to be called directly by an application but used
through the i/o system where it can typically be called in an applica‐
tion by:
io:request(In, {get_until,unicode,Prompt,Module,scan_sexpr,[Line]})
ERROR INFORMATION
The ErrorInfo mentioned above is the standard ErrorInfo structure which
is returned from all IO modules. It has the following format:
{ErrorLine,Module,ErrorDescriptor}
A string describing the error is obtained with the following call:
apply(Module, format_error, ErrorDescriptor)
AUTHORS
Robert Virding.
2008-2019 lfe_io(3)