]> gitweb.factorcode.org Git - factor.git/commitdiff
Make literals work with aliases, add flags{ parsing word to clean boilerplate with $[
authorDoug Coleman <doug.coleman@gmail.com>
Wed, 31 Mar 2010 12:24:00 +0000 (07:24 -0500)
committerDoug Coleman <doug.coleman@gmail.com>
Wed, 31 Mar 2010 20:03:33 +0000 (15:03 -0500)
basis/literals/literals.factor

index 001c56525f3852c5884c7819d1d43ee16944f72f..3e541a80ceba02e7945753fa6221ae479214905d 100644 (file)
@@ -1,6 +1,6 @@
 ! (c) Joe Groff, see license for details
-USING: accessors continuations kernel parser words quotations
-vectors sequences fry ;
+USING: accessors combinators continuations fry kernel lexer
+math parser quotations sequences vectors words words.alias ;
 IN: literals
 
 <PRIVATE
@@ -8,8 +8,13 @@ IN: literals
 ! Use def>> call so that CONSTANT:s defined in the same file can
 ! be called
 
+: expand-alias ( obj -- obj' )
+    dup alias? [ def>> first expand-alias ] when ;
+
 : expand-literal ( seq obj -- seq' )
-    '[ _ dup word? [ def>> call ] when ] with-datastack ;
+    '[
+        _ expand-alias dup word? [ def>> call ] when
+    ] with-datastack ;
 
 : expand-literals ( seq -- seq' )
     [ [ { } ] dip expand-literal ] map concat ;
@@ -19,3 +24,7 @@ PRIVATE>
 SYNTAX: $ scan-word expand-literal >vector ;
 SYNTAX: $[ parse-quotation with-datastack >vector ;
 SYNTAX: ${ \ } [ expand-literals ] parse-literal ;
+SYNTAX: flags{
+    "}" [ parse-word ] map-tokens
+    expand-literals
+    0 [ bitor ] reduce suffix! ;