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

Last change on this file since 38716 was 38716, checked in by Kon Lovett, 4 months ago

split grammers, strict-types

File size: 1.9 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  active-grammar active-grammar-set!
10  active-input-grammar active-output-grammar active-echo-grammar
11  read-syntax-setup!
12  ;
13  make-grammar
14  grammar?
15  grammar-name
16  grammar-reader
17  grammar-read-tab
18  grammar-writer
19  grammar-write-tab
20  ;
21  grammar-id-name-set!
22  grammar-id-name
23  list-of-grammar-ids
24  count-of-grammar-ids
25  clear-grammar-ids
26  grammar-id-name-setup!
27  ;
28  defgrammar
29  get-grammar
30  list-of-grammars
31  count-of-grammars
32  get-grammar/id
33  clear-grammars
34  ;
35  make-delimited-parse-grammar-reader
36  read-sexp
37  write-sexp
38  print-using-grammar
39  flush-input-whitespace)
40
41(import scheme)
42(import (chicken base))
43(import (chicken type))
44(import slib-prec-parse)
45
46;;;
47
48(include "slib-compat")
49(include "slib-grammar")
50
51;;
52
53(define *input-grammar*)
54(define *output-grammar*)
55(define *echo-grammar*)
56
57(define (active-grammar-set! input output #!optional (echo 'null))
58  (set! *input-grammar* (get-grammar input))
59  (set! *output-grammar* output)
60  (set! *echo-grammar* echo) )
61
62(define (active-grammar)
63  (values *input-grammar* *output-grammar* *echo-grammar*) )
64
65(define (active-input-grammar) (receive (i o e) (active-grammar) i))
66(define (active-output-grammar) (receive (i o e) (active-grammar) o))
67(define (active-echo-grammar) (receive (i o e) (active-grammar) e))
68
69;;
70
71(define (read-syntax-setup!)
72  (import (only (chicken base) parentheses-synonyms))
73  (import (only (chicken read-syntax) set-sharp-read-syntax! set-parameterized-read-syntax!))
74  (set-sharp-read-syntax! #\{
75    (lambda (port)
76      (parameterize ((parentheses-synonyms #f))
77        (read-delimited-sexp port #\} (get-grammar/id 0) 0))))
78  (set-parameterized-read-syntax! #\{
79    (lambda (port id)
80      (parameterize ((parentheses-synonyms #f))
81        (read-delimited-sexp port #\} (get-grammar/id id) 0)))) )
82
83) ;slib-prec-grammar
Note: See TracBrowser for help on using the repository browser.