Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions polymod/hscript/_internal/Expr.hx
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ ECustom(msg:String);
DClass(c:ClassDecl);
DTypedef(c:TypeDecl);
DEnum(e:EnumDecl);
DInterface(e:InterfaceDecl);
}

typedef ModuleType =
Expand Down Expand Up @@ -189,6 +190,14 @@ typedef TypeDecl =
var t:CType;
}

typedef InterfaceDecl =
{
> ModuleType,
var extend:Array<CType>;
var fields:Array<FieldDecl>;
var isExtern:Bool;
}

typedef FieldDecl =
{
var name:String;
Expand Down
112 changes: 112 additions & 0 deletions polymod/hscript/_internal/Parser.hx
Original file line number Diff line number Diff line change
Expand Up @@ -1457,6 +1457,39 @@ class Parser
name: name,
fields: fields
});
case "interface":
var name = getIdent();
var params = parseParams();
var extend = [];

while (true)
{
var t = token();
switch (t)
{
case TId("extends"):
extend.push(parseType());
default:
push(t);
break;
}
}

var fields = [];
ensure(TBrOpen);
while (!maybe(TBrClose))
fields.push(parseInterfaceField());

return DInterface(
{
name: name,
meta: meta,
params: params,
isPrivate: isPrivate,
extend: extend,
fields: fields,
isExtern: isExtern,
});
default:
unexpected(TId(ident));
}
Expand Down Expand Up @@ -1545,6 +1578,85 @@ class Parser
return null;
}

function parseInterfaceField():FieldDecl
{
var meta = parseMetadata();
var access = [];
while (true)
{
var id = getIdent();
switch (id)
{
case "public":
access.push(APublic);
case "private":
access.push(APrivate);
case "static":
access.push(AStatic);
case "function":
var name = getIdent();
ensure(TPOpen);
var args = parseFunctionArgs();
var ret = null;
if (allowTypes)
{
var tk = token();
if (tk != TDoubleDot) push(tk);
else
ret = parseType();
}
ensure(TSemicolon);
return {
name: name,
meta: meta,
access: access,
kind: KFunction(
{
args: args,
expr: null,
ret: ret,
}),
};
case "var", "final":
var name = getIdent();
var get = null, set = null;
if (maybe(TPOpen))
{
get = getIdent();
ensure(TComma);
set = getIdent();
ensure(TPClose);
}
var type = maybe(TDoubleDot) ? parseType() : null;

if (type != null && type.match(CTAnon(_)))
{
maybe(TSemicolon);
}
else
ensure(TSemicolon);

return {
name: name,
meta: meta,
access: access,
kind: KVar(
{
get: get,
set: set,
type: type,
expr: null,
isfinal: (id == "final")
}),
};
default:
unexpected(TId(id));
break;
}
}
return null;
}

function parseEnumField():EnumFieldDecl
{
var name = getIdent();
Expand Down
1 change: 1 addition & 0 deletions polymod/hscript/_internal/PolymodInterpEx.hx
Original file line number Diff line number Diff line change
Expand Up @@ -1964,6 +1964,7 @@ class PolymodInterpEx extends Interp

registerScriptEnum(enumDecl);
case DTypedef(_):
case DInterface(_):
}
}
}
Expand Down