2
; Copyright (C) 2014 Kookamara LLC
7
; 11410 Windermere Meadows
8
; Austin, TX 78759, USA
9
; http://www.kookamara.com/
11
; License: (An MIT/X11-style license)
13
; Permission is hereby granted, free of charge, to any person obtaining a
14
; copy of this software and associated documentation files (the "Software"),
15
; to deal in the Software without restriction, including without limitation
16
; the rights to use, copy, modify, merge, publish, distribute, sublicense,
17
; and/or sell copies of the Software, and to permit persons to whom the
18
; Software is furnished to do so, subject to the following conditions:
20
; The above copyright notice and this permission notice shall be included in
21
; all copies or substantial portions of the Software.
23
; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
24
; IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25
; FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
26
; AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27
; LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
28
; FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
29
; DEALINGS IN THE SOFTWARE.
31
; Original author: Jared Davis <jared@kookamara.com>
33
(in-package "SIDEKICK")
35
(include-book "xdoc/save" :dir :system)
39
(define props-jalist-aux (alist (config str::printconfig-p))
40
(b* (((when (atom alist))
42
((cons key val) (car alist)))
43
(cons (cons key (str::pretty val :config config))
44
(props-jalist-aux (cdr alist) config))))
46
(define props-jalist (name state)
47
(b* (((unless (symbolp name))
50
(alist (getprops name 'acl2::current-acl2-world world))
51
(pkg (current-package state))
52
(config (str::make-printconfig :home-package (pkg-witness pkg)
56
(pretty-printed-alist (props-jalist-aux alist config)))
57
pretty-printed-alist))
59
(define sk-get-props ((name stringp) state)
60
:returns (mv json-props state)
61
(b* (((mv errmsg objs state) (acl2::read-string name))
63
(mv (sk-json-error "Error in props: parsing failed: ~a: ~a" name errmsg)
65
((unless (and (equal (len objs) 1)
66
(symbolp (car objs))))
67
(mv (sk-json-error "Error in props: not a symbol: ~a" name)
69
(props (props-jalist (car objs) state)))
70
(mv (bridge::json-encode
71
(list (cons :error nil)
75
(define sk-get-origin ((name stringp) state)
76
:returns (mv json-props state)
77
(b* (((mv errmsg objs state) (acl2::read-string name))
79
(mv (sk-json-error "Error in origin: parsing failed: ~a: ~a~%" name errmsg)
81
((unless (and (equal (len objs) 1)
82
(symbolp (car objs))))
83
(mv (sk-json-error "Error in origin: not a symbol: ~a~%" name)
86
(acl2::origin-fn (car objs) state)))
87
(mv (bridge::json-encode (list (cons :error nil)
91
(defun json-xdoc-topic (name state)
92
(b* (((mv topics state) (xdoc::all-xdoc-topics state))
93
(topics-fal (xdoc::topics-fal topics))
94
(topic (cdr (hons-get name topics-fal)))
96
(mv (sk-json-error "No xdoc for topic ~a~%" name)
98
((mv short-str state) (xdoc::short-xml-for-topic topic topics-fal state))
99
((mv long-str state) (xdoc::long-xml-for-topic topic topics-fal state)))
100
(mv (bridge::json-encode
101
(list (cons :error nil)
102
(cons :short short-str)
103
(cons :long long-str)))
106
(define sk-get-xdoc ((name stringp) state)
107
:returns (mv json-props state)
108
(b* (((mv errmsg objs state) (acl2::read-string name))
110
(mv (sk-json-error "Error in origin: parsing failed: ~a: ~a~%" name errmsg)
112
((unless (and (equal (len objs) 1)
113
(symbolp (car objs))))
114
(mv (sk-json-error "Error in origin: not a symbol: ~a~%" name)
116
((mv out state) (json-xdoc-topic (car objs) state)))