Type Parameters parsing for "ENew"
it now parses type parameters on "ENew", ignored by the interpreter. Example: "var a = new Object<Float>();
This commit is contained in:
+2
-1
@@ -69,7 +69,7 @@ enum Expr {
|
||||
EReturn( ?e : Expr );
|
||||
EArray( e : Expr, index : Expr );
|
||||
EArrayDecl( e : Array<Expr>, ?wantedType: CType );
|
||||
ENew( cl : String, params : Array<Expr> );
|
||||
ENew( cl : String, params : Array<Expr>, ?paramType:Array<CType> );
|
||||
EThrow( e : Expr );
|
||||
ETry( e : Expr, v : String, t : Null<CType>, ecatch : Expr );
|
||||
EObject( fl : Array<ObjectField> );
|
||||
@@ -118,6 +118,7 @@ enum CType {
|
||||
CTParent( t : CType );
|
||||
CTOpt( t : CType );
|
||||
CTNamed( n : String, t : CType );
|
||||
CTExpr( e : Expr ); // for type parameters only
|
||||
}
|
||||
|
||||
#if hscriptPos
|
||||
|
||||
+1
-1
@@ -1066,7 +1066,7 @@ class Interp {
|
||||
} else {
|
||||
return arr[index];
|
||||
}
|
||||
case ENew(cl, params):
|
||||
case ENew(cl, params, _):
|
||||
return cnew(cl, makeArgs(params));
|
||||
case EThrow(e):
|
||||
throw expr(e);
|
||||
|
||||
+43
-2
@@ -1096,12 +1096,47 @@ class Parser {
|
||||
mk(EReturn(e),p1,if( e == null ) tokenMax else pmax(e));
|
||||
case "new":
|
||||
var a = [];
|
||||
var params:Null<Array<CType>> = null;
|
||||
a.push(getIdent());
|
||||
while( true ) {
|
||||
var tk = token();
|
||||
switch( tk ) {
|
||||
case TDot:
|
||||
a.push(getIdent());
|
||||
case TOp(op) :
|
||||
if( op == '<' ) {
|
||||
params = [];
|
||||
while(true) {
|
||||
switch(token()) {
|
||||
case TConst(c):
|
||||
params.push(CTExpr(mk(EConst(c))));
|
||||
case tk:
|
||||
push(tk);
|
||||
params.push(parseType());
|
||||
}
|
||||
tk = token();
|
||||
switch(tk) {
|
||||
case TComma: continue;
|
||||
case TOp(op):
|
||||
if( op == ">") break;
|
||||
if( op.charCodeAt(0) == ">".code ) {
|
||||
#if hscriptPos
|
||||
tokens.add({ t : TOp(op.substr(1)), min : tokenMax - op.length - 1, max : tokenMax });
|
||||
#else
|
||||
tokens.add(TOp(op.substr(1)));
|
||||
#end
|
||||
break;
|
||||
}
|
||||
default:
|
||||
}
|
||||
unexpected(tk);
|
||||
break;
|
||||
}
|
||||
}
|
||||
else {
|
||||
unexpected(tk);
|
||||
break;
|
||||
}
|
||||
case TPOpen:
|
||||
break;
|
||||
default:
|
||||
@@ -1110,7 +1145,7 @@ class Parser {
|
||||
}
|
||||
}
|
||||
var args = parseExprList(TPClose);
|
||||
mk(ENew(a.join("."), args), p1);
|
||||
mk(ENew(a.join("."), args, params), p1);
|
||||
case "throw":
|
||||
var e = parseExpr();
|
||||
mk(EThrow(e),p1,pmax(e));
|
||||
@@ -1344,7 +1379,13 @@ class Parser {
|
||||
if( op == "<" ) {
|
||||
params = [];
|
||||
while( true ) {
|
||||
params.push(parseType());
|
||||
switch( token() ) {
|
||||
case TConst(c):
|
||||
params.push(CTExpr(mk(EConst(c))));
|
||||
case tk:
|
||||
push(tk);
|
||||
params.push(parseType());
|
||||
}
|
||||
t = token();
|
||||
switch( t ) {
|
||||
case TComma: continue;
|
||||
|
||||
+14
-2
@@ -98,6 +98,8 @@ class Printer {
|
||||
add("(");
|
||||
type(t);
|
||||
add(")");
|
||||
case CTExpr(e):
|
||||
expr(e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -291,8 +293,18 @@ class Printer {
|
||||
expr(e);
|
||||
}
|
||||
add("]");
|
||||
case ENew(cl, args):
|
||||
add("new " + cl + "(");
|
||||
case ENew(cl, args, params):
|
||||
add("new " + cl);
|
||||
if(params != null) {
|
||||
add("<");
|
||||
var first = true;
|
||||
for( p in params ) {
|
||||
if( first ) first = false else add(", ");
|
||||
type(p);
|
||||
}
|
||||
add(">");
|
||||
}
|
||||
add("(");
|
||||
var first = true;
|
||||
for( e in args ) {
|
||||
if( first ) first = false else add(", ");
|
||||
|
||||
Reference in New Issue
Block a user