summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--src/parse.janet34
1 files changed, 19 insertions, 15 deletions
diff --git a/src/parse.janet b/src/parse.janet
index 58e8f79..bb329b5 100644
--- a/src/parse.janet
+++ b/src/parse.janet
@@ -43,8 +43,9 @@
   [& kwargs]
   (let [container @{:doc @[] :field @[] :decl @[]}]
     (each i (range 0 (length kwargs) 2)
-      (array/push (container (kwargs i))
-                  (kwargs (inc i))))
+      (if (container (kwargs i))
+        (array/push (container (kwargs i)) (kwargs (inc i)))
+        (set (container (kwargs i)) (kwargs (inc i)))))
     (freeze container)))
 
 (def grammar
@@ -281,16 +282,18 @@
         :expr/assign (* :expr (+ (* :op/assign :expr)
                                  (+ (some (* :comma :expr)) := :expr)
                                  0))
-        :expr/container (* (+ :keyword/extern :keyword/packed 0)
-                           (+ (* :keyword/struct
-                                 (? (* :paren/l :expr :paren/r)))
-                              :keyword/opaque
-                              :proto/enum
-                              (* :keyword/union
-                                 (? (* :paren/l
-                                       (+ :proto/enum :expr)
-                                       :paren/r))))
-                           :brace/l :container/members :brace/r)
+        :expr/container (/ (* (+ :keyword/extern :keyword/packed 0)
+                              (constant :kind)
+                              (+ (* (constant :struct) :keyword/struct
+                                    (? (* :paren/l :expr :paren/r)))
+                                 (* (constant :opaque) :keyword/opaque)
+                                 :proto/enum
+                                 (* (constant :union) :keyword/union
+                                    (? (* :paren/l
+                                          (+ :proto/enum :expr)
+                                          :paren/r))))
+                              :brace/l :container/members :brace/r)
+                           ,collect)
         :expr/type (* (any :proto/type) :expr/error-union)
         :expr/type/primary (+ :literal/char
                               :literal/float
@@ -422,8 +425,8 @@
                             (/ (* (? :doc-comment)
                                   (? :keyword/comptime)
                                   (! :keyword/fn)
-                                  (? (* :ident (drop ::)))
-                                  :expr/type
+                                  (? (* (constant :ident) :ident (drop ::)))
+                                  (constant :type) :expr/type
                                   (? :byte-align)
                                   (? (* := :expr)))
                                ,struct))
@@ -431,7 +434,8 @@
                               (any :container/decl)
                               (any (* :container/field :comma))
                               (+ :container/field (any :container/decl)))
-        :main (/ (* :skip :container/members -1)
+        :main (/ (* :skip (constant :kind) (constant :struct)
+                    :container/members -1)
                  ,collect)})))
 
 (defn ast