source: project/release/5/check-errors/trunk/type-errors-basic.impl.scm @ 36569

Last change on this file since 36569 was 36569, checked in by kon, 3 months ago

remove article stuff

File size: 3.7 KB
Line 
1;;;; type-errors-basic.impl.scm  -*- Scheme -*-
2;;;; Kon Lovett, Jul '18
3
4;; Issues
5;;
6;; - The type error message is built so as to look like those of the Chicken
7;; "core". This constraint necessarily means some knowledge of the use of the
8;; indefinite article. So any I18N effort will either have some logic needed or
9;; a change to the Chicken "core" form.
10;;
11;; Maybe "... not an integer" -> "... integer required" &
12;; "... not a list" -> "... list required".
13
14(import scheme)
15
16;;;
17
18;;
19
20(define (->boolean x) (and x #t))
21
22;;;
23
24;;
25
26(define (make-bad-argument-message #!optional argnam)
27  (if (not argnam)
28    "bad argument"
29    (conc "bad " #\` argnam #\' " argument") ) )
30
31(define (make-type-name-message typnam)
32  (->string typnam) )
33
34(define (make-error-type-message typnam #!optional argnam)
35  (string-append
36    (make-bad-argument-message argnam)
37    " type - not "
38    (make-type-name-message typnam)) )
39
40;;
41
42(define (signal-bounds-error loc . objs)
43  (apply ##sys#signal-hook #:bounds-error loc objs) )
44
45(define (signal-type-error loc . objs)
46  (apply ##sys#signal-hook #:type-error loc objs) )
47
48;;
49
50(define (error-argument-type loc obj typnam #!optional argnam)
51  (signal-type-error loc (make-error-type-message typnam argnam) obj) )
52
53;;
54
55(define (warning-argument-type loc obj typnam #!optional argnam)
56  (let* (
57    (typmsg (make-error-type-message typnam argnam))
58    (locmsg (if loc (string-append (location-message loc) " ") ""))
59    (wrn-msg (conc locmsg typmsg ": " obj)) )
60    (warning wrn-msg) ) )
61
62(define (location-message loc)
63  (conc #\( loc #\)) )
64
65;;
66
67; <symbol>          : <typnam> is "<symbol>"
68; <symbol> <string> : <typnam> is <string>
69; ->
70; (define (error-<symbol> loc obj #!optional argnam)
71;   (error-argument-type loc obj <typnam> argnam) )
72
73(define-syntax define-error-type
74  (er-macro-transformer
75    (lambda (frm rnm cmp)
76      (let (
77        (_define (rnm 'define))
78        (_#!optional (rnm '#!optional))
79        (_error-argument-type (rnm 'error-argument-type)) )
80        (let* (
81          (typ (cadr frm))
82          (typstr (symbol->string typ))
83          (typnam (if (null? (cddr frm)) typstr (caddr frm)))
84          (nam (string->symbol (string-append "error-" typstr))) )
85          `(,_define (,nam loc obj ,_#!optional argnam)
86             (,_error-argument-type loc obj ,typnam argnam) ) ) ) ) ) )
87
88;;
89
90(define (error-bound-value loc obj tag #!optional argnam)
91        (error-argument-type loc "#<unbound>" "bound-value" argnam) )
92
93(define (error-defined-value loc obj tag #!optional argnam)
94        (error-argument-type loc "#<unspecified>" "defined-value" argnam) )
95
96(define (error-minimum-argument-count loc argc minargc)
97  (##sys#signal-hook #:arity-error loc
98    (conc "too few arguments - received " argc " but expected " minargc))
99  #; ;int & foreign-value unrecognized, & foreign is imported
100  (##sys#error-hook
101    (foreign-value "C_BAD_MINIMUM_ARGUMENT_COUNT_ERROR" int)
102    loc
103    minargc argc #f) )
104
105(define (error-argument-count loc argc maxargc)
106  (##sys#signal-hook #:arity-error loc
107    (conc "bad argument count - received " argc " but expected " maxargc))
108  #; ;int & foreign-value unrecognized, & foreign is imported
109  (##sys#error-hook
110    (foreign-value "C_BAD_ARGUMENT_COUNT_ERROR" int)
111    loc
112    maxargc argc #f) )
113
114;;;
115
116#|
117;;
118
119(define (localized-type-name-message typnam)
120  ;FIXME en only
121  (conc (appropriate-indefinite-article typnam) " " typnam) )
122
123;;
124
125(define +english-vowels+ '(#\a #\e #\i #\o #\u))
126(define +english-indefinite-articles+ '(an a))
127
128(define (vowel? ch)
129  (->boolean (memq ch +english-vowels+)) )
130
131(define (appropriate-indefinite-article wrd)
132  (let ((s (->string wrd)))
133    (if (vowel? (string-ref s 0))
134      (car +english-indefinite-articles+)
135      (cadr +english-indefinite-articles+) ) ) )
136|#
Note: See TracBrowser for help on using the repository browser.