instead of removing type annotations from hscript, allow them in the parser
This commit is contained in:
@@ -337,7 +337,9 @@ class Helpers {
|
||||
#if macrotest
|
||||
Prelude.print("Compile-time hscript: " + code);
|
||||
#end
|
||||
// Need parser external to the KissInterp to wrap parsing in an informative try-catch
|
||||
var parser = new Parser();
|
||||
parser.allowTypes = true;
|
||||
if (interps.length == 0) {
|
||||
var interp = new KissInterp();
|
||||
interp.variables.set("read", Reader.assertRead.bind(_, k));
|
||||
@@ -484,28 +486,6 @@ class Helpers {
|
||||
return def.withPosOf(exp);
|
||||
}
|
||||
|
||||
public static function removeTypeAnnotations(exp:ReaderExp):ReaderExp {
|
||||
var def = switch (exp.def) {
|
||||
case Symbol(_) | StrExp(_) | RawHaxe(_) | Quasiquote(_):
|
||||
exp.def;
|
||||
case CallExp(func, callArgs):
|
||||
CallExp(removeTypeAnnotations(func), callArgs.map(removeTypeAnnotations));
|
||||
case ListExp(elements):
|
||||
ListExp(elements.map(removeTypeAnnotations));
|
||||
case TypedExp(type, innerExp):
|
||||
innerExp.def;
|
||||
case MetaExp(meta, innerExp):
|
||||
MetaExp(meta, removeTypeAnnotations(innerExp));
|
||||
case FieldExp(field, innerExp):
|
||||
FieldExp(field, removeTypeAnnotations(innerExp));
|
||||
case KeyValueExp(keyExp, valueExp):
|
||||
KeyValueExp(removeTypeAnnotations(keyExp), removeTypeAnnotations(valueExp));
|
||||
default:
|
||||
throw CompileError.fromExp(exp, 'cannot remove type annotations');
|
||||
};
|
||||
return def.withPosOf(exp);
|
||||
}
|
||||
|
||||
// Return convenient functions for succinctly making new ReaderExps that link back to an original exp's
|
||||
// position in source code
|
||||
public static function expBuilder(posRef:ReaderExp) {
|
||||
|
@@ -283,8 +283,6 @@ class Kiss {
|
||||
// Bind the table arguments of this function for easy recursive calling/passing
|
||||
var convert = readerExpToHaxeExpr.bind(_, k);
|
||||
|
||||
if (k.hscript)
|
||||
exp = Helpers.removeTypeAnnotations(exp);
|
||||
|
||||
var none = EBlock([]).withMacroPosOf(exp);
|
||||
|
||||
|
@@ -19,6 +19,8 @@ class KissInterp extends Interp {
|
||||
public function new(nullForUnknownVar = false) {
|
||||
super();
|
||||
|
||||
parser.allowTypes = true;
|
||||
|
||||
this.nullForUnknownVar = nullForUnknownVar;
|
||||
|
||||
variables.set("Reflect", Reflect);
|
||||
|
@@ -130,7 +130,6 @@ class Macros {
|
||||
var thenExp = exps.shift();
|
||||
var elseExp = if (exps.length > 0) exps.shift(); else b.none();
|
||||
|
||||
var parser = new Parser();
|
||||
var conditionInterp = new KissInterp(true);
|
||||
var conditionStr = Reader.toString(conditionExp.def);
|
||||
for (flag => value in Context.getDefines()) {
|
||||
@@ -144,8 +143,7 @@ class Macros {
|
||||
#if test
|
||||
Prelude.print("#if condition hscript: " + hscriptStr);
|
||||
#end
|
||||
var conditionHScript = parser.parseString(hscriptStr);
|
||||
return if (Prelude.truthy(conditionInterp.execute(conditionHScript))) {
|
||||
return if (Prelude.truthy(conditionInterp.evalHaxe(hscriptStr))) {
|
||||
#if test
|
||||
Prelude.print("using thenExp");
|
||||
#end
|
||||
@@ -186,7 +184,6 @@ class Macros {
|
||||
|
||||
var caseExp = b.callSymbol("case", caseArgs);
|
||||
|
||||
var parser = new Parser();
|
||||
var caseInterp = new KissInterp();
|
||||
var caseStr = Reader.toString(caseExp.def);
|
||||
for (matchBodySymbol in matchBodySymbols) {
|
||||
@@ -201,8 +198,7 @@ class Macros {
|
||||
#if test
|
||||
Prelude.print("#case hscript: " + hscriptStr);
|
||||
#end
|
||||
var caseHScript = parser.parseString(hscriptStr);
|
||||
return caseInterp.execute(caseHScript);
|
||||
return caseInterp.evalHaxe(caseStr);
|
||||
} catch (e) {
|
||||
throw CompileError.fromExp(caseExp, '#case evaluation threw error $e');
|
||||
}
|
||||
|
Reference in New Issue
Block a user