-
-
Notifications
You must be signed in to change notification settings - Fork 648
/
syntax-implicit-error.rkt
39 lines (37 loc) · 1.61 KB
/
syntax-implicit-error.rkt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#lang racket/base
(require "../syntax/error.rkt"
"../syntax/scope.rkt"
"context.rkt"
"syntax-id-error.rkt")
(provide raise-syntax-implicit-error)
(define (raise-syntax-implicit-error s sym trigger-id ctx)
(define phase (expand-context-phase ctx))
(define what
(case sym
[(#%app) "function application"]
[(#%datum) "literal data"]
[(#%top)
(if (expand-context-allow-unbound? ctx)
"reference to a top-level identifier"
"reference to an unbound identifier")]))
(define unbound? (and trigger-id (not (resolve trigger-id phase))))
(define unbound-form (and unbound?
(not (eq? (syntax-e s) (syntax-e trigger-id)))
s))
(raise-syntax-error #f
(format (if unbound?
"unbound identifier;\n also, no ~a syntax transformer is bound~a"
(string-append what " is not allowed;\n no ~a syntax transformer is bound~a"))
sym
(case phase
[(0) ""]
[(1) " in the transformer phase"]
[else (format " at phase ~a" phase)]))
(and unbound?
(or unbound-form
trigger-id))
(if unbound?
(and unbound-form trigger-id)
s)
null
(if unbound? (syntax-debug-info-string trigger-id ctx) "")))