From 93b6a5d9300b6cc9b16a7772fbb64ad8da20f750 Mon Sep 17 00:00:00 2001 From: Nat Quayle Nelson Date: Wed, 18 Nov 2020 19:15:31 -0700 Subject: [PATCH] Make empty string the default read macro --- src/kiss/Reader.hx | 5 ++++- src/test/cases/BasicTestCase.hx | 1 + 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/kiss/Reader.hx b/src/kiss/Reader.hx index 1c96c93f..dbfb7445 100644 --- a/src/kiss/Reader.hx +++ b/src/kiss/Reader.hx @@ -38,6 +38,9 @@ class Reader { readTable[":"] = (stream) -> TypedExp(nextToken(stream, "a type path"), assertRead(stream, readTable)); + // Because macro keys are sorted by length and peekChars(0) returns "", this will be used as the default reader macro: + readTable[""] = (stream) -> Symbol(nextToken(stream, "a symbol name")); + return readTable; } @@ -74,7 +77,7 @@ class Reader { } } - return Some(Symbol(nextToken(stream, "a symbol name"))); + throw 'No macro to read next expression'; } public static function readExpArray(stream:Stream, end:String, readTable:Map):Array { diff --git a/src/test/cases/BasicTestCase.hx b/src/test/cases/BasicTestCase.hx index 8b73882b..6fb50aa0 100644 --- a/src/test/cases/BasicTestCase.hx +++ b/src/test/cases/BasicTestCase.hx @@ -128,6 +128,7 @@ class BasicTestCase extends Test { })); } + // TODO to really test typed variable definitions, check for compilation failure on a bad example function testTypedDefvar() { Assert.equals(8, BasicTestCase.myInt); }