From bce35bc6c0952cf6130b06d9f7663a57c8545ae5 Mon Sep 17 00:00:00 2001 From: Nat Quayle Nelson Date: Sun, 24 Jan 2021 17:25:15 -0700 Subject: [PATCH] raw strings --- src/kiss/Reader.hx | 4 +++- src/kiss/Stream.hx | 2 +- src/test/cases/BasicTestCase.hx | 4 ++++ src/test/cases/BasicTestCase.kiss | 6 +++++- 4 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/kiss/Reader.hx b/src/kiss/Reader.hx index 78a8271..0e04e2e 100644 --- a/src/kiss/Reader.hx +++ b/src/kiss/Reader.hx @@ -47,7 +47,9 @@ class Reader { readTable["("] = (stream, k) -> CallExp(assertRead(stream, k), readExpArray(stream, ")", k)); readTable["["] = (stream, k) -> ListExp(readExpArray(stream, "]", k)); - readTable["\""] = (stream, k) -> StrExp(stream.expect("closing \"", () -> stream.takeUntilAndDrop("\""))); + readTable['"'] = readString; + readTable["#"] = readRawString; + readTable["/*"] = (stream, k) -> { stream.takeUntilAndDrop("*/"); null; diff --git a/src/kiss/Stream.hx b/src/kiss/Stream.hx index fd4ea02..fdd2853 100644 --- a/src/kiss/Stream.hx +++ b/src/kiss/Stream.hx @@ -76,7 +76,7 @@ class Stream { var lineLengths = []; /** Every drop call should end up calling dropChars() or the position tracker will be wrong. **/ - private function dropChars(count:Int) { + public function dropChars(count:Int) { for (idx in 0...count) { switch (content.charAt(idx)) { case "\n": diff --git a/src/test/cases/BasicTestCase.hx b/src/test/cases/BasicTestCase.hx index 501ce12..f6d687a 100644 --- a/src/test/cases/BasicTestCase.hx +++ b/src/test/cases/BasicTestCase.hx @@ -273,6 +273,10 @@ class BasicTestCase extends Test { function testPatternLets() { _testPatternLets(); } + + function testRawString() { + _testRawString(); + } } class BasicObject { diff --git a/src/test/cases/BasicTestCase.kiss b/src/test/cases/BasicTestCase.kiss index 3155f6e..a812544 100644 --- a/src/test/cases/BasicTestCase.kiss +++ b/src/test/cases/BasicTestCase.kiss @@ -454,4 +454,8 @@ (Assert.fail)) (unlessLet [(Some (or 5 6)) some5] (print "something else went wrong!") - (Assert.fail)))) \ No newline at end of file + (Assert.fail)))) + +(defun _testRawString [] + (Assert.equals #| "\\" |# #"\"#) + (Assert.equals #| "\"#" |# ##""#"##)) \ No newline at end of file