! 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] ; 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 } TUPLE: concatenation first second ; : ( seq -- concatenation ) [ epsilon ] [ unclip [ concatenation boa ] reduce ] if-empty ; TUPLE: alternation first second ; : ( seq -- alternation ) unclip [ alternation boa ] 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 comments case-insensitive unicode-case 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 ; M: from-to [ n>> ] [ m>> ] bi [a,b] swap '[ _ repetition ] map ; : char-class ( ranges ? -- term ) [ ] dip [ ] when ; TUPLE: lookahead term ; C: lookahead TUPLE: lookbehind term ; C: lookbehind TUPLE: possessive-star term ; C: possessive-star : ( term -- term' ) dup 2array ;