2 USING: kernel parser namespaces sequences quotations arrays vectors splitting
3 strings words math generalizations
4 macros combinators.conditional newfx ;
8 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
13 : comma? ( obj -- ? ) , = ;
14 : atsym? ( obj -- ? ) @ = ;
16 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
20 : broil-element ( obj -- quot )
22 { [ comma? ] [ drop [ >r ] ] }
23 { [ f = ] [ [ >r ] prefix-on ] }
24 { [ integer? ] [ [ >r ] prefix-on ] }
25 { [ string? ] [ [ >r ] prefix-on ] }
26 { [ sequence? ] [ [bake] [ >r ] append ] }
27 { [ word? ] [ literalize [ >r ] prefix-on ] }
28 { [ drop t ] [ [ >r ] prefix-on ] }
32 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
34 : constructor ( seq -- quot )
36 { [ array? ] [ length [ narray ] prefix-on ] }
37 ! { [ quotation? ] [ length [ ncurry ] prefix-on [ ] prefix ] }
38 { [ quotation? ] [ length [ narray >quotation ] prefix-on ] }
39 { [ vector? ] [ length [ narray >vector ] prefix-on ] }
43 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
45 : [broil] ( seq -- quot )
46 [ reverse [ broil-element ] map concat ]
47 [ length [ drop [ r> ] ] map concat ]
52 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
54 SYMBOL: saved-sequence
56 : [connector] ( -- quot )
57 saved-sequence get quotation? [ [ compose ] ] [ [ append ] ] if ;
59 : [starter] ( -- quot )
62 { [ quotation? ] [ drop [ [ ] ] ] }
63 { [ array? ] [ drop [ { } ] ] }
64 { [ vector? ] [ drop [ V{ } ] ] }
68 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
70 : [simmer] ( seq -- quot )
72 dup saved-sequence set
75 [ [ [bake] [connector] append [ >r ] append ] map concat ]
76 [ length [ drop [ r> ] [connector] append ] map concat ]
79 >r 1 invert-index pluck r> ! remove the last append/compose
85 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
87 : [bake] ( seq -- quot ) [ @ member? ] [ [simmer] ] [ [broil] ] 1if ;
89 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
91 MACRO: bake ( seq -- quot ) [bake] ;
93 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
95 : `{ \ } [ >array ] parse-literal \ bake parsed ; parsing
96 : `V{ \ } [ >vector ] parse-literal \ bake parsed ; parsing
97 : `[ \ ] [ >quotation ] parse-literal \ bake parsed ; parsing