! 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 math.ranges math ; IN: regexp.ast TUPLE: negation term ; C: negation TUPLE: from-to n m ; C: from-to TUPLE: at-least n ; C: at-least TUPLE: tagged-epsilon tag ; C: tagged-epsilon CONSTANT: epsilon T{ tagged-epsilon { tag t } } TUPLE: concatenation first second ; : ( seq -- concatenation ) [ epsilon ] [ [ ] [ concatenation boa ] map-reduce ] if-empty ; TUPLE: alternation first second ; : ( seq -- alternation ) [ ] [ alternation boa ] map-reduce ; TUPLE: star term ; C: star TUPLE: with-options tree options ; C: with-options TUPLE: options on off ; C: options SINGLETONS: unix-lines dotall multiline case-insensitive reversed-regexp ; : ( term -- term' ) f 2array ; : ( term -- term' ) dup 2array ; : repetition ( n term -- term' ) ; 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>> swap repetition ] [ [ m>> ] [ n>> ] bi - to-times ] 2bi 2array ; : char-class ( ranges ? -- term ) [ ] dip [ ] when ; TUPLE: lookahead term ; C: lookahead TUPLE: lookbehind term ; C: lookbehind