]> gitweb.factorcode.org Git - factor.git/blob - extra/slots/syntax/syntax.factor
a17bee4c1931250784fadc7e5a278c904be2be3a
[factor.git] / extra / slots / syntax / syntax.factor
1 ! Copyright (C) 2010 Doug Coleman.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: combinators combinators.smart fry kernel lexer quotations
4 sequences sequences.generalizations slots words ;
5 IN: slots.syntax
6
7 SYNTAX: slots[
8     "]" [ reader-word 1quotation ] map-tokens
9     '[ _ cleave ] append! ;
10
11 SYNTAX: slots{
12     "}" [ reader-word 1quotation ] map-tokens
13     '[ [ _ cleave ] output>array ] append! ;
14
15 : >>writer-word ( name -- word )
16     ">>" prepend "accessors" lookup-word ;
17
18 : writer-word<< ( name -- word )
19     ">>" prepend "accessors" lookup-word ;
20
21 SYNTAX: set-slots[
22     "]" [ >>writer-word 1quotation ] map-tokens
23     '[ _ spread ] append! ;
24
25 SYNTAX: set-slots{
26     "}" [ >>writer-word 1quotation ] map-tokens
27     [ length ] [ ] bi
28     '[ _ firstn _ spread ] append! ;
29
30 SYNTAX: copy-slots{
31     "}" [
32         [ reader-word 1quotation ]
33         [ writer-word<< 1quotation ] bi append
34     ] map-tokens
35     '[ swap _ cleave ] append! ;
36
37 SYNTAX: get[ POSTPONE: slots[ ;
38 SYNTAX: get{ POSTPONE: slots{ ;
39 SYNTAX: set[ POSTPONE: set-slots[ ;
40 SYNTAX: set{ POSTPONE: set-slots{ ;