|
77 | 77 | (define path (loop neighbor))
|
78 | 78 | (and path (cons node path)))]))))
|
79 | 79 |
|
80 |
| - (define full-path (cons cycle bad-path)) |
81 |
| - (define all/backwards (for/list ([nt (in-list (reverse bad-path))]) |
82 |
| - (define stx-lst (hash-ref nt-identifiers nt)) |
83 |
| - (define lst (if (syntax? stx-lst) (syntax->list stx-lst) stx-lst)) |
84 |
| - (define stx (car lst)) |
85 |
| - (datum->syntax stx nt stx))) |
| 80 | + (define bad-path/stx-objects |
| 81 | + (for/list ([nt (in-list bad-path)]) |
| 82 | + (define stx-lst (hash-ref nt-identifiers nt)) |
| 83 | + (define lst (if (syntax? stx-lst) (syntax->list stx-lst) stx-lst)) |
| 84 | + (define stx (car lst)) |
| 85 | + (datum->syntax stx nt stx))) |
| 86 | + |
| 87 | + (define bad-path-starting-point |
| 88 | + (for/fold ([smallest (car bad-path/stx-objects)]) |
| 89 | + ([point (in-list (cdr bad-path/stx-objects))]) |
| 90 | + (define smaller? |
| 91 | + (< (or (syntax-position smallest) +inf.0) |
| 92 | + (or (syntax-position point) +inf.0))) |
| 93 | + (if smaller? |
| 94 | + smallest |
| 95 | + point))) |
| 96 | + (define bad-path-in-canonical-order |
| 97 | + (let loop ([bad-path bad-path/stx-objects]) |
| 98 | + (cond |
| 99 | + [(equal? bad-path-starting-point (car bad-path)) |
| 100 | + bad-path] |
| 101 | + [else |
| 102 | + (loop (append (cdr bad-path) (list (car bad-path))))]))) |
| 103 | + (define full-path (cons (car (reverse bad-path-in-canonical-order)) |
| 104 | + bad-path-in-canonical-order)) |
86 | 105 | (raise-syntax-error 'define-language
|
87 |
| - (if (= 1 (length bad-path)) |
| 106 | + (if (= 1 (length bad-path-in-canonical-order)) |
88 | 107 | (format "the non-terminal ~a is defined in terms of itself"
|
89 |
| - (car bad-path)) |
| 108 | + (syntax-e (car bad-path-in-canonical-order))) |
90 | 109 | (format
|
91 | 110 | "found a cycle of non-terminals that doesn't consume input:~a"
|
92 | 111 | (apply
|
93 | 112 | string-append
|
94 |
| - (for/list ([node (in-list full-path)]) |
95 |
| - (format " ~a" node))))) |
| 113 | + (for/list ([node (in-list bad-path-in-canonical-order)]) |
| 114 | + (format " ~a" (syntax-e node)))))) |
96 | 115 | stx
|
97 |
| - (car all/backwards) |
98 |
| - (cdr all/backwards)))) |
| 116 | + (car bad-path-in-canonical-order) |
| 117 | + (cdr bad-path-in-canonical-order)))) |
0 commit comments