Merge branch 'master' of git://factorcode.org/git/factor
commit
999f038567
|
@ -77,17 +77,8 @@ C: <box> box
|
|||
: 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 )
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
! 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 ;
|
||||
|
@ -32,9 +32,8 @@ 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
|
||||
|
|
|
@ -96,4 +96,5 @@ IN: regexp.minimize
|
|||
clone
|
||||
number-states
|
||||
combine-states
|
||||
combine-transitions ;
|
||||
combine-transitions
|
||||
expand-ors ;
|
||||
|
|
|
@ -47,3 +47,15 @@ TUPLE: transition-table transitions start-state final-states ;
|
|||
[ '[ _ 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 ;
|
||||
|
|
Loading…
Reference in New Issue