 <PRIVATE
 
 : compose-all ( seq -- quot )
-    [ ] [ compose ] reduce ;
+    [ ] [ compose ] reduce ; inline
 
 : fix-sign ( string -- string )
     dup CHAR: 0 swap index 0 =

pad-char  = (zero|char)?         => [[ CHAR: \s or ]]
pad-align = ("-")?               => [[ \ pad-tail \ pad-head ? ]]
pad-width = ([0-9])*             => [[ >digits ]]
pad       = pad-align pad-char pad-width => [[ reverse >quotation dup first 0 = [ drop [ ] ] when ]]

sign      = ("+")?               => [[ [ dup CHAR: - swap index [ "+" prepend ] unless ] [ ] ? ]]



plain-text = (!("%").)+          => [[ >string '[ _ swap ] ]]

text      = (formats|plain-text)* => [[ <reversed> [ [ [ push ] keep ] append ] map ]]

;EBNF

PRIVATE>

MACRO: printf ( format-string -- )
    parse-printf [ length ] keep compose-all
    '[ _ <vector> @ <reversed> [ write ] each ] ;

: sprintf ( format-string -- result )
    [ printf ] with-string-writer ; inline
