diff --git a/convex-core/src/main/antlr4/convex/core/lang/reader/antlr/Convex.g4 b/convex-core/src/main/antlr4/convex/core/lang/reader/antlr/Convex.g4 index df150293f..762b936a3 100644 --- a/convex-core/src/main/antlr4/convex/core/lang/reader/antlr/Convex.g4 +++ b/convex-core/src/main/antlr4/convex/core/lang/reader/antlr/Convex.g4 @@ -123,7 +123,7 @@ DECIMAL: fragment EPART: - [eE] (DIGITS | SIGNED_DIGITS); + [eE] (DIGITS | SIGNED_DIGITS) SYMBOL_FOLLOWING*; ADDRESS: '#' [0-9]+; diff --git a/convex-core/src/main/java/convex/core/data/prim/CVMDouble.java b/convex-core/src/main/java/convex/core/data/prim/CVMDouble.java index 70163457b..5503b2aa0 100644 --- a/convex-core/src/main/java/convex/core/data/prim/CVMDouble.java +++ b/convex-core/src/main/java/convex/core/data/prim/CVMDouble.java @@ -145,11 +145,16 @@ public double doubleValue() { /** * Parses a CVM Double value. * @param s String to parse - * @return CVMDouble value - * @throws NumberFormatException If number format is invalid + * @return CVMDouble value, or null if not parseable as a double */ public static CVMDouble parse(String s) { - return create(Double.parseDouble(s)); + try { + double d=Double.parseDouble(s); + return create(d); + } catch (NumberFormatException e) { + return null; + } + } @Override diff --git a/convex-core/src/main/java/convex/core/lang/reader/AntlrReader.java b/convex-core/src/main/java/convex/core/lang/reader/AntlrReader.java index 6a6df93d1..ac01c275f 100644 --- a/convex-core/src/main/java/convex/core/lang/reader/AntlrReader.java +++ b/convex-core/src/main/java/convex/core/lang/reader/AntlrReader.java @@ -234,7 +234,9 @@ public void enterDoubleValue(DoubleValueContext ctx) { @Override public void exitDoubleValue(DoubleValueContext ctx) { String s=ctx.getText(); - push( CVMDouble.parse(s)); + CVMDouble v=CVMDouble.parse(s); + if (v==null) throw new ParseException("Bad double format: "+s); + push(v); } @Override diff --git a/convex-core/src/test/java/convex/core/lang/ReaderTest.java b/convex-core/src/test/java/convex/core/lang/ReaderTest.java index 3317e1187..1d2422c0e 100644 --- a/convex-core/src/test/java/convex/core/lang/ReaderTest.java +++ b/convex-core/src/test/java/convex/core/lang/ReaderTest.java @@ -116,6 +116,12 @@ public void testSymbols() { public void testSymbolPath() { ACell form=Reader.read("foo/bar/baz"); assertEquals(Lists.of(Symbols.LOOKUP,Lists.of(Symbols.LOOKUP,Symbols.FOO,Symbols.BAR),Symbols.BAZ),form) ; + + assertParseException(()->Reader.read("foo/12")); + + // TODO: is this sane? + // assertParseException(()->Reader.read("foo/ bar")); + } @Test @@ -174,9 +180,7 @@ public void testNumbers() { assertParseException(() -> { Reader.read("2.0e0.1234"); }); - // assertNull( Reader.read("[2.0e0.1234]")); - // TODO: do we want this? - //assertThrows(Error.class, () -> Reader.read("[2.0e0.1234]")); // Issue #70 + assertParseException( () -> Reader.read("[2.0e0.1234]")); // Issue #70 // metadata ignored assertEquals(Syntax.create(RT.cvm(3.23),Maps.of(Keywords.FOO, CVMBool.TRUE)), Reader.read("^:foo 3.23"));