Utilities on gestalts and matchers useful for analyzing and transforming whole tables
This commit is contained in:
parent
5cce0db45f
commit
1fa2743751
|
@ -3,6 +3,7 @@
|
||||||
|
|
||||||
(require racket/set)
|
(require racket/set)
|
||||||
(require racket/match)
|
(require racket/match)
|
||||||
|
(require (only-in racket/list make-list))
|
||||||
(require (only-in racket/port with-output-to-string))
|
(require (only-in racket/port with-output-to-string))
|
||||||
|
|
||||||
(require "route.rkt")
|
(require "route.rkt")
|
||||||
|
@ -26,14 +27,17 @@
|
||||||
simple-gestalt
|
simple-gestalt
|
||||||
gestalt-empty
|
gestalt-empty
|
||||||
gestalt-empty?
|
gestalt-empty?
|
||||||
|
gestalt-full
|
||||||
gestalt-union*
|
gestalt-union*
|
||||||
gestalt-union
|
gestalt-union
|
||||||
gestalt-filter
|
gestalt-filter
|
||||||
gestalt-match
|
gestalt-match
|
||||||
gestalt-subtract
|
gestalt-subtract
|
||||||
gestalt-transform
|
gestalt-transform
|
||||||
|
gestalt-matcher-transform
|
||||||
strip-gestalt-label
|
strip-gestalt-label
|
||||||
label-gestalt
|
label-gestalt
|
||||||
|
gestalt-level-count
|
||||||
pretty-print-gestalt
|
pretty-print-gestalt
|
||||||
gestalt->pretty-string
|
gestalt->pretty-string
|
||||||
gestalt->jsexpr
|
gestalt->jsexpr
|
||||||
|
@ -226,6 +230,13 @@
|
||||||
(for*/and [(ml (in-list (gestalt-metalevels g))) (l (in-list ml))]
|
(for*/and [(ml (in-list (gestalt-metalevels g))) (l (in-list ml))]
|
||||||
(and (matcher-empty? (car l)) (matcher-empty? (cdr l)))))
|
(and (matcher-empty? (car l)) (matcher-empty? (cdr l)))))
|
||||||
|
|
||||||
|
;; Nat Nat -> GestaltSet
|
||||||
|
;; Produces a "full" gestalt including the wildcard matcher at each of
|
||||||
|
;; the n metalevels and m levels.
|
||||||
|
(define (gestalt-full n m)
|
||||||
|
(define w (pattern->matcher ?))
|
||||||
|
(gestalt (make-list n (make-list m (cons w w)))))
|
||||||
|
|
||||||
;; map-zip: ((U 'right-longer 'left-longer) (Listof X) -> (Listof Y))
|
;; map-zip: ((U 'right-longer 'left-longer) (Listof X) -> (Listof Y))
|
||||||
;; (X X -> Y)
|
;; (X X -> Y)
|
||||||
;; (Y (Listof Y) -> (Listof Y))
|
;; (Y (Listof Y) -> (Listof Y))
|
||||||
|
@ -400,6 +411,11 @@
|
||||||
(define pidset (set pid))
|
(define pidset (set pid))
|
||||||
(gestalt-matcher-transform g (lambda (m) (matcher-relabel m (lambda (v) pidset)))))
|
(gestalt-matcher-transform g (lambda (m) (matcher-relabel m (lambda (v) pidset)))))
|
||||||
|
|
||||||
|
;; Gestalt Nat -> Nat
|
||||||
|
;; Returns the number of "interesting" levels in g at metalevel n.
|
||||||
|
(define (gestalt-level-count g n)
|
||||||
|
(length (gestalt-metalevel-ref g n)))
|
||||||
|
|
||||||
;; Gestalt [OutputPort] -> Void
|
;; Gestalt [OutputPort] -> Void
|
||||||
;; Pretty-prints g on port.
|
;; Pretty-prints g on port.
|
||||||
(define (pretty-print-gestalt g [port (current-output-port)])
|
(define (pretty-print-gestalt g [port (current-output-port)])
|
||||||
|
|
|
@ -15,6 +15,7 @@
|
||||||
wildcard?
|
wildcard?
|
||||||
?!
|
?!
|
||||||
(struct-out capture)
|
(struct-out capture)
|
||||||
|
(struct-out embedded-matcher)
|
||||||
|
|
||||||
matcher? ;; expensive; see implementation
|
matcher? ;; expensive; see implementation
|
||||||
matcher-empty
|
matcher-empty
|
||||||
|
|
Loading…
Reference in New Issue