Skip to content

Commit f27a4ab

Browse files
committed
update docs with more information
changes to file "docs/built-ins.md": + add undocumented subs + add undocumented methods on a file handle changes to file "docs/ops.markdown": + correct and expand on some nqp subs change to file "src/core/IO.nqp": + correct indent to four spaces on IO.nqp
1 parent d3794d7 commit f27a4ab

File tree

3 files changed

+137
-23
lines changed

3 files changed

+137
-23
lines changed

docs/built-ins.md

Lines changed: 118 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,128 @@
11
# NQP Built-in Subs List
22

3-
The following subroutines are available to use in ```nqp``` programs.
4-
They are described in ```nqp/src/core``` modules.
3+
The following subroutines are available to use in `nqp` programs.
4+
They are described in `nqp/src/core` modules.
55

6-
# From ```nqp/src/core/Regex.nqp```
6+
# From `nqp/src/core/Regex.nqp`
77

88
## match
9-
* `match($text, $regex, :$global?)`
9+
* `match($text, $regex, :$global? --> @array)`
1010

11-
Match ```$text``` against ```$regex```. If the ```$global``` flag is
11+
Match `$text` against `$regex`. If the `$global` flag is
1212
given, then return an array of all non-overlapping matches.
1313

1414
## subst
15-
* `subst($text, $regex, $replacement, :$global?)`
15+
* `subst($text, $regex, $replacement, :$global? --> str)`
1616

17-
Substitute a match of ```$regex``` in ```$text``` with ```$replacement```,
18-
returning the substituted string. If ```$global``` is given, then
19-
perform the replacement on all matches of ```$text```.
17+
Substitute a match of `$regex` in `$text` with `$replacement`,
18+
returning the substituted string. If `$global` is given, then
19+
perform the replacement on all matches of `$text`.
20+
21+
# From `nqp/src/core/IO.nqp`
22+
23+
## open
24+
* `open($filename, :$r, :$w, :$a, :$bin, :$enc, :$chomp --> $filehandle)`
25+
26+
Open file `$filename`. Options:
27+
+ :w - open for writing
28+
+ :r - open for reading (default)
29+
+ :a - open for appending
30+
+ :bin - open in binary mode
31+
+ :enc - define encoding (default: `utf8`)
32+
+ :chomp - strip ending newlines (default: true)
33+
34+
## close
35+
* `close($fh)`
36+
37+
Close the file attached to file handle `$fh`.
38+
39+
## slurp
40+
* `slurp ($filename --> str)`
41+
42+
Returns the contents of `$filename` as a single string.
43+
44+
## spew
45+
* `spew($filename, $contents)`
46+
47+
Write the string value of `$contents` to `$filename`.
48+
49+
## say
50+
* `say($string)`
51+
52+
Write `$string` to `stdout` with a newline added.
53+
54+
## note
55+
* `note($string)`
56+
57+
Write `$string` to `stderr` with a newline added.
58+
59+
## join
60+
* `join($delim, @array --> str)`
61+
62+
Returns a string formed by joining each element of `@array`
63+
with the `$delim`.
64+
65+
## print
66+
* `print($string)`
67+
68+
Write `$string` to `stdout`.
69+
70+
## stdin
71+
* `stdin(--> $filehandle)`
72+
73+
Returns a file handle to `stdin`.
74+
75+
## stdout
76+
* `stdout(--> $filehandle)`
77+
78+
Returns a file handle to `stdout`.
79+
80+
## stderr
81+
* `stderr(--> $filehandle)`
82+
83+
Returns a file handle to `stderr`.
84+
85+
# File handle (fh) methods
86+
87+
Some methods available on the file handle (fh) returned from `open`.
88+
Other methods available of lesser interest not documented below are:
89+
+ flush
90+
+ get
91+
+ seek
92+
+ set-encoding
93+
+ set-nl-in
94+
+ t
95+
+ tell
96+
+ wrap
97+
98+
## fh.slurp
99+
* `$fh.slurp()`
100+
101+
Reads the entire file attached to file handle `$fh`.
102+
103+
## fh.print
104+
* `$fh.print($string)`
105+
106+
Write `$string` to the file attached to file handle `$fh`.
107+
An ending newline is not added.
108+
109+
## fh.say
110+
* `$fh.say($string)`
111+
112+
Write `$string` to the file attached to file handle `$fh`.
113+
An ending newline is added.
114+
115+
## fh.close
116+
* `$fh.close()`
117+
118+
Close the file attached to file handle `$fh`.
119+
120+
## fh.readchars
121+
* `$fh.readchars($nchars)`
122+
123+
Read `$nchars` characters from file handle `$fh`.
124+
125+
## fh.eof
126+
* `$fh.eof`
127+
128+
Returns true if end-of-file has been reached on file handle `$fh`.

