source: project/release/5/slib-prec/trunk/slib-prec-grammar.scm @ 38563

Last change on this file since 38563 was 38563, checked in by Kon Lovett, 6 months ago

use slib prec include, use slib simetrix, combine *-setups

File size: 2.2 KB
Line 
1;;;; slib-prec-grammar.scm  -*- Scheme -*-
2;;;; Kon Lovett, Apr '20
3;;;; Kon Lovett, Apr '18
4
5(module slib-prec-grammar
6
7(;export
8  ;
9  *input-grammar*
10  *output-grammar*
11  *echo-grammar*
12  active-grammar-set!
13  read-syntax-setup!
14  ;
15  make-grammar
16  grammar?
17  grammar-name
18  grammar-reader
19  grammar-read-tab
20  grammar-writer
21  grammar-write-tab
22  ;
23  grammar-id-name-set!
24  grammar-id-name
25  list-of-grammar-ids
26  count-of-grammar-ids
27  clear-grammar-ids
28  grammar-id-name-setup!
29  ;
30  defgrammar
31  get-grammar
32  list-of-grammars
33  count-of-grammars
34  get-grammar/id
35  clear-grammars
36  ;
37  read-sexp
38  write-sexp
39  print-using-grammar
40  flush-input-whitespace)
41
42(import scheme)
43(import (chicken base))
44(import (chicken type))
45(import slib-prec)
46
47;;;
48
49(define mod modulo)
50
51(include "slib-compat")
52(include "slib-grammar")
53(include "output-grammars")
54(include "input-grammars")
55
56(defgrammar 'null
57  (make-grammar
58    'null
59                (lambda (grm) (math:error 'cannot-read-null-grammar))
60                #f
61                (lambda (sexp grm) #t)
62                #f))
63
64(defgrammar 'scheme
65  (make-grammar
66    'scheme
67                (lambda (grm) (read))
68                #f
69                (lambda (sexp grm) (write sexp) (force-output))
70                #f))
71
72;;; Establish autoload for PRETTY-PRINT.
73(defgrammar 'schemepretty
74  (make-grammar
75    'schemepretty
76    (lambda (grm)
77      (read) )
78    #f
79    (lambda (sexp grm)
80      (import (chicken pretty-print))
81      (pretty-print sexp)
82      (force-output) )
83    #f))
84
85(define (active-grammar-set! input output #!optional (echo 'null))
86  (set! *input-grammar* (get-grammar input))
87  (set! *output-grammar* output)
88  (set! *echo-grammar* echo) )
89
90;;
91
92(define (read-syntax-setup!)
93  (import (only (chicken base) parentheses-synonyms))
94  (import (only (chicken read-syntax) set-sharp-read-syntax! set-parameterized-read-syntax!))
95  (parentheses-synonyms #f)
96  (set-sharp-read-syntax! #\{
97    (lambda (port)
98      (read-sexp/delim (get-grammar/id 0) #\} port)))
99  (set-parameterized-read-syntax! #\{
100    (lambda (port id)
101      (read-sexp/delim (get-grammar/id id) #\} port))) )
102
103;;
104
105;init by id-# grammar lookup
106(define-constant DEFAULT-GRAMMARS '(
107  standard disp2d tex
108  null scheme schemepretty))
109(grammar-id-name-setup! DEFAULT-GRAMMARS)
110
111) ;slib-prec-grammar
Note: See TracBrowser for help on using the repository browser.