maude: run.sx search command + result-sort output (254 total)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 36s
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 36s
run.sx now handles 'search START =>* GOAL .' (reports the witness path) and mau/run-pretty prints Maude-style 'result SORT: TERM' using least-sort inference. searchpath.sx exposes mau/search-path-terms (term-level entry). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -4,8 +4,13 @@
|
||||
;; executes them, Maude-style:
|
||||
;; reduce TERM . (alias: red) — normalise with equations
|
||||
;; rewrite TERM . (alias: rew) — apply rules under the default strategy
|
||||
;; search START =>* GOAL . — reachability (=>*, =>+, =>! all treated
|
||||
;; as reachability); reports the path
|
||||
;; `... in MODNAME : TERM .` is accepted (the module qualifier is ignored —
|
||||
;; there is one module in scope). Results are rendered in mixfix surface syntax.
|
||||
;; there is one module in scope). reduce/rewrite results carry the least sort,
|
||||
;; rendered Maude-style by mau/run-pretty as `result SORT: TERM`.
|
||||
|
||||
(define mau/search-depth 200)
|
||||
|
||||
(define
|
||||
mau/module-end-idx
|
||||
@@ -27,7 +32,6 @@
|
||||
name
|
||||
(mau/take (mau/drop toks 3) (- (len toks) 4))))))
|
||||
|
||||
;; strip an optional `in MODNAME :` qualifier from a command's term tokens
|
||||
(define
|
||||
mau/strip-in
|
||||
(fn
|
||||
@@ -37,18 +41,49 @@
|
||||
(rest (mau/drop-until toks ":"))
|
||||
toks)))
|
||||
|
||||
(define
|
||||
mau/find-arrow
|
||||
(fn
|
||||
(toks)
|
||||
(cond
|
||||
((empty? toks) nil)
|
||||
((and (>= (len (first toks)) 2) (= (slice (first toks) 0 2) "=>"))
|
||||
(first toks))
|
||||
(else (mau/find-arrow (rest toks))))))
|
||||
|
||||
(define
|
||||
mau/run-search
|
||||
(fn
|
||||
(m term-toks)
|
||||
(let
|
||||
((arrow (mau/find-arrow term-toks)) (g (mau/module-grammar m)))
|
||||
(if
|
||||
(= arrow nil)
|
||||
{:path nil :cmd "search" :result "no arrow"}
|
||||
(let
|
||||
((start-toks (mau/take-until term-toks arrow))
|
||||
(goal-toks (rest (mau/drop-until term-toks arrow))))
|
||||
(let
|
||||
((path (mau/search-path-terms m (mau/parse-term start-toks g) (mau/parse-term goal-toks g) mau/search-depth)))
|
||||
{:path path :cmd "search" :result (if (= path nil) "no solution" (join " => " path))}))))))
|
||||
|
||||
(define
|
||||
mau/run-command
|
||||
(fn
|
||||
(m stmt)
|
||||
(let
|
||||
((head (first stmt)) (term-toks (mau/strip-in (rest stmt))))
|
||||
(let
|
||||
((t (mau/parse-term term-toks (mau/module-grammar m))))
|
||||
(cond
|
||||
((or (= head "reduce") (= head "red")) {:cmd "reduce" :result (mau/term->maude m (mau/creduce m t))})
|
||||
((or (= head "rewrite") (= head "rew")) {:cmd "rewrite" :result (mau/term->maude m (mau/rewrite m t))})
|
||||
(else {:cmd head :result "?"}))))))
|
||||
((head (first stmt)))
|
||||
(if
|
||||
(or (= head "search") (= head "srch"))
|
||||
(mau/run-search m (rest stmt))
|
||||
(let
|
||||
((t (mau/parse-term (mau/strip-in (rest stmt)) (mau/module-grammar m))))
|
||||
(cond
|
||||
((or (= head "reduce") (= head "red"))
|
||||
(let ((r (mau/creduce m t))) {:cmd "reduce" :sort (mau/term-sort m r) :result (mau/term->maude m r)}))
|
||||
((or (= head "rewrite") (= head "rew"))
|
||||
(let ((r (mau/rewrite m t))) {:cmd "rewrite" :sort (mau/term-sort m r) :result (mau/term->maude m r)}))
|
||||
(else {:cmd head :result "?"})))))))
|
||||
|
||||
(define
|
||||
mau/run-commands
|
||||
@@ -77,7 +112,21 @@
|
||||
(cmd-toks (mau/drop toks (+ eidx 1))))
|
||||
(mau/run-commands m (mau/split-statements cmd-toks)))))))
|
||||
|
||||
;; convenience: just the rendered result strings
|
||||
;; just the rendered result strings
|
||||
(define
|
||||
mau/run
|
||||
(fn (src) (map (fn (r) (get r :result)) (mau/run-program src))))
|
||||
|
||||
;; Maude-style printout: `result SORT: TERM` for reduce/rewrite, the path for search
|
||||
(define
|
||||
mau/run-pretty
|
||||
(fn
|
||||
(src)
|
||||
(map
|
||||
(fn
|
||||
(r)
|
||||
(if
|
||||
(= (get r :cmd) "search")
|
||||
(str "search: " (get r :result))
|
||||
(str "result " (get r :sort) ": " (get r :result))))
|
||||
(mau/run-program src))))
|
||||
|
||||
Reference in New Issue
Block a user