# HG changeset patch # User Chris Cannam # Date 1493295989 -3600 # Thu Apr 27 13:26:29 2017 +0100 # Node ID 69c01349a8dd931f519a59f7f7b927a296c4a49c # Parent 09a100db23ab7152b1eb48af3a0c242525a46ec1 Minor tidy diff --git a/Makefile b/Makefile --- a/Makefile +++ b/Makefile @@ -4,3 +4,7 @@ ./test.sh > test.log 2>&1 tail -3 test.log +clean: + rm -f test test.log + + diff --git a/json.sml b/json.sml --- a/json.sml +++ b/json.sml @@ -229,41 +229,41 @@ (* 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