factor/basis/regexp/transition-tables/transition-tables.factor

25 lines
779 B
Factor
Raw Normal View History

! Copyright (C) 2008 Doug Coleman.
! See http://factorcode.org/license.txt for BSD license.
USING: accessors arrays assocs fry hashtables kernel sequences
vectors locals ;
IN: regexp.transition-tables
2008-11-24 23:16:29 -05:00
TUPLE: transition-table transitions start-state final-states ;
: <transition-table> ( -- transition-table )
transition-table new
H{ } clone >>transitions
2008-11-24 23:16:29 -05:00
H{ } clone >>final-states ;
2008-09-19 18:54:34 -04:00
: maybe-initialize-key ( key hashtable -- )
2009-01-23 19:20:47 -05:00
2dup key? [ 2drop ] [ [ H{ } clone ] 2dip set-at ] if ;
2008-09-19 18:54:34 -04:00
:: set-transition ( from to obj hash -- )
to hash maybe-initialize-key
from hash at
[ [ to obj ] dip push-at ]
[ to 1vector obj associate from hash set-at ] if* ;
: add-transition ( from to obj transition-table -- )
transitions>> set-transition ;