diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2016-01-01 12:23:00 -0800 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2016-01-01 12:23:00 -0800 |
commit | 27e0a161c083222ef78bcf6192b931aa815583b3 (patch) | |
tree | ebb045f0417307f3c7763ce900cbb4b50781e581 /txr.1 | |
parent | bccdfcb523d7b0315c20a41dec43a6b0cf302a73 (diff) | |
download | txr-27e0a161c083222ef78bcf6192b931aa815583b3.tar.gz txr-27e0a161c083222ef78bcf6192b931aa815583b3.tar.bz2 txr-27e0a161c083222ef78bcf6192b931aa815583b3.zip |
Record-delimiting stream adapter.
* regex.c (read_until_match): New function.
(regex_init): Registered read-until-match intrinsic.
* regex.h (read_until_match): Declared.
* stream.c (struct delegate_base): New struct type.
(delegate_base_mark, delegate_put_string, delegate_put_char,
delegate_put_byte, delegate_get_char, delegate_get_byte,
delegate_unget_char, delegate_unget_byte, delegate_close,
delegate_flush, delegate_seek, delegate_truncate,
delegate_get_prop, delegate_set_prop, delegate_get_error,
delegate_get_error_str, delegate_clear_error,
make_delegate_stream): New static functions.
(struct record_adapter_base): New struct type.
(record_adapter_base_mark, record_adapter_mark_op,
record_adapter_get_line): New static functions.
(record_adapter_ops): New static structure.
(record_adapter): New function.
(stream_init): Registered record-adapter intrinsic.
* stream.h (record_adapter): Declared.
* txr.1: Documented read-until-match and record-adapter.
Diffstat (limited to 'txr.1')
-rw-r--r-- | txr.1 | 89 |
1 files changed, 89 insertions, 0 deletions
@@ -29825,6 +29825,49 @@ The double backslash in the string literal produces a single backslash in the resulting string object that is processed by .codn regex-parse . +.coNP Function @ read-until-match +.synb +.mets (read-until-match < regex <> [ stream ]) +.syne +.desc +The +.code read-until-match +function reads characters from +.metn stream , +accumulating them into a string, which is returned. + +If an argument is not specified for +.metn stream , +then the +.code *std-input* +stream is used. + +The accumulation of characters is terminated by a match on +.metn regex , +the end of the stream, or an error. + +This means that characters are read from the stream and accumulated while the +stream has more characters available, and while its prefix does not match +.metn regex . + +If +.meta regex +matches the stream before any characters are accumulated, +then an empty string is returned. + +If the stream ends or an error occurs before any characters +are accumulated, the function returns +.codn nil . + +When the accumulation of characters terminates by a match on +.metn regex , +reading characters from the stream continues. The longest +possible prefix of the stream which matches +.meta regex +is read, and discarded. If an error is encountered, the +matching procedure terminates and returns the previously +accumulated string. + .SS* Hashing Library .coNP Functions @, make-hash and @ hash .synb @@ -33746,6 +33789,52 @@ possibility that the expression will be further extended by means of the dot or dotdot operators. An explicit end-of-input signal must be given from the terminal to terminate the expression. +.coNP Function @ record-adapter +.synb +.mets (record-adapter < regex <> [ stream ]) +.syne +.desc +The +.code record-adapter +function returns a new stream object which acts as an +.I adapter +to the existing +.metn stream . + +If an argument is not specified for +.metn stream , +then the +.code *std-input* +stream is used. + +With the exception of +.metn get-line , +all operations on the returned adapter transparently delegate to the original +.meta stream +object. + +When the +.code get-line +function is used on the adapter, it behaves differently. A string is +extracted from +.metn stream , +and returned. However, the string isn't a line delimited by a newline +character, but a record delimited by +.metn regex +as if using the +.code read-until-match +function. + +All behavior which is built on the +.code get-lines +functions is affected by the record-delimiting semantics of a record adapter's +.code get-line +implementation. Notably, the +.code get-lines +and +.code lazy-stream-cons +functions return a lazy list of delimited records rather than of lines. + .SS* Stream Output Indentation \*(TL streams provide support for establishing hanging indentations in text output. Each stream which supports output has a built-in state variable |