Skip to content

Commit 30b01ca

Browse files
committed
added parsing of constant type params
1 parent 9ef5811 commit 30b01ca

File tree

4 files changed

+30
-12
lines changed

4 files changed

+30
-12
lines changed

hscript/Expr.hx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ enum CType {
8080
CTParent( t : CType );
8181
CTOpt( t : CType );
8282
CTNamed( n : String, t : CType );
83+
CTExpr( e : Expr ); // for type parameters only
8384
}
8485

8586
#if hscriptPos

hscript/Macro.hx

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ class Macro {
9090
}
9191
}
9292

93-
function map < T, R > ( a : Array<T>, f : T -> R ) : Array<R> {
93+
function map<T,R>( a : Array<T>, f : T -> R ) : Array<R> {
9494
var b = new Array();
9595
for( x in a )
9696
b.push(f(x));
@@ -102,9 +102,13 @@ class Macro {
102102
case CTOpt(t): TOptional(convertType(t));
103103
case CTPath(pack, args):
104104
var params = [];
105-
if( args != null )
105+
if( args != null ) {
106106
for( t in args )
107-
params.push(TPType(convertType(t)));
107+
params.push(switch( t ) {
108+
case CTExpr(e): TPExpr(convert(e));
109+
default: TPType(convertType(t));
110+
});
111+
}
108112
TPath({
109113
pack : pack,
110114
name : pack.pop(),
@@ -127,6 +131,8 @@ class Macro {
127131
tf.push( { name : f.name, meta : meta, doc : null, access : [], kind : FVar(convertType(f.t), null), pos : p } );
128132
}
129133
TAnonymous(tf);
134+
case CTExpr(_):
135+
throw "assert";
130136
};
131137
}
132138

hscript/Parser.hx

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -916,7 +916,13 @@ class Parser {
916916
if( op == "<" ) {
917917
params = [];
918918
while( true ) {
919-
params.push(parseType());
919+
switch( token() ) {
920+
case TConst(c):
921+
params.push(CTExpr(mk(EConst(c))));
922+
case tk:
923+
push(tk);
924+
params.push(parseType());
925+
}
920926
t = token();
921927
switch( t ) {
922928
case TComma: continue;
@@ -942,8 +948,8 @@ class Parser {
942948
}
943949
return parseTypeNext(CTPath(path, params));
944950
case TPOpen:
945-
var a = token(),
946-
b = token();
951+
var a = token();
952+
var b = token();
947953

948954
push(b);
949955
push(a);

hscript/Printer.hx

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,8 @@ class Printer {
9898
add("(");
9999
type(t);
100100
add(")");
101+
case CTExpr(e):
102+
expr(e);
101103
}
102104
}
103105

@@ -108,18 +110,21 @@ class Printer {
108110
}
109111
}
110112

113+
function addConst( c : Const ) {
114+
switch( c ) {
115+
case CInt(i): add(i);
116+
case CFloat(f): add(f);
117+
case CString(s): add('"'); add(s.split('"').join('\\"').split("\n").join("\\n").split("\r").join("\\r").split("\t").join("\\t")); add('"');
118+
}
119+
}
120+
111121
function expr( e : Expr ) {
112122
if( e == null ) {
113123
add("??NULL??");
114124
return;
115125
}
116126
switch( #if hscriptPos e.e #else e #end ) {
117-
case EConst(c):
118-
switch( c ) {
119-
case CInt(i): add(i);
120-
case CFloat(f): add(f);
121-
case CString(s): add('"'); add(s.split('"').join('\\"').split("\n").join("\\n").split("\r").join("\\r").split("\t").join("\\t")); add('"');
122-
}
127+
case EConst(c): addConst(c);
123128
case EIdent(v):
124129
add(v);
125130
case EVar(n, t, e):

0 commit comments

Comments
 (0)