2 USING: kernel parser namespaces quotations vectors strings
3 sequences assocs tuples math combinators ;
7 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
9 TUPLE: insert-quot expr ;
11 C: <insert-quot> insert-quot
13 : ,[ \ ] [ >quotation <insert-quot> ] parse-literal ; parsing
15 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
17 TUPLE: splice-quot expr ;
19 C: <splice-quot> splice-quot
21 : %[ \ ] [ >quotation <splice-quot> ] parse-literal ; parsing
23 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
27 : reset-building ( -- ) 1024 <vector> building set ;
29 : save-exemplar ( seq -- seq ) dup exemplar set ;
31 : finish-baking ( -- seq ) building get exemplar get like ;
35 : bake-item ( item -- )
36 { { [ dup \ , = ] [ drop , ] }
37 { [ dup \ % = ] [ drop % ] }
38 { [ dup insert-quot? ] [ insert-quot-expr call , ] }
39 { [ dup splice-quot? ] [ splice-quot-expr call % ] }
40 { [ dup integer? ] [ , ] }
41 { [ dup string? ] [ , ] }
42 { [ dup tuple? ] [ tuple>array bake >tuple , ] }
43 { [ dup assoc? ] [ [ >alist bake ] keep assoc-like , ] }
44 { [ dup sequence? ] [ bake , ] }
48 : bake-items ( seq -- ) [ bake-item ] each ;
51 [ reset-building save-exemplar bake-items finish-baking ] with-scope ;