diff --git a/factor/lib/reader/reader.factor b/factor/lib/reader/reader.factor index 587ed90ab7..767241ae26 100644 --- a/factor/lib/reader/reader.factor +++ b/factor/lib/reader/reader.factor @@ -1,18 +1,26 @@ ! Copyright (C) 2015 Jordan Lewis. ! See http://factorcode.org/license.txt for BSD license. -USING: arrays combinators grouping hashtables kernel lists -locals make lib.types math.parser regexp sequences splitting ; +USING: arrays combinators grouping hashtables kernel lists locals +make lib.types math.parser regexp sequences splitting strings ; IN: lib.reader CONSTANT: token-regex R/ (~@|[\[\]{}()'`~^@]|"(?:\\.|[^\\"])*"|;.*|[^\s\[\]{}('"`,;)~^@]+)/ DEFER: read-form +: (read-string) ( str -- maltype ) + rest but-last R/ \\./ [ + { + { [ dup >string "\\\\" = ] [ drop "\\" ] } + { [ dup >string "\\n" = ] [ drop "\n" ] } + { [ dup >string "\\\"" = ] [ drop "\"" ] } + [ ] + } cond + ] re-replace-with ; + : (read-atom) ( str -- maltype ) { - { [ dup first CHAR: " = ] [ rest but-last "\\\"" "\"" replace - "\\n" "\n" replace - "\\\\" "\\" replace ] } + { [ dup first CHAR: " = ] [ (read-string) ] } { [ dup first CHAR: : = ] [ rest ] } { [ dup "false" = ] [ drop f ] } { [ dup "true" = ] [ drop t ] }