]> gitweb.factorcode.org Git - factor.git/blobdiff - basis/alien/parser/parser.factor
Change C-ENUM: to always take a type. Use f for anonymous enums. Update all uses.
[factor.git] / basis / alien / parser / parser.factor
index 4c5f5dbd6aa0f189d6dd0f8aed5e379f35cc3c68..0891caa04ab9c54c12b9e441a175e4c14ee518cb 100644 (file)
@@ -4,7 +4,7 @@ USING: accessors alien alien.c-types alien.libraries arrays
 assocs classes combinators combinators.short-circuit
 compiler.units effects grouping kernel parser sequences
 splitting words fry locals lexer namespaces summary math
-vocabs.parser ;
+vocabs.parser words.constant ;
 IN: alien.parser
 
 : parse-c-type-name ( name -- word )
@@ -51,14 +51,17 @@ ERROR: *-in-c-type-name name ;
     dup "*" tail?
     [ *-in-c-type-name ] when ;
 
-: CREATE-C-TYPE ( -- word )
-    scan validate-c-type-name current-vocab create {
+: (CREATE-C-TYPE) ( word -- word )
+    validate-c-type-name current-vocab create {
         [ fake-definition ]
         [ set-word ]
         [ reset-c-type ]
         [ ]
     } cleave ;
 
+: CREATE-C-TYPE ( -- word )
+    scan (CREATE-C-TYPE) ;
+
 <PRIVATE
 GENERIC: return-type-name ( type -- name )
 
@@ -72,6 +75,18 @@ M: pointer return-type-name to>> return-type-name CHAR: * suffix ;
 
 PRIVATE>
 
+: define-enum-member ( word-string value -- next-value )
+     [ create-in ] dip [ define-constant ] keep 1 + ;
+
+: parse-enum-member ( word-string value -- next-value )
+     over "{" =
+     [ 2drop scan scan-object define-enum-member "}" expect ]
+     [ define-enum-member ] if ;
+
+: parse-enum-members ( counter -- )
+     scan dup ";" = not
+     [ swap parse-enum-member parse-enum-members ] [ 2drop ] if ;
+
 : scan-function-name ( -- return function )
     scan-c-type scan parse-pointers ;