Fix comment at end of list problem
This commit is contained in:
@@ -97,6 +97,10 @@ class Kiss {
|
|||||||
Sys.println(err);
|
Sys.println(err);
|
||||||
Sys.exit(1);
|
Sys.exit(1);
|
||||||
return null; // Necessary for build() to compile
|
return null; // Necessary for build() to compile
|
||||||
|
} catch (err:UnmatchedBracketSignal) {
|
||||||
|
Sys.println(Stream.toPrint(err.position) + ': Unmatched ${err.type}');
|
||||||
|
Sys.exit(1);
|
||||||
|
return null;
|
||||||
} catch (err:Exception) {
|
} catch (err:Exception) {
|
||||||
throw err; // Re-throw haxe exceptions for precise stacks
|
throw err; // Re-throw haxe exceptions for precise stacks
|
||||||
}
|
}
|
||||||
|
@@ -10,6 +10,16 @@ typedef ReaderExp = {
|
|||||||
def:ReaderExpDef
|
def:ReaderExpDef
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class UnmatchedBracketSignal {
|
||||||
|
public var type:String;
|
||||||
|
public var position:Stream.Position;
|
||||||
|
|
||||||
|
public function new(type, position) {
|
||||||
|
this.type = type;
|
||||||
|
this.position = position;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
enum ReaderExpDef {
|
enum ReaderExpDef {
|
||||||
CallExp(func:ReaderExp, args:Array<ReaderExp>); // (f a1 a2...)
|
CallExp(func:ReaderExp, args:Array<ReaderExp>); // (f a1 a2...)
|
||||||
ListExp(exps:Array<ReaderExp>); // [v1 v2 v3]
|
ListExp(exps:Array<ReaderExp>); // [v1 v2 v3]
|
||||||
@@ -61,9 +71,17 @@ class Reader {
|
|||||||
// Lets you construct key-value pairs for map literals or for-loops
|
// Lets you construct key-value pairs for map literals or for-loops
|
||||||
readTable["=>"] = (stream:Stream) -> KeyValueExp(assertRead(stream, readTable), assertRead(stream, readTable));
|
readTable["=>"] = (stream:Stream) -> KeyValueExp(assertRead(stream, readTable), assertRead(stream, readTable));
|
||||||
|
|
||||||
|
readTable[")"] = (stream:Stream) -> {
|
||||||
|
stream.putBackString(")");
|
||||||
|
throw new UnmatchedBracketSignal(")", stream.position());
|
||||||
|
};
|
||||||
|
readTable["]"] = (stream:Stream) -> {
|
||||||
|
stream.putBackString("]");
|
||||||
|
throw new UnmatchedBracketSignal("]", stream.position());
|
||||||
|
};
|
||||||
|
|
||||||
// Because macro keys are sorted by length and peekChars(0) returns "", this will be used as the default reader macro:
|
// 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"));
|
readTable[""] = (stream) -> Symbol(nextToken(stream, "a symbol name"));
|
||||||
// TODO make - A macro for numerical negation
|
|
||||||
|
|
||||||
return readTable;
|
return readTable;
|
||||||
}
|
}
|
||||||
@@ -115,8 +133,16 @@ class Reader {
|
|||||||
var array = [];
|
var array = [];
|
||||||
while (!stream.startsWith(end)) {
|
while (!stream.startsWith(end)) {
|
||||||
stream.dropWhitespace();
|
stream.dropWhitespace();
|
||||||
if (!stream.startsWith(end))
|
if (!stream.startsWith(end)) {
|
||||||
array.push(assertRead(stream, readTable));
|
try {
|
||||||
|
array.push(assertRead(stream, readTable));
|
||||||
|
} catch (s:UnmatchedBracketSignal) {
|
||||||
|
if (s.type == end)
|
||||||
|
break;
|
||||||
|
else
|
||||||
|
throw s;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
stream.dropString(end);
|
stream.dropString(end);
|
||||||
return array;
|
return array;
|
||||||
|
9
kiss/src/test/cases/CommentAtEndOfListTestCase.hx
Normal file
9
kiss/src/test/cases/CommentAtEndOfListTestCase.hx
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
package test.cases;
|
||||||
|
|
||||||
|
import utest.Assert;
|
||||||
|
import utest.Test;
|
||||||
|
import kiss.Prelude;
|
||||||
|
import kiss.List;
|
||||||
|
|
||||||
|
@:build(kiss.Kiss.build("kiss/src/test/cases/CommentAtEndOfListTestCase.kiss"))
|
||||||
|
class CommentAtEndOfListTestCase extends Test {}
|
@@ -1,4 +1,4 @@
|
|||||||
(defun myFun []
|
(defun myFun []
|
||||||
(deflocal something 5)
|
(deflocal something 5)
|
||||||
// TODO This comment causes a hard-to-track-down error!
|
// This comment used to cause a hard-to-track-down error!
|
||||||
)
|
)
|
Reference in New Issue
Block a user