Skip to content

Commit

Permalink
Fix unescaping of strings for factor
Browse files Browse the repository at this point in the history
  • Loading branch information
iqbalansari authored and kanaka committed Sep 28, 2017
1 parent 1b17329 commit 9ce82e3
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions factor/lib/reader/reader.factor
Original file line number Diff line number Diff line change
@@ -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 <malkeyword> ] }
{ [ dup "false" = ] [ drop f ] }
{ [ dup "true" = ] [ drop t ] }
Expand Down

0 comments on commit 9ce82e3

Please sign in to comment.