Make literals work with aliases, add flags{ parsing word to clean boilerplate with $[

release
Doug Coleman 2010-03-31 07:24:00 -05:00
parent be51468863
commit c49f45f051
1 changed files with 12 additions and 3 deletions

View 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! ;