 LAZY: surrounded-by ( parser start end -- parser' )
     [ token ] 2apply swapd pack ;
 
+: flatten* ( obj -- )
+    dup array? [ [ flatten* ] each ] [ , ] if ;
+
+: flatten [ flatten* ] { } make ;
+
 : exactly-n ( parser n -- parser' )
-    swap <repetition> <and-parser> ;
+    swap <repetition> <and-parser> [ flatten ] <@ ;
 
 : at-most-n ( parser n -- parser' )
     dup zero? [


LAZY: <?> ( parser -- parser )
    #! Return a parser that optionally uses the parser
    #! if that parser would be successfull.
    [ 1array ] <@ f succeed <|> ;

TUPLE: only-first-parser p1 ;

    #! 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.