docs/ops.markdown

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# NQP Opcode List
1+
List
22

33
## Table of Contents
44

@@ -1321,7 +1321,7 @@ must have elements of type `int8` or `uint8`.
13211321

13221322
Returns an NFG string consisting of `$num-chars` graphemes, provided that
13231323
many are available after decoding. If less than `$num-chars` characters
1324-
can be decoded, then `nqp::null_s` will be returned. Note that some a
1324+
can be decoded, then `nqp::null_s` will be returned. Note that a
13251325
decoded codepoint at the end of a byte buffer may not be available as a
13261326
character if the encoding allows the next character to be a combining
13271327
character.
@@ -1349,7 +1349,7 @@ Decodes bytes until a line separator is reached, or all bytes have been
13491349
decoded. If `$incomplete-ok` is zero and the separator was not found, then
13501350
`nqp::null_s` will be returned. (Thus, `$incomplete-ok` is appropriate only
13511351
when knowing that the end of the stream has been reached.) If `$chomp` is
1352-
non-zero, then the separator - if present - will not be included in the
1352+
non-zero, then the separator--if present--will not be included in the
13531353
resulting string.
13541354

13551355
## decoderbytesavailable
@@ -2540,18 +2540,23 @@ specific to a given backend. The type to use for that is given as $handle_type.
25402540
## permit
25412541
* `permit(AsyncTask $handle, int $channel, int $permits)`
25422542

2543-
Takes something with the AsyncTask REPR and permits it to emit up to `$permits`
2544-
more notifications. This is used as a back-pressure mechanism for asynchronous
2545-
tasks that produce a stream of events, such as representing data arriving over
2546-
a socket. Some kinds of tasks may emit on multiple channels, for example an
2547-
asynchronous process may emit events for STDOUT and STDERR if both are of
2548-
interest. The `$channel` argument is used to specify which channel is to get
2549-
the permits if needed. If `$permits` is less than zero then it means there is
2550-
no limit to the emits. If it is set to any value greater than or equal to
2551-
zero, then:
2543+
Takes something with the AsyncTask REPR (the `$handle` parameter) and
2544+
permits it to emit up to `$permits` more notifications. This is used
2545+
as a back-pressure mechanism for asynchronous tasks that produce a
2546+
stream of events, such as representing data arriving over a
2547+
socket. Some kinds of tasks may emit on multiple channels, for example
2548+
an asynchronous process may emit events for STDOUT (channel 1) and
2549+
STDERR (channel 2) if both are of interest. The `$channel` argument is
2550+
used to specify which channel is to get the permits if needed (use a
2551+
separate `permit` stament for each channel of interest).
2552+
2553+
If `$permits` is less than zero (e.g., `permit($task, $channel, -1)`,
2554+
then it means there is no limit to the emits.
2555+
2556+
If `$permits` is set to any value greater than or equal to zero, then:
25522557

25532558
* In the case unlimited emits were permitted previously, the permits will be
2554-
set to the new value. If the new value is zero then the reader will be
2559+
set to the new value. If the new value is zero, then the reader will be
25552560
stopped.
25562561
* Otherwise the number of permits will be incremented by the specified value.
25572562
If the resulting number of permits allowed is greater than zero and the

src/core/IO.nqp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ my class NQPFileHandle {
147147
$line
148148
}
149149

150-
method slurp() {
150+
method slurp() {
151151
$!decoder || nqp::die("Cannot 'slurp' on a binary file handle");
152152
while nqp::elems(my $buf := nqp::readfh($!vmio, nqp::create($NQPBuf), 0x100000)) {
153153
$!decoder.add-bytes($buf);

0 commit comments

Comments
 (0)