]> asedeno.scripts.mit.edu Git - cl-protobufs.git/blobdiff - parser.lisp
define-proto: refactor DEFINE-EXTEND
[cl-protobufs.git] / parser.lisp
index 26c72053905756e254ddbfeb07c85595b9fea72e..e533b066d34bae8d83b42346f349b7a34b4b59d2 100644 (file)
                   (expect-char stream terminator () "import")
                   (maybe-skip-comments stream))))
     (process-imports schema (list import))
-    (setf (proto-imports schema) (nconc (proto-imports schema) (list import)))))
+    (appendf (proto-imports schema) (list import))))
 
 (defun parse-proto-option (stream protobuf &optional (terminators '(#\;)))
   "Parse a Protobufs option line from 'stream'.
                              (t (kintern (parse-token stream)))))
                 (setq terminator (expect-char stream terminators () "option"))
                 (maybe-skip-comments stream)))
-         (option (make-instance 'protobuf-option
-                   :name  key
-                   :value val)))
+         (option (make-option key val)))
     (cond (protobuf
-           (setf (proto-options protobuf) (nconc (proto-options protobuf) (list option)))
+           (appendf (proto-options protobuf) (list option))
            (values option terminator))
           (t
            ;; If nothing to graft the option into, just return it as the value
         (when (null name)
           (expect-char stream #\} '(#\;) "enum")
           (maybe-skip-comments stream)
-          (setf (proto-enums protobuf) (nconc (proto-enums protobuf) (list enum)))
+          (appendf (proto-enums protobuf) (list enum))
           (let ((type (find-option enum "lisp_name")))
             (when type
               (setf (proto-class enum) (make-lisp-symbol type))))
                   :index idx
                   :value (proto->enum-name name *protobuf-package*)
                   :parent enum)))
-    (setf (proto-values enum) (nconc (proto-values enum) (list value)))
+    (appendf (proto-values enum) (list value))
     value))
 
 
         (when (null token)
           (expect-char stream #\} '(#\;) "message")
           (maybe-skip-comments stream)
-          (setf (proto-messages protobuf) (nconc (proto-messages protobuf) (list message)))
+          (appendf (proto-messages protobuf) (list message))
           (let ((type (find-option message "lisp_name")))
             (when type
               (setf (proto-class message) (make-lisp-symbol type))))
         (when (null token)
           (expect-char stream #\} '(#\;) "extend")
           (maybe-skip-comments stream)
-          (setf (proto-messages protobuf) (nconc (proto-messages protobuf) (list extends)))
-          (setf (proto-extenders protobuf) (nconc (proto-extenders protobuf) (list extends)))
+          (appendf (proto-messages protobuf) (list extends))
+          (appendf (proto-extenders protobuf) (list extends))
           (let ((type (find-option extends "lisp_name")))
             (when type
               (setf (proto-class extends) (make-lisp-symbol type))))
           (return-from parse-proto-extend extends))
         (cond ((member token '("required" "optional" "repeated") :test #'string=)
                (let ((field (parse-proto-field stream extends token message)))
-                 (setf (proto-extended-fields extends) (nconc (proto-extended-fields extends) (list field)))))
+                 (appendf (proto-extended-fields extends) (list field))))
               ((string= token "option")
                (parse-proto-option stream extends))
               (t
         (let ((slot (find-option opts "lisp_name")))
           (when slot
             (setf (proto-value field) (make-lisp-symbol type))))
-        (setf (proto-fields message) (nconc (proto-fields message) (list field)))
+        (appendf (proto-fields message) (list field))
         field))))
 
 (defmethod resolve-lisp-names ((field protobuf-field))
       (assert (index-within-extensions-p idx extended-from) ()
               "The index ~D is not in range for extending ~S"
               idx (proto-class extended-from)))
-    (setf (proto-fields message) (nconc (proto-fields message) (list field)))
+    (appendf (proto-fields message) (list field))
     field))
 
 (defun parse-proto-field-options (stream)
     (let ((extension (make-instance 'protobuf-extension
                        :from from
                        :to   (if (integerp to) to #.(1- (ash 1 29))))))
-      (setf (proto-extensions message)
-            (nconc (proto-extensions message)
-                   (list extension)))
+      (appendf (proto-extensions message) (list extension))
       extension)))
 
 
         (when (null token)
           (expect-char stream #\} '(#\;) "service")
           (maybe-skip-comments stream)
-          (setf (proto-services schema) (nconc (proto-services schema) (list service)))
+          (appendf (proto-services schema) (list service))
           (return-from parse-proto-service service))
         (cond ((string= token "option")
                (parse-proto-option stream service))
     (let ((strm (find-option method "stream_type")))
       (when strm
         (setf (proto-streams-name method) strm)))
-    (setf (proto-methods service) (nconc (proto-methods service) (list method)))
+    (appendf (proto-methods service) (list method))
     method))
 
 (defmethod resolve-lisp-names ((method protobuf-method))