standardize reader errors
This commit is contained in:
@@ -99,9 +99,8 @@ class Reader {
|
|||||||
public static function nextToken(stream:Stream, expect:String) {
|
public static function nextToken(stream:Stream, expect:String) {
|
||||||
var tok = stream.expect(expect, () -> stream.takeUntilOneOf(terminators));
|
var tok = stream.expect(expect, () -> stream.takeUntilOneOf(terminators));
|
||||||
if (tok.length == 0) {
|
if (tok.length == 0) {
|
||||||
Sys.stderr().writeString('Kiss reader error!\n');
|
error(stream, 'Expected $expect');
|
||||||
Sys.stderr().writeString(stream.position().toPrint() + ': Expected $expect\n');
|
return null;
|
||||||
Sys.exit(1);
|
|
||||||
}
|
}
|
||||||
return tok;
|
return tok;
|
||||||
}
|
}
|
||||||
@@ -112,9 +111,7 @@ class Reader {
|
|||||||
case Some(exp):
|
case Some(exp):
|
||||||
exp;
|
exp;
|
||||||
case None:
|
case None:
|
||||||
Sys.stderr().writeString('Kiss reader error!\n');
|
error(stream, 'Ran out of Kiss expressions');
|
||||||
Sys.stderr().writeString(stream.position().toPrint() + ': Ran out of Kiss expressions\n');
|
|
||||||
Sys.exit(1);
|
|
||||||
return null;
|
return null;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -217,6 +214,35 @@ class Reader {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static function readString(stream:Stream, k:KissState) {
|
||||||
|
return StrExp(stream.expect("closing \"", () -> stream.takeUntilAndDrop("\"")));
|
||||||
|
}
|
||||||
|
|
||||||
|
static function readRawString(stream:Stream, k:KissState) {
|
||||||
|
var terminator = '"#';
|
||||||
|
do {
|
||||||
|
var next = stream.expect('# or "', () -> stream.peekChars(1));
|
||||||
|
switch (next) {
|
||||||
|
case "#":
|
||||||
|
terminator += "#";
|
||||||
|
stream.dropChars(1);
|
||||||
|
case '"':
|
||||||
|
stream.dropChars(1);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
error(stream, 'Invalid syntax for raw string. Delete $next');
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
} while (true);
|
||||||
|
return StrExp(stream.expect('closing $terminator', () -> stream.takeUntilAndDrop(terminator)));
|
||||||
|
}
|
||||||
|
|
||||||
|
static function error(stream:Stream, message:String) {
|
||||||
|
Sys.stderr().writeString('Kiss reader error!\n');
|
||||||
|
Sys.stderr().writeString(stream.position().toPrint() + ': $message\n');
|
||||||
|
Sys.exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
public static function toString(exp:ReaderExpDef) {
|
public static function toString(exp:ReaderExpDef) {
|
||||||
return switch (exp) {
|
return switch (exp) {
|
||||||
case CallExp(func, args):
|
case CallExp(func, args):
|
||||||
|
Reference in New Issue
Block a user