! Copyright (C) 2007 Alex Chapman ! See http://factorcode.org/license.txt for BSD license. USING: assocs hashtables kernel lazy-lists namespaces openal parser-combinators promises sequences strings unicode.case ; IN: morse morse-assoc ( -- assoc ) morse-codes >hashtable ; : morse>ch-assoc ( -- assoc ) morse-codes [ reverse ] map >hashtable ; PRIVATE> : ch>morse ( ch -- str ) ch>lower ch>morse-assoc at* swap "" ? ; : morse>ch ( str -- ch ) morse>ch-assoc at* swap f ? ; : >morse ( str -- str ) [ [ CHAR: \s , ] [ ch>morse % ] interleave ] "" make ; <+> ; LAZY: 'morse-word' ( -- parser ) 'morse-char' 'char-gap' list-of ; LAZY: 'morse-words' ( -- parser ) 'morse-word' 'word-gap' list-of ; PRIVATE> : morse> ( str -- str ) 'morse-words' parse car parse-result-parsed [ [ >string morse>ch ] map >string ] map [ [ CHAR: \s , ] [ % ] interleave ] "" make ;