]> gitweb.factorcode.org Git - factor.git/commitdiff
strings.parser: better string error messages.
authorJohn Benediktsson <mrjbq7@gmail.com>
Mon, 4 Apr 2016 21:48:05 +0000 (14:48 -0700)
committerJohn Benediktsson <mrjbq7@gmail.com>
Mon, 4 Apr 2016 22:00:04 +0000 (15:00 -0700)
core/strings/parser/parser.factor

index 6f7e0f1bec37cbcafc45703719a2ee85b4b14849..17259bd6deee0a8922dfabd11bfe9d6f46ff7b3f 100644 (file)
@@ -1,8 +1,8 @@
 ! Copyright (C) 2008, 2009 Slava Pestov, Doug Coleman.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: accessors arrays assocs combinators kernel kernel.private
-lexer math math.parser namespaces sbufs sequences splitting
-strings ;
+USING: accessors assocs combinators continuations kernel
+kernel.private lexer math math.parser namespaces sbufs sequences
+splitting strings ;
 IN: strings.parser
 
 ERROR: bad-escape char ;
@@ -151,12 +151,21 @@ DEFER: (parse-full-string)
             (parse-full-string)
         ] if*
     ] [
-        throw-unexpected-eof
+        "Unterminated string" throw
     ] if ;
 
+: rewind-on-error ( quot -- )
+    lexer get [ line>> ] [ line-text>> ] [ column>> ] tri
+    [
+        lexer get [ column<< ] [ line-text<< ] [ line<< ] tri
+        rethrow
+    ] 3curry recover ; inline
+
 PRIVATE>
 
 : parse-full-string ( -- str )
-    SBUF" " clone [
-        lexer get (parse-full-string)
-    ] keep unescape-string ;
+    [
+        SBUF" " clone [
+            lexer get (parse-full-string)
+        ] keep unescape-string
+    ] rewind-on-error ;