 
 : <regexp> 'regexp' just parse-1 ;
 
-
 GENERIC: >regexp ( obj -- parser )
 M: string >regexp 'regexp' just parse-1 ;
 M: object >regexp ;

USING: combinators kernel lazy-lists math math.parser
namespaces parser parser-combinators parser-combinators.simple
promises sequences strings ;
USING: continuations io prettyprint ;
IN: regexp

: 'any-char'
    "." token [ drop any-char-parser ] <@ ;

: 'escaped-char'
    "\\" token any-char-parser &> ;

: 'ordinary-char'
    [ "*+?|(){}" member? not ] satisfy ;

: 'char' 'escaped-char' 'ordinary-char' <|> ;

: 'string' 'char' <+> [ >string token ] <@ ;

: exactly-n ( parser n -- parser' )
    swap <repetition> and-parser construct-boa ;

    ] <@ ;

: 'interval'
    'term' "{" token <& 'integer' <&> "}" token <& [ first2 exactly-n ] <@
    'term' "{" token <& 'integer' <&> "," token <& "}" token <&
        [ first2 at-least-n ] <@ <|>
    'term' "{" token <& "," token <& 'integer' <&> "}" token <&
        [ first2 at-most-n ] <@ <|>
    'term' "{" token <& 'integer' <&> "," token <& 'integer' <:&> "}" token <&
        [ first3 from-m-to-n ] <@ <|> ;

: 'repetition'
    'term'
