]> gitweb.factorcode.org Git - factor.git/commitdiff
bare: better errors for empty enums/unions/structs
authorJohn Benediktsson <mrjbq7@gmail.com>
Thu, 16 Jun 2022 18:04:47 +0000 (11:04 -0700)
committerJohn Benediktsson <mrjbq7@gmail.com>
Thu, 16 Jun 2022 18:04:47 +0000 (11:04 -0700)
extra/bare/bare-tests.factor
extra/bare/bare.factor

index 80632711b42584e2b6eedae3f5688197010feb74..ba1d18112869875a768b58b1f907856ba07670aa 100644 (file)
@@ -379,6 +379,8 @@ type Person union {Customer | Employee | TerminatedEmployee}
 
 ! enum checks
 
+[ "type Thing enum {}" parse-schema ] [ not-enough-entries? ] must-fail-with
+[ "type Thing enum { }" parse-schema ] [ not-enough-entries? ] must-fail-with
 [
     "type Alphabet enum {
       A
@@ -422,11 +424,15 @@ type Person union {Customer | Employee | TerminatedEmployee}
 
 ! union checks
 
+[ "type Thing union {}" parse-schema ] [ not-enough-entries? ] must-fail-with
+[ "type Thing union { }" parse-schema ] [ not-enough-entries? ] must-fail-with
 [ "type Thing union {int=0|int|str=0}" parse-schema ] [ duplicate-keys? ] must-fail-with
 [ "type Thing union {int=0|uint|str=0}" parse-schema ] [ duplicate-values? ] must-fail-with
 
 ! struct checks
 
+[ "type Thing struct {}" parse-schema ] [ not-enough-entries? ] must-fail-with
+[ "type Thing struct { }" parse-schema ] [ not-enough-entries? ] must-fail-with
 [ "type Thing struct { a: int b: int a: int }" parse-schema ] [ duplicate-keys? ] must-fail-with
 [ "type Thing struct { a: void }" parse-schema ] [ cannot-be-void? ] must-fail-with
 
index 5504d707702b05f1ea4c3258c1e587b543215333..fd193fbb63223fd6c20561f8ea7d4d98289b4396 100644 (file)
@@ -260,7 +260,7 @@ str       = "str"                         => [[ str ]]
 data      = "data"~ length?               => [[ <data> ]]
 void      = "void"                        => [[ void ]]
 
-enum-values = enum-value (ws enum-value)* => [[ first2 swap prefix ]]
+enum-values = (ws enum-value ws)*
 enum-value = enum-value-name (ws "="~ ws number)?
 enum-value-name = upper (upper|digit|[_])* => [[ first2 swap prefix >string ]]
 enum      = "enum"~ ws "{"~ ws enum-values ws "}"~ => [[ <enum> ]]
@@ -276,12 +276,12 @@ map       = "map"~ type type              => [[ first2 <map> ]]
 
 struct-field-name = alpha+                => [[ >string ]]
 struct-field = struct-field-name ws ":"~ ws any-type => [[ >array ]]
-struct-fields = struct-field (ws struct-field)* => [[ first2 swap prefix ]]
-struct    = "struct"~ ws "{"~ ws~ struct-fields ws "}"~ => [[ <struct> ]]
+struct-fields = (ws struct-field ws)*
+struct    = "struct"~ ws "{"~ ws struct-fields ws "}"~ => [[ <struct> ]]
 
 union-members = union-member (ws "|"~ ws union-member)* => [[ first2 swap prefix ]]
 union-member  = any-type (ws "="~ ws number)? => [[ >array ]]
-union     = "union"~ ws "{"~ ws ("|"?)~ ws union-members ws ("|"?)~ ws "}"~ => [[ <union> ]]
+union     = "union"~ ws "{"~ ws ("|"?)~ ws union-members? ws ("|"?)~ ws "}"~ => [[ <union> ]]
 
 aggregate = optional|list|map|struct|union
 
@@ -293,8 +293,7 @@ user-type-name = (alpha|digit)+     => [[ >string ]]
 user-type = "type"~ ws user-type-name ws any-type
           => [[ first2 [ 2array ] 2keep swap user-types [ ?set-at ] change ]]
 
-user-types = user-type (ws user-type)* => [[ first2 swap prefix ]]
-schema = ws user-types ws => [[ <schema> ]]
+schema = (ws user-type ws)* => [[ <schema> ]]
 
 ]=]