1 USING: kernel parser lexer strings math namespaces make
2 sequences words io arrays quotations debugger accessors
7 ! STATES: set-name state1 state2 ... ;
11 [ create-in swap 1quotation define ] 2each ; parsing
13 TUPLE: state place data ;
15 ERROR: missing-state ;
17 M: missing-state error.
18 drop "Missing state" print ;
20 : make-machine ( states -- table quot )
21 ! quot is ( state string -- output-string )
22 [ missing-state ] <array> dup
24 [ [ dup [ data>> ] [ place>> ] bi ] dip ] %
25 [ swapd bounds-check dispatch ] curry ,
26 [ each pick (>>place) swap (>>date) ] %
27 ] [ ] make [ over make ] curry ;
29 : define-machine ( word state-class -- )
32 "state-table" set-word-prop ;
35 ! MACHINE: utf8 unicode-states
36 CREATE scan-word define-machine ; parsing
39 ! S: state state-machine definition... ;
40 ! definition MUST be ( data char -- newdata state )
41 scan-word execute scan-word "state-table" word-prop
42 parse-definition -rot set-nth ; parsing