]> gitweb.factorcode.org Git - factor.git/blobdiff - basis/regexp/compiler/compiler.factor
regexp: don't use execute so the generated code is easier to read
[factor.git] / basis / regexp / compiler / compiler.factor
index d8940bb829a3afc70848194901b8a795d36d8999..9102836d68798eeb2ba16af6e9c23c143fe4a60f 100644 (file)
@@ -1,10 +1,9 @@
 ! Copyright (C) 2009 Daniel Ehrenberg.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: regexp.classes kernel sequences regexp.negation
-quotations assocs fry math locals combinators
-accessors words compiler.units kernel.private strings
-sequences.private arrays namespaces unicode.breaks
-regexp.transition-tables combinators.short-circuit ;
+USING: accessors assocs combinators combinators.short-circuit
+kernel kernel.private math namespaces quotations regexp.classes
+regexp.transition-tables sequences sequences.private sets
+strings unicode words ;
 IN: regexp.compiler
 
 GENERIC: question>quot ( question -- quot )
@@ -31,10 +30,10 @@ M: end-of-file question>quot
         } 2&&
     ] ;
 
-M: $ question>quot
+M: $crlf question>quot
     drop [ { [ length = ] [ ?nth "\r\n" member? ] } 2|| ] ;
 
-M: ^ question>quot
+M: ^crlf question>quot
     drop [ { [ drop zero? ] [ [ 1 - ] dip ?nth "\r\n" member? ] } 2|| ] ;
 
 M: $unix question>quot
@@ -52,7 +51,7 @@ M: word-break question>quot
         [ question>> question>quot ] [ yes>> ] [ no>> ] tri
         [ (execution-quot) ] bi@
         '[ 2dup @ _ _ if ]
-    ] [ '[ _ execute ] ] if ;
+    ] [ 1quotation ] if ;
 
 : execution-quot ( next-state -- quot )
     dup sequence? [ first ] when
@@ -106,13 +105,13 @@ C: <box> box
 
 : word>quot ( word dfa -- quot )
     [ transitions>> at ]
-    [ final-states>> key? ] 2bi
+    [ final-states>> in? ] 2bi
     transitions>quot ;
 
 : states>code ( words dfa -- )
     '[
         dup _ word>quot
-        (( last-match index string -- ? ))
+        ( last-match index string -- ? )
         define-declared
     ] each ;
 
@@ -120,7 +119,7 @@ C: <box> box
     dup transitions>> keys [ gensym ] H{ } map>assoc
     [ transitions-at ]
     [ values ]
-    bi swap ; 
+    bi swap ;
 
 : dfa>main-word ( dfa -- word )
     states>words [ states>code ] keep start-state>> ;
@@ -132,7 +131,7 @@ PRIVATE>
 
 : dfa>word ( dfa -- quot )
     dfa>main-word execution-quot word-template
-    (( start-index string regexp -- i/f )) define-temp ;
+    ( start-index string regexp -- i/f ) define-temp ;
 
 : dfa>shortest-word ( dfa -- word )
     t shortest? [ dfa>word ] with-variable ;