 ! Copyright (C) 2004 Chris Double.
 ! See http://factorcode.org/license.txt for BSD license.
 USING: lazy-lists promises kernel sequences strings math
-arrays splitting quotations combinators ;
+arrays splitting quotations combinators namespaces ;
 IN: parser-combinators
 
 ! Parser combinator protocol

        rot slice-seq <slice>
    ] if ;

TUPLE: token-parser string ;

C: token token-parser ( string -- parser )

M: token-parser parse ( input parser -- list )
    token-parser-string swap over ?head-slice [
        <parse-result> 1list
    ] [
        2drop nil
    ] if ;

: 1token ( n -- parser ) 1string token ;


    #! required.
    <?> only-first ;

LAZY: <(?)> ( parser -- parser )
    #! Like <?> but take shortest match first.
    f succeed swap [ 1array ] <@ <|> ;

LAZY: <(*)> ( parser -- parser )
    #! Like <*> but take shortest match first.
    #! Implementation by Matthew Willis.
