Created
June 18, 2019 19:53
-
-
Save kmicinski/895e0bce13c73ab7ffc4e4499a268006 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[program ([toplevel-rule program] (void)) | |
([toplevel-fact program] (void)) | |
([toplevel-rule] (void)) | |
([toplevel-fact] (void))] | |
;; Rules | |
[rule ([lb hclause+ arrow bclause+ rb] | |
(wrap-prov | |
$1-start-pos | |
$5-end-pos | |
(λ () `(,@$2 ,$3 ,@$4))))] | |
[hclause ([lp prov-neq ihclause ihclause rp] | |
(wrap-prov $1-start-pos $5-end-pos (lambda () `(,$2 ,$3 ,$4)))) | |
([lp prov-eq ihclause ihclause rp] | |
(wrap-prov $1-start-pos $5-end-pos (lambda () `(,$2 ,$3 ,$4)))) | |
([lp prov-id ihclause+ rp] | |
(wrap-prov $1-start-pos $4-end-pos (lambda () `(,$2 ,@$3))))] | |
[ihclause ([qp prov-id iclause* rp] | |
(wrap-prov $1-start-pos $4-end-pos (lambda () `(,$2 ,@$3)))) | |
([lp prov-id ihclause* rp] | |
(wrap-prov $1-start-pos $4-end-pos (lambda () `(,$2 ,@$3)))) | |
([bval] $1)] | |
[bclause ([lp prov-neq iclause iclause rp] | |
(wrap-prov $1-start-pos $5-end-pos (lambda () `(,$2 ,$3 ,$4)))) | |
([lp prov-eq iclause iclause rp] | |
(wrap-prov $1-start-pos $5-end-pos (lambda () `(,$2 ,$3 ,$4)))) | |
([lp prov-id iclause+ rp] | |
(wrap-prov $1-start-pos $4-end-pos (lambda () `(,$2 ,@$3))))] | |
[iclause ([lp prov-id iclause+ rp] | |
(wrap-prov $1-start-pos $4-end-pos (lambda () `(,$2 ,@$3)))) | |
([bval] $1)] | |
[bval ([prov-lit] $1) | |
([prov-id] $1)] | |
;;([prov-id dots] `(dots ,$1))] | |
;; Facts | |
[fact ([lp id fact-or-lits rp] | |
`(,$2 ,@$3))] | |
[fact-or-lits ([fact fact-or-lits] (cons $1 $2)) | |
([lit fact-or-lits] (cons $1 $2)) | |
([fact] (list $1)) | |
([lit] (list $1))] | |
;; The arrows | |
[arrow ([larr] (mk-prov $1 $1-start-pos $1-end-pos)) | |
([rarr] (mk-prov $1 $1-start-pos $1-end-pos))] | |
;; Literals | |
[lit ;;([str] $1) | |
([string] $1) | |
([integer] $1)] | |
;; Helpers | |
[hclause+ ([hclause hclause+] (cons $1 $2)) | |
([hclause] (list $1))] | |
[iclause+ ([iclause iclause+] (cons $1 $2)) | |
([iclause] (list $1))] | |
[ihclause+ ([ihclause ihclause+] (cons $1 $2)) | |
([ihclause] (list $1))] | |
[bclause+ ([bclause bclause+] (cons $1 $2)) | |
([bclause] (list $1))] | |
[hclause* ([hclause hclause+] (cons $1 $2)) | |
([] '())] | |
[iclause* ([iclause iclause+] (cons $1 $2)) | |
([] '())] | |
[ihclause* ([ihclause ihclause+] (cons $1 $2)) | |
([] '())] | |
[bclause* ([bclause bclause+] (cons $1 $2)) | |
([] '())] | |
;; Wrappers around other nonterminals that wrap them w/ prov info | |
[prov-eq ([eq] (mk-prov $1 $1-start-pos $1-end-pos))] | |
[prov-neq ([neq] (mk-prov $1 $1-start-pos $1-end-pos))] | |
[prov-id ([id] (mk-prov $1 $1-start-pos $1-end-pos))] | |
[prov-lit ([lit] (mk-prov $1 $1-start-pos $1-end-pos))] | |
;; The toplevel rules wrap their underlying rules and then | |
;; install the proper entries in the rules hash. | |
[toplevel-rule ([rule] | |
(let ([k (new-rule-key)]) | |
(hash-set! rules k $1)))] | |
[toplevel-fact ([fact] (set! facts (cons $1 facts)))]))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment