: literals>cases ( literal-transitions -- case-body )
[ execution-quot ] assoc-map ;
-: expand-one-or ( or-class transition -- alist )
- [ seq>> ] dip '[ _ 2array ] map ;
-
-: expand-or ( alist -- new-alist )
- [
- first2 over or-class?
- [ expand-one-or ] [ 2array 1array ] if
- ] map concat ;
-
: split-literals ( transitions -- case default )
- >alist expand-or [ first integer? ] partition
+ { } assoc-like [ first integer? ] partition
[ [ literals>cases ] keep ] dip non-literals>dispatch ;
:: step ( last-match index str quot final? direction -- last-index/f )
! Copyright (C) 2009 Daniel Ehrenberg.
! See http://factorcode.org/license.txt for BSD license.
USING: kernel accessors regexp.classes math.bits assocs sequences
-arrays sets regexp.dfa math fry regexp.minimize regexp.ast ;
+arrays sets regexp.dfa math fry regexp.minimize regexp.ast regexp.transition-tables ;
IN: regexp.disambiguate
TUPLE: parts in out ;
: preserving-epsilon ( state-transitions quot -- new-state-transitions )
[ [ drop tagged-epsilon? ] assoc-filter ] bi
assoc-union H{ } assoc-like ; inline
-
: disambiguate ( nfa -- nfa )
- [
+ expand-ors [
dup new-transitions '[
[
_ swap '[ _ get-transitions ] assoc-map
clone
number-states
combine-states
- combine-transitions ;
+ combine-transitions
+ expand-ors ;
[ '[ _ condition-at ] change-start-state ]
[ '[ [ _ at ] map-set ] change-final-states ]
[ '[ _ number-transitions ] change-transitions ] tri ;
+
+: expand-one-or ( or-class transition -- alist )
+ [ seq>> ] dip '[ _ 2array ] map ;
+
+: expand-or ( state-transitions -- new-transitions )
+ >alist [
+ first2 over or-class?
+ [ expand-one-or ] [ 2array 1array ] if
+ ] map concat >hashtable ;
+
+: expand-ors ( transition-table -- transition-table )
+ [ [ expand-or ] assoc-map ] change-transitions ;