USING: accessors assocs circular io kernel lists lists.lazy math math.parser multiline peg.ebnf prettyprint prettyprint.custom sequences strings ; IN: rosetta-code.number-wheels TUPLE: group pretty list ; C: group M: group pprint* pretty>> write ; TUPLE: number-wheel seq i ; : ( seq -- number-wheel ) 0 number-wheel boa ; : yield ( assoc -- n ) dup first first [ dup integer? ] [ dupd of [ i>> ] [ [ 1 + ] change-i seq>> nth ] bi ] until nip ; : number-wheel>lazy ( assoc -- list ) 0 lfrom swap [ yield nip ] curry lmap-lazy ; EBNF: nw-parser [=[ num = [0-9]+ => [[ >string string>number ]] name = [a-zA-Z]+ => [[ >string ]] wheel = (" "~ (num | name))+ "\n"? => [[ but-last first ]] group = (name ":"~ wheel)+ => [[ number-wheel>lazy ]] ]=] SYNTAX: NUMBER-WHEELS: parse-here dup nw-parser suffix! ; : .take ( n group -- ) list>> ltake list>array [ pprint bl ] each "..." print ;