Fixed some bugs with the encoding of paths
This commit is contained in:
parent
359c22cb8c
commit
a0d682cb6c
9
dot-lang.rkt
Normal file
9
dot-lang.rkt
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
#lang typed/racket
|
||||||
|
|
||||||
|
(provide dot λdot)
|
||||||
|
|
||||||
|
(define-syntax (dot stx)
|
||||||
|
(raise-syntax-error 'dot "Dot is not implemented yet" stx))
|
||||||
|
|
||||||
|
(define-syntax (λdot stx)
|
||||||
|
(raise-syntax-error 'dot "Dot is not implemented yet" stx))
|
|
@ -413,15 +413,16 @@ making a union of all paths, without factoring out common parts.
|
||||||
(datum->syntax #'d '|.| #'d #'d)))
|
(datum->syntax #'d '|.| #'d #'d)))
|
||||||
(pattern ({~and d λdot} e …)
|
(pattern ({~and d λdot} e …)
|
||||||
#:with full
|
#:with full
|
||||||
(cons #'d (add-between (syntax->list #'(e …))
|
(cons (datum->syntax #'d '|.| #'d #'d)
|
||||||
(datum->syntax #'d '|.| #'d #'d)))))
|
(add-between (syntax->list #'(e …))
|
||||||
|
(datum->syntax #'d '|.| #'d #'d)))))
|
||||||
(define-syntax ~dot-ish
|
(define-syntax ~dot-ish
|
||||||
(pattern-expander
|
(pattern-expander
|
||||||
(λ (stx)
|
(λ (stx)
|
||||||
(syntax-case stx ()
|
(syntax-case stx ()
|
||||||
[(_ pat …)
|
[(_ pat …)
|
||||||
#'(~and x:dot-ish
|
#'(~and x:dot-ish
|
||||||
(~parse (pat …) #'x))]))))
|
(~parse (pat …) #'x.full))]))))
|
||||||
|
|
||||||
(define (match-id rx id)
|
(define (match-id rx id)
|
||||||
(let ([m (regexp-match rx (identifier→string id))])
|
(let ([m (regexp-match rx (identifier→string id))])
|
||||||
|
@ -444,16 +445,14 @@ making a union of all paths, without factoring out common parts.
|
||||||
#:attributes (τ)
|
#:attributes (τ)
|
||||||
(pattern {~rx-id #px"^:([^:]+)$" τ}))
|
(pattern {~rx-id #px"^:([^:]+)$" τ}))
|
||||||
(define-syntax-class π-elements
|
(define-syntax-class π-elements
|
||||||
#:literals (|.| *)
|
#:datum-literals (|.|)
|
||||||
|
#:attributes ([f 1] [τ 1])
|
||||||
|
(pattern (~dot-ish {~seq |.| :f+τ} …)))
|
||||||
|
(define-syntax-class sub-elements
|
||||||
|
#:literals (*) #:datum-literals (|.|)
|
||||||
|
#:attributes ([f 2] [τ 2] [sub 1])
|
||||||
(pattern
|
(pattern
|
||||||
(~dot-ish {~or {~seq |.| :f+τ} {~seq sub:π-elements *}} …)))
|
({~either :π-elements {~seq sub:sub-elements *}} …))))]
|
||||||
(define-syntax-class whole-π
|
|
||||||
#:literals (|.| *)
|
|
||||||
#:attributes ([f 1] [τ 1] [τ₀ 0])
|
|
||||||
(pattern
|
|
||||||
(~dot-ish {~optional fst:just-τ}
|
|
||||||
{~or {~seq |.| :f+τ} {~seq sub:π-elements *}} …)
|
|
||||||
#:with τ₀ #'fst.τ)))]
|
|
||||||
|
|
||||||
@chunk[<parse>
|
@chunk[<parse>
|
||||||
(define-type-expander (<~τ stx)
|
(define-type-expander (<~τ stx)
|
||||||
|
@ -462,27 +461,35 @@ making a union of all paths, without factoring out common parts.
|
||||||
[(_ f₀ . more)
|
[(_ f₀ . more)
|
||||||
#'(f₀ (<~τ . more))]))
|
#'(f₀ (<~τ . more))]))
|
||||||
(begin-for-syntax
|
(begin-for-syntax
|
||||||
(define-template-metafunction (generate-sub-π stx)
|
(define-template-metafunction generate-sub-π
|
||||||
(syntax-parser
|
(syntax-parser
|
||||||
[(_ :π-elements after)
|
[(_ :sub-elements after)
|
||||||
(template
|
(template
|
||||||
(Rec R
|
(Rec R
|
||||||
(U (<~τ (?? (∀ (more) (generate-sub-π sub more))
|
(U (<~τ (?? (∀ (more) (generate-sub-π sub more))
|
||||||
(∀ (more) (List* (Pairof (?? f AnyField)
|
(∀ (more) (List* (Pairof (?? 'f AnyField)
|
||||||
(?? τ AnyType))
|
(?? τ AnyType))
|
||||||
|
…
|
||||||
more)))
|
more)))
|
||||||
…
|
…
|
||||||
R)
|
R)
|
||||||
after)))])))
|
after)))])))
|
||||||
(define-for-syntax parse-path
|
(define-for-syntax parse-path
|
||||||
(syntax-parser
|
(syntax-parser
|
||||||
[:whole-π
|
[({~optional (~dot-ish fst-τ:just-τ {~seq |.| fst:f+τ} …)}
|
||||||
(template (Rec R (U (Pairof Any R) <π>)))]))]
|
. :sub-elements)
|
||||||
|
(template (Rec R (U (Pairof Any R)
|
||||||
|
(List* (?? (?@ (Pairof AnyField fst-τ.τ)
|
||||||
|
(Pairof (?? 'fst.f AnyField)
|
||||||
|
(?? fst.τ AnyType))
|
||||||
|
…))
|
||||||
|
<π>))))]))]
|
||||||
|
|
||||||
@chunk[<π>
|
@chunk[<π>
|
||||||
(<~τ (?? (∀ (more) (List* (Pairof AnyField τ₀) more)))
|
(<~τ (?? (∀ (more) (generate-sub-π sub more))
|
||||||
(?? (∀ (more) (generate-sub-π sub more))
|
(∀ (more) (List* (Pairof (?? 'f AnyField) (?? τ AnyType))
|
||||||
(∀ (more) (List* (Pairof (?? f AnyField) (?? τ AnyType)) more)))
|
…
|
||||||
|
more)))
|
||||||
…
|
…
|
||||||
Null)]
|
Null)]
|
||||||
|
|
||||||
|
@ -592,7 +599,8 @@ Two sorts of paths inside (in)equality constraints:
|
||||||
syntax/parse/experimental/template)
|
syntax/parse/experimental/template)
|
||||||
(for-meta 2 racket/base)
|
(for-meta 2 racket/base)
|
||||||
(for-meta 2 phc-toolkit/untyped/aliases)
|
(for-meta 2 phc-toolkit/untyped/aliases)
|
||||||
(for-meta 3 racket/base))
|
(for-meta 3 racket/base)
|
||||||
|
"dot-lang.rkt")
|
||||||
|
|
||||||
;; For testing:
|
;; For testing:
|
||||||
(provide Invariants
|
(provide Invariants
|
||||||
|
@ -603,7 +611,8 @@ Two sorts of paths inside (in)equality constraints:
|
||||||
Target
|
Target
|
||||||
NonTarget
|
NonTarget
|
||||||
ε
|
ε
|
||||||
witness-value)
|
witness-value
|
||||||
|
(for-syntax parse-path))
|
||||||
|
|
||||||
<parse>
|
<parse>
|
||||||
|
|
||||||
|
|
|
@ -2,8 +2,21 @@
|
||||||
|
|
||||||
(require (lib "phc-graph/invariants-phantom.hl.rkt")
|
(require (lib "phc-graph/invariants-phantom.hl.rkt")
|
||||||
"util.rkt"
|
"util.rkt"
|
||||||
|
phc-graph/dot-lang
|
||||||
phc-toolkit)
|
phc-toolkit)
|
||||||
|
|
||||||
|
(define-type-expander (Π stx)
|
||||||
|
(syntax-case stx ()
|
||||||
|
[(_ . π)
|
||||||
|
(parse-path #'π)]))
|
||||||
|
(eval #'(#%top-interaction . (:type (Π (λdot a aa) ((λdot b c))* (λdot d e))))
|
||||||
|
(variable-reference->namespace (#%variable-reference)))
|
||||||
|
(struct a ()); the field.
|
||||||
|
(eval #'(#%top-interaction . (:type (Π (dot :a aa) ((λdot b c))* (λdot d e))))
|
||||||
|
(variable-reference->namespace (#%variable-reference)))
|
||||||
|
(eval #'(#%top-interaction . (:type (Π (dot :a) ((λdot b c))* (λdot d e))))
|
||||||
|
(variable-reference->namespace (#%variable-reference)))
|
||||||
|
|
||||||
#|
|
#|
|
||||||
|
|
||||||
(check-ann witness-value (Invariants)) ;; No invariants
|
(check-ann witness-value (Invariants)) ;; No invariants
|
||||||
|
|
Loading…
Reference in New Issue
Block a user