expect macro for reader macros
This commit is contained in:
@@ -641,9 +641,17 @@ class Kiss {
|
||||
};
|
||||
};
|
||||
|
||||
copy.macros["expect"] = (wholeExp:ReaderExp, exps:Array<ReaderExp>, k:KissState) -> {
|
||||
wholeExp.checkNumArgs(3, null, "(expect <stream> <description> <stream method> <args...>)");
|
||||
var b = wholeExp.expBuilder();
|
||||
var streamSymbol = exps.shift();
|
||||
b.callField("expect", streamSymbol, [exps.shift(), b.callSymbol("lambda", [b.list([]), b.callField(Prelude.symbolNameValue(exps.shift()), streamSymbol, exps)])]);
|
||||
};
|
||||
|
||||
// TODO should this also be in forHScript()?
|
||||
// In macro evaluation,
|
||||
copy.macros.remove("eval");
|
||||
// BECAUSE it is provided as a function instead.
|
||||
|
||||
return copy;
|
||||
}
|
||||
|
@@ -39,6 +39,7 @@ abstract List<T>(Array<T>) from Array<T> to Array<T> {
|
||||
return v;
|
||||
}
|
||||
|
||||
// TODO deleting these should be fine, because the haxe Array functions already allow negative arguments
|
||||
public function insert(idx:Int, v:T) {
|
||||
this.insert(realIndex(idx), v);
|
||||
}
|
||||
|
@@ -294,7 +294,7 @@ class Reader {
|
||||
}
|
||||
}
|
||||
|
||||
public static function readExpArray(stream:Stream, end:String, k:KissState, startingPos=null):Array<ReaderExp> {
|
||||
public static function readExpArray(stream:Stream, end:String, k:KissState, allowEof=false, startingPos=null):Array<ReaderExp> {
|
||||
var array = [];
|
||||
if (startingPos == null)
|
||||
startingPos = stream.position();
|
||||
@@ -306,7 +306,8 @@ class Reader {
|
||||
case Some(exp):
|
||||
array.push(exp);
|
||||
case None:
|
||||
throw new StreamError(startingPos, 'Ran out of expressions before $end was found.');
|
||||
if (allowEof) return array;
|
||||
else throw new StreamError(startingPos, 'Ran out of expressions before $end was found.');
|
||||
}
|
||||
} catch (s:UnmatchedBracketSignal) {
|
||||
if (s.type == end)
|
||||
|
Reference in New Issue
Block a user