1 ! Copyright (C) 2008, 2010 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: arrays combinators effects kernel lexer make namespaces
4 parser sequences splitting words ;
10 ERROR: invalid-row-variable ;
11 ERROR: row-variable-can't-have-type ;
12 ERROR: stack-effect-omits-dashes ;
17 : end-token? ( end token -- token ? ) [ nip ] [ = ] 2bi ; inline
18 : effect-opener? ( token -- token ? ) dup { f "(" "((" "--" } member? ; inline
19 : effect-closer? ( token -- token ? ) dup { ")" "))" } member? ; inline
20 : row-variable? ( token -- token' ? ) ".." ?head ; inline
22 : parse-effect-var ( first? var name -- var )
24 [ ":" ?tail [ row-variable-can't-have-type ] when ] curry
25 [ invalid-row-variable ] if ;
27 : parse-effect-value ( token -- value )
28 ":" ?tail [ scan-object 2array ] when ;
31 : parse-effect-token ( first? var end -- var more? )
33 { [ end-token? ] [ drop nip f ] }
34 { [ effect-opener? ] [ bad-effect ] }
35 { [ effect-closer? ] [ stack-effect-omits-dashes ] }
36 { [ row-variable? ] [ parse-effect-var t ] }
37 [ [ drop ] 2dip parse-effect-value , t ]
40 : parse-effect-tokens ( end -- var tokens )
42 [ t f ] dip [ parse-effect-token [ f ] 2dip ] curry [ ] while nip
45 : parse-effect ( end -- effect )
46 [ "--" parse-effect-tokens ] dip parse-effect-tokens
49 : scan-effect ( -- effect )
50 "(" expect ")" parse-effect ;
52 : parse-call-paren ( accum word -- accum )
53 [ ")" parse-effect ] dip 2array append! ;
57 ERROR: can't-nest-definitions word ;
59 : check-in-definition ( -- )
60 in-definition get [ last-word can't-nest-definitions ] when ;
62 : with-definition ( quot -- )
63 [ check-in-definition t in-definition ] dip with-variable ; inline
65 : (:) ( -- word def effect )