Переглянути джерело

Improved handling of stack-effect descriptions.

Paul Onions 11 роки тому
батько
коміт
f8860e4aa9
1 змінених файлів з 38 додано та 16 видалено
  1. 38 16
      rpl-edb.el

+ 38 - 16
rpl-edb.el

@@ -31,6 +31,19 @@ As a side-effect set point to the start of the next line."
 
 ;;; Parsing identifier lines
 ;;;
+(defun rpl-trim-stack-effect-description (lines)
+  "Trim leading and trailing fluff from strings in LINES list."
+  (let ((left-edge 1000))
+    (dolist (s lines)
+      (string-match "[[:blank:]]*" s)
+      (when (< (match-end 0) left-edge)
+        (setq left-edge (match-end 0))))
+    (mapcar (lambda (s)
+              (if (string-match "\\([[:blank:]]*\\(\\\\\\)*[[:blank:]]*$\\)" s)
+                  (substring s left-edge (match-beginning 1))
+                (substring s left-edge)))
+            lines)))
+
 (defun rpl-edb-consume-ident-line ()
   "Consume an EDB identifier line.
 Return a list of two strings: the identifier and its stack effect
@@ -38,15 +51,14 @@ description.  Move point to the start of the next line."
   (let ((line (rpl-edb-get-line)))
     (cond ((string-match "^[[:graph:]]+" line)
            (let* ((name (match-string 0 line))
-                  (desc (substring line (match-end 0))))
+                  (desc (list (concat (make-string (match-end 0) 32)
+                                      (substring line (match-end 0))))))
              ;; Automatically consume continuation lines
              ;; (after line ends with a backslash)
-             (while (and (> (length desc) 0)
-                         (string-match ".*\\\\[[:blank:]]*$" desc))
-               (setq desc (concat (substring desc 0 (1- (length desc)))
-                                  "\n"
-                                  (rpl-edb-get-line))))
-             (list name desc)))
+             (while (and (> (length (car desc)) 0)
+                         (string-match ".*\\\\[[:blank:]]*$" (car desc)))
+               (setq desc (cons (rpl-edb-get-line) desc)))
+             (list name (rpl-trim-stack-effect-description (reverse desc)))))
           (t
            (list "" "")))))
 
@@ -109,14 +121,25 @@ Return a string.  Move point to the start of the next line."
 ;;;
 (defun rpl-edb-parse-buffer ()
   "Parse the current buffer, assumed to be the entries.db file.
-Return a list of EDB entries of the format:
-???
-"
+Return a list of EDB entries, where each entry has the format:
+  (NAMES STACK-EFFECT DESCRIPTION CALC-INFOS)
+where NAMES is a list of strings representing the different names
+under which the entry is known, STACK-EFFECT and DESCRIPTION are
+lists of strings -- one for each line of text in their respective
+desciptions -- and CALC-INFOS is a list of entries of the form:
+  (CALC-KEY ADDRESS NAME-FORMAT &rest FLAG-KEYS)
+where CALC-KEY is a keyword specifying a calculator
+model (:38G, :39G, :48G or :49G), ADDRESS is a string containing
+a hexadecimal address (5 digits for a ROM address, 6 digits for a
+library/flash pointer), NAME-FORMAT is a FORMAT string allowing
+the name of the entry to be modified for this particular
+calculator, and FLAG-KEYS are keyword symbols specifying certain
+flags for this calculator."
   (interactive)
   (let ((entry-names nil)
         (entry-stack-effect nil)
+        (entry-description nil)
         (entry-calc-infos nil)
-        (entry-description "")
         (entries nil))
     (beginning-of-buffer)
     (while (not (eobp))
@@ -128,8 +151,7 @@ Return a list of EDB entries of the format:
              (forward-line))
             ((eql (char-after) ?\;)
              ;; An extended description line
-             (setq entry-description (concat entry-description " "
-                                             (rpl-edb-consume-description-line))))
+             (setq entry-description (cons (rpl-edb-consume-description-line) entry-description)))
             ((eql (char-after) ?.)
              ;; A keyword line
              (cl-destructuring-bind (keyword &rest params)
@@ -142,15 +164,15 @@ Return a list of EDB entries of the format:
             (t
              ;; An identifier/stack-effect line
              (when entry-names
-               (push (list entry-names entry-stack-effect entry-calc-infos entry-description) entries))
+               (push (list entry-names entry-stack-effect (reverse entry-description) entry-calc-infos) entries))
              (cl-destructuring-bind (name stack-effect)
                  (rpl-edb-consume-ident-line)
                (setq entry-names (list name))
                (setq entry-stack-effect stack-effect)
                (setq entry-calc-infos nil)
-               (setq entry-description "")))))
+               (setq entry-description nil)))))
     (when entry-names
-      (push (list entry-names entry-stack-effect entry-calc-infos entry-description) entries))
+      (push (list entry-names entry-stack-effect (reverse entry-description) entry-calc-infos) entries))
     (reverse entries)))
 
 (defvar rpl-edb-entries nil