diff --git a/basis/regexp/ast/ast.factor b/basis/regexp/ast/ast.factor index 1c11ed5c7d..be657227e5 100644 --- a/basis/regexp/ast/ast.factor +++ b/basis/regexp/ast/ast.factor @@ -1,7 +1,7 @@ ! Copyright (C) 2008, 2009 Doug Coleman, Daniel Ehrenberg. ! See http://factorcode.org/license.txt for BSD license. -USING: kernel arrays accessors fry sequences regexp.classes ; -FROM: math.ranges => [a,b] ; +USING: kernel arrays accessors fry sequences regexp.classes +math.ranges math ; IN: regexp.ast TUPLE: negation term ; @@ -49,10 +49,20 @@ SINGLETONS: unix-lines dotall multiline case-insensitive reversed-regexp ; ; GENERIC: ( term times -- term' ) + M: at-least n>> swap [ repetition ] [ ] bi 2array ; + +: to-times ( term n -- ast ) + dup zero? + [ 2drop epsilon ] + [ dupd 1- to-times 2array ] + if ; + M: from-to - [ n>> ] [ m>> ] bi [a,b] swap '[ _ repetition ] map ; + [ n>> swap repetition ] + [ [ m>> ] [ n>> ] bi - to-times ] 2bi + 2array ; : char-class ( ranges ? -- term ) [ ] dip [ ] when ;