edward

An extensible POSIX-compatible implementation of the ed(1) text editor

git clone https://git.8pit.net/edward.git

 1;;> This is a stripped-down and minimally modified version of [chibi parse][chibi parse],
 2;;> a parser combinator library with optional memoization. This version of the library
 3;;> is specifically designed to faciliate building read-eval-print loops with parser
 4;;> combinators.
 5;;>
 6;;> Apart from [parse streams][stream section], the central abstraction of this libary
 7;;> is therefore a [REPL][repl section] type which continously reads data from standard
 8;;> input and parses this data with parsers constructed using provided parser combinators.
 9;;>
10;;> An exemplary parser may be constructed as follows:
11;;>
12;;> ```
13;;> (import (srfi 14) (edward parse))
14;;>
15;;> (define hexadecimal
16;;>   (parse-map
17;;>     (parse-seq
18;;>       (parse-string "0x")
19;;>       (parse-map
20;;>         (parse-token char-set:hex-digit)
21;;>         (lambda (str)
22;;>           (string->number str 16))))
23;;>     cadr))
24;;> ```
25;;>
26;;> This parser recognizes hexadecimal integers using the character set definition
27;;> provided by [SRFI 14][srfi 14] and transform these characters into a Scheme
28;;> number type using [parse-map][parse-map]. Refer to the documentation below
29;;> for more information on available combinators.
30;;>
31;;> [chibi parse]: https://synthcode.com/scheme/chibi/lib/chibi/parse.html
32;;> [stream section]: #section-parse-streams
33;;> [repl section]: #section-read–eval–print-loop
34;;> [srfi 14]: https://srfi.schemers.org/srfi-14/srfi-14.html
35;;> [parse-map]: #parse-map
36
37(define-library (edward.parse)
38  (import (scheme base)
39          (scheme char)
40          (scheme file)
41          (scheme write)
42
43          (srfi 1)
44          (srfi 14)
45
46          (edward util)
47
48          (only (chicken file posix) file-read file-close fileno/stdin)
49          (only (chicken process signal) set-signal-handler! signal/int))
50
51  ;; repl.scm
52  (export make-repl repl? repl-run repl-interactive repl-prompt?  repl-set-prompt!)
53
54  ;; parse.scm
55  (export call-with-parse parse parse-fully parse-fold parse-failure
56          parse->list parse-fully->list
57          file->parse-stream string->parse-stream parse-stream-substring
58          parse-stream-start? parse-stream-end? parse-stream-ref
59          parse-anything parse-nothing parse-epsilon
60          parse-seq parse-and parse-or parse-not list->parse-seq
61          parse-repeat parse-repeat+ parse-optional
62          parse-map parse-map-substring parse-ignore parse-assert
63          parse-atomic parse-commit parse-lazy parse-memoize
64          parse-char parse-not-char
65          parse-string parse-token
66          parse-beginning parse-end
67          parse-beginning-of-line parse-end-of-line
68          parse-with-failure-reason
69          make-parse-stream)
70
71  ;; parse-util.scm
72  (export parse-fail parse-bind parse-as-string parse-digits parse-lowercase
73          parse-default parse-newline parse-blank
74          parse-blanks+ parse-blanks parse-between parse-esc
75          parse-strip-blanks parse-blanks-seq parse-line parse-alist
76          parse-with-context parse-regex-lit* parse-regex-lit)
77
78  (include "parse/repl.scm"
79           "parse/parse.scm"
80           "parse/util.scm"))