]> gitweb.factorcode.org Git - factor.git/commitdiff
math.complex: Check C{ } syntax -- can only have two elements in the complex array...
authorDoug Coleman <doug.coleman@gmail.com>
Fri, 10 Aug 2012 22:57:29 +0000 (15:57 -0700)
committerDoug Coleman <doug.coleman@gmail.com>
Fri, 10 Aug 2012 22:58:04 +0000 (15:58 -0700)
basis/math/complex/complex-tests.factor
basis/math/complex/complex.factor

index d7fe54b201eb9caecd812d2de0f76384a11f7ae1..537163cb09ea0bd586e263c213f813fde110495f 100644 (file)
@@ -76,3 +76,6 @@ IN: math.complex.tests
 10 number-base [
     [ "C{ 1/2 2/3 }" ] [ C{ 1/2 2/3 } unparse ] unit-test
 ] with-variable
+
+[ "C{ 1 2 3 }" eval( -- obj ) ]
+[ error>> T{ malformed-complex f V{ 1 2 3 } } = ] must-fail-with
index c432089f4d944afe6579c2e6dcbf02d4daf79ec5..381f21d693d2ea1fc74fa26c918a30bfc8cfb089 100644 (file)
@@ -1,7 +1,8 @@
 ! Copyright (C) 2006, 2009 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
 USING: accessors kernel kernel.private math math.private
-math.functions arrays math.functions.private sequences parser ;
+math.functions arrays math.functions.private sequences
+sequences.private parser ;
 IN: math.complex.private
 
 M: real real-part ; inline
@@ -30,10 +31,15 @@ M: complex sqrt >polar [ sqrt ] [ 2.0 / ] bi* polar> ; inline
 
 IN: syntax
 
-SYNTAX: C{ \ } [ first2 rect> ] parse-literal ;
+ERROR: malformed-complex obj ;
+
+: parse-complex ( seq -- complex )
+    dup length 2 = [ first2-unsafe rect> ] [ malformed-complex ] if ;
+
+SYNTAX: C{ \ } [ parse-complex ] parse-literal ;
 
 USE: prettyprint.custom
 
 M: complex pprint* pprint-object ;
 M: complex pprint-delims drop \ C{ \ } ;
-M: complex >pprint-sequence >rect 2array ;
\ No newline at end of file
+M: complex >pprint-sequence >rect 2array ;