69c01349a8dd — Chris Cannam 6 years ago
Minor tidy
2 files changed, 32 insertions(+), 28 deletions(-)

M Makefile
M json.sml
M Makefile +4 -0
@@ 4,3 4,7 @@ test:	test.mlb json.sml test.sml
 	./test.sh > test.log 2>&1
 	tail -3 test.log
 
+clean:
+	rm -f test test.log
+
+

          
M json.sml +28 -28
@@ 229,41 229,41 @@ structure Json :> JSON = struct
         (* Note lexNumber already case-insensitised the E for us *)
         let open Char
 
-            fun chkExpNumber [] = false
-              | chkExpNumber (c :: []) = isDigit c
-              | chkExpNumber (c :: rest) = isDigit c andalso chkExpNumber rest
+            fun okExpDigits [] = false
+              | okExpDigits (c :: []) = isDigit c
+              | okExpDigits (c :: cs) = isDigit c andalso okExpDigits cs
 
-            fun chkExp [] = false
-              | chkExp (#"+" :: rest) = chkExpNumber rest
-              | chkExp (#"-" :: rest) = chkExpNumber rest
-              | chkExp cc = chkExpNumber cc
+            fun okExponent [] = false
+              | okExponent (#"+" :: cs) = okExpDigits cs
+              | okExponent (#"-" :: cs) = okExpDigits cs
+              | okExponent cc = okExpDigits cc
 
-            fun chkAfterDotAndDigit [] = true
-              | chkAfterDotAndDigit (c :: rest) =
-                (isDigit c andalso chkAfterDotAndDigit rest) orelse
-                (c = #"e" andalso chkExp rest)
+            fun okFracTrailing [] = true
+              | okFracTrailing (c :: cs) =
+                (isDigit c andalso okFracTrailing cs) orelse
+                (c = #"e" andalso okExponent cs)
 
-            fun chkAfterDot [] = false
-              | chkAfterDot (c :: rest) =
-                isDigit c andalso chkAfterDotAndDigit rest
+            fun okFraction [] = false
+              | okFraction (c :: cs) =
+                isDigit c andalso okFracTrailing cs
 
-            fun chkPosAfterFirst [] = true
-              | chkPosAfterFirst (#"." :: rest) = chkAfterDot rest
-              | chkPosAfterFirst (#"e" :: rest) = chkExp rest
-              | chkPosAfterFirst (c :: rest) =
-                isDigit c andalso chkPosAfterFirst rest
+            fun okPosTrailing [] = true
+              | okPosTrailing (#"." :: cs) = okFraction cs
+              | okPosTrailing (#"e" :: cs) = okExponent cs
+              | okPosTrailing (c :: cs) =
+                isDigit c andalso okPosTrailing cs
                                                       
-            fun chkPos [] = false
-              | chkPos (#"0" :: []) = true
-              | chkPos (#"0" :: #"." :: rest) = chkAfterDot rest
-              | chkPos (#"0" :: #"e" :: rest) = chkExp rest
-              | chkPos (#"0" :: rest) = false
-              | chkPos (c :: rest) = isDigit c andalso chkPosAfterFirst rest
+            fun okPositive [] = false
+              | okPositive (#"0" :: []) = true
+              | okPositive (#"0" :: #"." :: cs) = okFraction cs
+              | okPositive (#"0" :: #"e" :: cs) = okExponent cs
+              | okPositive (#"0" :: cs) = false
+              | okPositive (c :: cs) = isDigit c andalso okPosTrailing cs
                     
-            fun chkNumber (#"-" :: rest) = chkPos rest
-              | chkNumber cc = chkPos cc
+            fun okNumber (#"-" :: cs) = okPositive cs
+              | okNumber cc = okPositive cc
         in
-            if chkNumber digits
+            if okNumber digits
             then case Real.fromString (implode digits) of
                      NONE => ERROR "Number out of range"
                    | SOME r => OK r