]> gitweb.factorcode.org Git - factor.git/commitdiff
Making regexp generate less class algebra
authorDaniel Ehrenberg <littledan@Macintosh-122.local>
Thu, 12 Mar 2009 03:04:47 +0000 (22:04 -0500)
committerDaniel Ehrenberg <littledan@Macintosh-122.local>
Thu, 12 Mar 2009 03:04:47 +0000 (22:04 -0500)
basis/regexp/compiler/compiler.factor
basis/regexp/disambiguate/disambiguate.factor
basis/regexp/minimize/minimize.factor
basis/regexp/transition-tables/transition-tables.factor

index c837df0f0f2e887586ea77d396c2cf84d26b95a2..186d683f8219939ce5848741f04db479253d3e6e 100644 (file)
@@ -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 )
index eac9c7e81d745047f83b6a6278c4c39771d840d7..67b1503f9b7b9ca33851d11f6dffb4e51b1582af 100644 (file)
@@ -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
index bdb53c51cbdf28faee4fe8315fbde93c92973e3a..1885144e6ccb45937d7aa3d8174fa37aa5870ff5 100644 (file)
@@ -96,4 +96,5 @@ IN: regexp.minimize
     clone
     number-states
     combine-states
-    combine-transitions ;
+    combine-transitions
+    expand-ors ;
index 48e84d372cf268c0daffccf635f7d2599c40fdfc..3c33ae88466da489ce2a91df898d6e33c87a0a15 100644 (file)
@@ -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 ;