Quasiquote reader macros

This commit is contained in:
2020-12-09 16:48:24 -07:00
parent e62a65fb57
commit 1e989ac79c
7 changed files with 103 additions and 18 deletions

View File

@@ -15,8 +15,11 @@ class ReaderMacroTestCase extends Test {
}
function testMultipleInitiators() {
Assert.equals("a", ReaderMacroTestCase.str1);
Assert.equals("b", ReaderMacroTestCase.str2);
Assert.equals("c", ReaderMacroTestCase.str3);
Assert.equals("b", ReaderMacroTestCase.str1);
Assert.equals("c", ReaderMacroTestCase.str2);
}
function testQuasiquoteMacro() {
_testQuasiquoteMacro();
}
}

View File

@@ -12,9 +12,17 @@
(defvar mySum (pluppers fluffers buffers))
// Read a b c directly as strings
(defreadermacro ["a" "b" "c"] [stream] #|ReaderExp.StrExp(stream.expect("a, b, or c", function () stream.takeChars(1)))|#)
// Read b c directly as strings
(defreadermacro ["b" "c"] [stream] #|ReaderExp.StrExp(stream.expect("b, or c", function () stream.takeChars(1)))|#)
(defvar str1 a)
(defvar str2 b)
(defvar str3 c)
(defvar str1 b)
(defvar str2 c)
// rassert asserts the next expression without parens
(defreadermacro "rassert" [stream] `(assert ,(read stream)))
(defun _testQuasiquoteMacro []
rassert [5]
rassert b
rassert fluffers
(Assert.pass))