~ubuntu-branches/ubuntu/wily/acl2/wily

« back to all changes in this revision

Viewing changes to books/projects/sidekick/lookup.lisp

  • Committer: Package Import Robot
  • Author(s): Camm Maguire
  • Date: 2015-01-16 10:35:45 UTC
  • mfrom: (3.3.26 sid)
  • Revision ID: package-import@ubuntu.com-20150116103545-prehe9thgo79o8w8
Tags: 7.0-1
New upstream release

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
; ACL2 Sidekick
 
2
; Copyright (C) 2014 Kookamara LLC
 
3
;
 
4
; Contact:
 
5
;
 
6
;   Kookamara LLC
 
7
;   11410 Windermere Meadows
 
8
;   Austin, TX 78759, USA
 
9
;   http://www.kookamara.com/
 
10
;
 
11
; License: (An MIT/X11-style license)
 
12
;
 
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:
 
19
;
 
20
;   The above copyright notice and this permission notice shall be included in
 
21
;   all copies or substantial portions of the Software.
 
22
;
 
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.
 
30
;
 
31
; Original author: Jared Davis <jared@kookamara.com>
 
32
 
 
33
(in-package "SIDEKICK")
 
34
(include-book "io")
 
35
(include-book "xdoc/save" :dir :system)
 
36
(set-state-ok t)
 
37
(program)
 
38
 
 
39
(define props-jalist-aux (alist (config str::printconfig-p))
 
40
  (b* (((when (atom alist))
 
41
        nil)
 
42
       ((cons key val) (car alist)))
 
43
    (cons (cons key (str::pretty val :config config))
 
44
          (props-jalist-aux (cdr alist) config))))
 
45
 
 
46
(define props-jalist (name state)
 
47
  (b* (((unless (symbolp name))
 
48
        nil)
 
49
       (world  (w state))
 
50
       (alist  (getprops name 'acl2::current-acl2-world world))
 
51
       (pkg    (current-package state))
 
52
       (config (str::make-printconfig :home-package (pkg-witness pkg)
 
53
                                      :print-lowercase t
 
54
                                      :hard-right-margin 60
 
55
                                      ))
 
56
       (pretty-printed-alist (props-jalist-aux alist config)))
 
57
    pretty-printed-alist))
 
58
 
 
59
(define sk-get-props ((name stringp) state)
 
60
  :returns (mv json-props state)
 
61
  (b* (((mv errmsg objs state) (acl2::read-string name))
 
62
       ((when errmsg)
 
63
        (mv (sk-json-error "Error in props: parsing failed: ~a: ~a" name errmsg)
 
64
            state))
 
65
       ((unless (and (equal (len objs) 1)
 
66
                     (symbolp (car objs))))
 
67
        (mv (sk-json-error "Error in props: not a symbol: ~a" name)
 
68
            state))
 
69
       (props (props-jalist (car objs) state)))
 
70
    (mv (bridge::json-encode
 
71
         (list (cons :error nil)
 
72
               (cons :val props)))
 
73
        state)))
 
74
 
 
75
(define sk-get-origin ((name stringp) state)
 
76
  :returns (mv json-props state)
 
77
  (b* (((mv errmsg objs state) (acl2::read-string name))
 
78
       ((when errmsg)
 
79
        (mv (sk-json-error "Error in origin: parsing failed: ~a: ~a~%" name errmsg)
 
80
            state))
 
81
       ((unless (and (equal (len objs) 1)
 
82
                     (symbolp (car objs))))
 
83
        (mv (sk-json-error "Error in origin: not a symbol: ~a~%" name)
 
84
            state))
 
85
       ((mv ?er val ?state)
 
86
        (acl2::origin-fn (car objs) state)))
 
87
    (mv (bridge::json-encode (list (cons :error nil)
 
88
                                   (cons :val val)))
 
89
        state)))
 
90
 
 
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)))
 
95
       ((unless topic)
 
96
        (mv (sk-json-error "No xdoc for topic ~a~%" name)
 
97
            state))
 
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)))
 
104
        state)))
 
105
 
 
106
(define sk-get-xdoc ((name stringp) state)
 
107
  :returns (mv json-props state)
 
108
  (b* (((mv errmsg objs state) (acl2::read-string name))
 
109
       ((when errmsg)
 
110
        (mv (sk-json-error "Error in origin: parsing failed: ~a: ~a~%" name errmsg)
 
111
            state))
 
112
       ((unless (and (equal (len objs) 1)
 
113
                     (symbolp (car objs))))
 
114
        (mv (sk-json-error "Error in origin: not a symbol: ~a~%" name)
 
115
            state))
 
116
       ((mv out state) (json-xdoc-topic (car objs) state)))
 
117
    (mv out state)))