]> gitweb.factorcode.org Git - factor.git/commitdiff
Refactor source-file-errors a little bit to remove some code duplication, and so...
authorSlava Pestov <slava@slava-pestovs-macbook-pro.local>
Wed, 5 Aug 2009 02:01:21 +0000 (21:01 -0500)
committerSlava Pestov <slava@slava-pestovs-macbook-pro.local>
Wed, 5 Aug 2009 02:01:21 +0000 (21:01 -0500)
basis/editors/editors.factor
basis/tools/errors/errors.factor
basis/tools/test/test.factor
core/lexer/lexer.factor
core/source-files/errors/errors.factor

index da6a589031ed0ae9aa8d1aff2ef0f361f500f990..4a6dd9b5bef93fa6e0850491a607b32fdc2f0f7e 100644 (file)
@@ -47,43 +47,12 @@ M: cannot-find-source error.
 : edit-vocab ( name -- )
     >vocab-link edit ;
 
-GENERIC: error-file ( error -- file )
-
-GENERIC: error-line ( error -- line )
-
-M: lexer-error error-file
-    error>> error-file ;
-
-M: lexer-error error-line
-    [ error>> error-line ] [ line>> ] bi or ;
-
-M: source-file-error error-file
-    [ error>> error-file ] [ file>> ] bi or ;
-
-M: source-file-error error-line
-    error>> error-line ;
-
-M: condition error-file
-    error>> error-file ;
-
-M: condition error-line
-    error>> error-line ;
-
-M: object error-file
-    drop f ;
-
-M: object error-line
-    drop f ;
-
-: (:edit) ( error -- )
+: edit-error ( error -- )
     [ error-file ] [ error-line ] bi
     2dup and [ edit-location ] [ 2drop ] if ;
 
 : :edit ( -- )
-    error get (:edit) ;
-
-: edit-error ( error -- )
-    [ file>> ] [ line#>> ] bi 2dup and [ edit-location ] [ 2drop ] if ;
+    error get edit-error ;
 
 : edit-each ( seq -- )
     [
index b53d4ef7a2a6578caa20fe9ba4ef0562cded2449..963ea7592ccec5ddd5709f7ced0211f36e4c5cb0 100644 (file)
@@ -14,14 +14,16 @@ M: source-file-error error-help error>> error-help ;
 
 CONSTANT: +listener-input+ "<Listener input>"
 
-M: source-file-error summary
+: error-location ( error -- string )
     [
-        [ file>> [ % ": " % ] [ +listener-input+ % ] if* ]
-        [ line#>> [ # ] when* ] bi
+        [ file>> [ % ] [ +listener-input+ % ] if* ]
+        [ line#>> [ ": " % # ] when* ] bi
     ] "" make ;
 
+M: source-file-error summary error>> summary ;
+
 M: source-file-error error.
-    [ summary print nl ]
+    [ error-location print nl ]
     [ asset>> [ "Asset: " write short. nl ] when* ]
     [ error>> error. ]
     tri ;
index 7b07311ded119dc7923ef76212d7ef1339540132..b6d56b18c078a6c2abde8ac99889b1ae30f41e4e 100644 (file)
@@ -130,7 +130,7 @@ TEST: must-fail
 
 M: test-failure error. ( error -- )
     {
-        [ summary print nl ]
+        [ error-location print nl ]
         [ asset>> [ experiment. nl ] when* ]
         [ error>> error. ]
         [ traceback-button. ]
index 99e6f05c6c6df186cb947b43a2d297ebe1c139ad..036c7d9721bc48cf7575d2c942e33ea039b2d1d2 100644 (file)
@@ -1,7 +1,8 @@
 ! Copyright (C) 2008, 2009 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
 USING: kernel sequences accessors namespaces math words strings
-io vectors arrays math.parser combinators continuations ;
+io vectors arrays math.parser combinators continuations
+source-files.errors ;
 IN: lexer
 
 TUPLE: lexer text line line-text line-length column ;
@@ -24,11 +25,8 @@ TUPLE: lexer text line line-text line-length column ;
 
 ERROR: unexpected want got ;
 
-PREDICATE: unexpected-tab < unexpected
-    got>> CHAR: \t = ;
-
 : forbid-tab ( c -- c )
-    [ CHAR: \t eq? [ "[space]" "[tab]" unexpected ] when ] keep ;
+    [ CHAR: \t eq? [ "[space]" "[tab]" unexpected ] when ] keep ; inline
 
 : skip ( i seq ? -- n )
     over length
@@ -96,6 +94,9 @@ PREDICATE: unexpected-eof < unexpected
 
 TUPLE: lexer-error line column line-text error ;
 
+M: lexer-error error-file error>> error-file ;
+M: lexer-error error-line [ error>> error-line ] [ line>> ] bi or ;
+
 : <lexer-error> ( msg -- error )
     \ lexer-error new
         lexer get
index 86a8354071e5c54f90103324c3039847cb567c98..93078c162b9d75aac21129c83df2ad4b1e3b379f 100644 (file)
@@ -1,11 +1,23 @@
 ! Copyright (C) 2009 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
 USING: accessors assocs kernel math.order sorting sequences definitions
-namespaces arrays splitting io math.parser math init ;
+namespaces arrays splitting io math.parser math init continuations ;
 IN: source-files.errors
 
+GENERIC: error-file ( error -- file )
+GENERIC: error-line ( error -- line )
+
+M: object error-file drop f ;
+M: object error-line drop f ;
+
+M: condition error-file error>> error-file ;
+M: condition error-line error>> error-line ;
+
 TUPLE: source-file-error error asset file line# ;
 
+M: source-file-error error-file [ error>> error-file ] [ file>> ] bi or ;
+M: source-file-error error-line [ error>> error-line ] [ line#>> ] bi or ;
+
 : sort-errors ( errors -- alist )
     [ [ line#>> ] sort-with ] { } assoc-map-as sort-keys ;