|
169 | 169 | (lookup-binding bnds 'modeless-prem-names) ...)
|
170 | 170 | body)))))
|
171 | 171 |
|
| 172 | + (define (get-id-depths ids) |
| 173 | + (define ht (make-hash)) |
| 174 | + (for ([id (in-list (syntax->list ids))]) |
| 175 | + (define-values (sym depth) (get-id-depth id)) |
| 176 | + (hash-set! ht sym depth)) |
| 177 | + ht) |
| 178 | + (define (get-id-depth stx) |
| 179 | + (let loop ([stx stx] |
| 180 | + [n 0]) |
| 181 | + (syntax-case stx () |
| 182 | + [(more ell) |
| 183 | + (is-ellipsis? #'ell) |
| 184 | + (loop #'more (+ n 1))] |
| 185 | + [_ (values (syntax-e stx) n)]))) |
| 186 | + (define premise-id-depths (get-id-depths #'(modeless-prem-names/ellipses ...))) |
| 187 | + (define conc-id-depths (get-id-depths #'(conc-names/ellipses ...))) |
| 188 | + (define (get-ids-to-dup our-id-depths others-id-depths) |
| 189 | + (for/list ([(id depth) (in-hash our-id-depths)] |
| 190 | + #:when (< depth |
| 191 | + (hash-ref others-id-depths id -inf.0))) |
| 192 | + id)) |
| 193 | + |
172 | 194 | #`(begin
|
173 | 195 | conc-syncheck-exp
|
174 | 196 | modeless-jf-name-only-prems-syncheck-exp
|
175 | 197 | modeless-prems-syncheck-exp
|
176 | 198 | (build-modeless-jf-clause
|
177 | 199 | lang
|
178 | 200 | `conc
|
| 201 | + '(#,@(get-ids-to-dup conc-id-depths premise-id-depths)) |
179 | 202 | `modeless-prem
|
| 203 | + '(#,@(get-ids-to-dup premise-id-depths conc-id-depths)) |
180 | 204 | `modeless-jf-name-only-prem
|
181 | 205 | '(#,@premise-repeat-names)
|
182 | 206 | #,other-conditions
|
|
205 | 229 | (list)
|
206 | 230 | (list #`(cons #f (list #,@noname-clauses))))))))
|
207 | 231 |
|
208 |
| -(define (build-modeless-jf-clause lang conc modeless-prem modeless-jf-name-only-prem |
| 232 | +(define (build-modeless-jf-clause lang conc conc-ids-to-duplicate |
| 233 | + modeless-prem modeless-prem-ids-to-duplicate |
| 234 | + modeless-jf-name-only-prem |
209 | 235 | premise-repeat-names other-conditions funcs)
|
210 | 236 | (modeless-jf-clause (compile-pattern lang conc #f)
|
| 237 | + conc-ids-to-duplicate |
211 | 238 | (compile-pattern lang modeless-prem #f)
|
| 239 | + modeless-prem-ids-to-duplicate |
212 | 240 | (compile-pattern lang modeless-jf-name-only-prem #f)
|
213 | 241 | premise-repeat-names other-conditions funcs))
|
214 | 242 |
|
|
276 | 304 | (match candidates
|
277 | 305 | [`() (fail)]
|
278 | 306 | [(cons (modeless-jf-clause conclusion-compiled-pattern
|
| 307 | + conclusion-ids-to-duplicate |
279 | 308 | premises-compiled-pattern
|
| 309 | + premise-ids-to-duplicate |
280 | 310 | premises-jf-name-only-compiled-pattern
|
281 | 311 | premises-repeat-names
|
282 | 312 | other-conditions
|
|
297 | 327 | (cons (symbol->string (car t)) (cdr t))))
|
298 | 328 | (define sub-derivations-mtch (match-pattern premises-compiled-pattern
|
299 | 329 | sub-derivations-arguments-term-list))
|
| 330 | + (define sub-derivation-bindings (and sub-derivations-mtch |
| 331 | + (map mtch-bindings sub-derivations-mtch))) |
| 332 | + (define conc-bindings (map mtch-bindings conc-mtch)) |
300 | 333 | (define conc+sub-bindings
|
301 | 334 | (and sub-derivations-mtch
|
302 |
| - (combine-bindings-lists (map mtch-bindings conc-mtch) |
303 |
| - (map mtch-bindings sub-derivations-mtch) |
| 335 | + (combine-bindings-lists sub-derivation-bindings |
| 336 | + premise-ids-to-duplicate |
| 337 | + conc-bindings |
| 338 | + conclusion-ids-to-duplicate |
304 | 339 | (λ (a b) (alpha-equivalent? lang a b)))))
|
305 | 340 | (cond
|
306 | 341 | [conc+sub-bindings
|
|
332 | 367 | (fail-to-next-candidate)])]
|
333 | 368 | [else (fail-to-next-candidate)])]))
|
334 | 369 |
|
| 370 | + |
335 | 371 | (define (modeless-jf-process-other-conditions lang
|
336 | 372 | sub-derivations
|
337 | 373 | conc+sub-bindings
|
|
398 | 434 | [_ #f])]))])))
|
399 | 435 |
|
400 | 436 | (struct modeless-jf-clause (conclusion-compiled-pattern
|
| 437 | + conclusion-ids-to-duplicate |
401 | 438 |
|
402 | 439 | ;; pattern with all of the premises
|
403 | 440 | ;; strung together in a list, but where
|
404 | 441 | ;; the names of the judgment forms are
|
405 | 442 | ;; strings instead of symbols (so that they
|
406 | 443 | ;; don't accidentally run into non-terminals, etc)
|
407 | 444 | premises-compiled-pattern
|
| 445 | + premises-ids-to-duplicate |
408 | 446 |
|
409 | 447 | ;; pattern with all of the premises jf-names strung
|
410 | 448 | ;; together, but with `any` for all of the arguments
|
|
0 commit comments