diff --git a/hscript/Bytes.hx b/hscript/Bytes.hx index 5b2a473..20619bf 100644 --- a/hscript/Bytes.hx +++ b/hscript/Bytes.hx @@ -124,6 +124,8 @@ class Bytes { #end bout.addByte(Type.enumIndex(e)); switch( e ) { + case EPackage(n): + // TODO case EImport(c): // TODO case EClass(_, _, _, _): diff --git a/hscript/Expr.hx b/hscript/Expr.hx index 87522c0..f313d19 100644 --- a/hscript/Expr.hx +++ b/hscript/Expr.hx @@ -79,6 +79,7 @@ enum Expr { EMeta( name : String, args : Array, e : Expr ); ECheckType( e : Expr, t : CType ); + EPackage( ?n:String ); EImport( c : String, ?asname:String, ?isUsing:Bool ); EClass( name:String, fields:Array, ?extend:String, interfaces:Array, ?isFinal:Bool, ?isPrivate:Bool ); EEnum( en:EnumDecl, ?isAbstract:Bool ); diff --git a/hscript/Interp.hx b/hscript/Interp.hx index b95d741..988a090 100644 --- a/hscript/Interp.hx +++ b/hscript/Interp.hx @@ -703,6 +703,7 @@ class Interp { var e = e.e; #end switch (e) { + case EPackage(_): case EClass(name, fields, extend, interfaces, isFinal): var oldName:String = name; var hasAlias:Bool = (setAlias != null && beforeAlias == oldName); diff --git a/hscript/Parser.hx b/hscript/Parser.hx index 4bb1473..ade871c 100644 --- a/hscript/Parser.hx +++ b/hscript/Parser.hx @@ -957,6 +957,15 @@ class Parser { var tk = token(); push(tk); mk(EFunction(inf.args, inf.body, name, inf.ret, nextIsPublic, nextIsStatic, nextIsOverride, nextIsPrivate, nextIsFinal, nextIsInline),p1,pmax(inf.body)); + case "package": + var tk = token(); + if(tk == TSemicolon) + mk(EPackage(null), p1); + + push(tk); + var pkg:String = parsePath().join('.'); + ensure(TSemicolon); + mk(EPackage(pkg), p1); case "import" | "using": var isUsing = id == "using"; var oldReadPos = readPos; @@ -1160,7 +1169,7 @@ class Parser { e = parseExpr(); } - mk(ECast(e, t)); + mk(ECast(e, t), p1); case "return": var tk = token(); push(tk); diff --git a/hscript/Printer.hx b/hscript/Printer.hx index deb6817..b671779 100644 --- a/hscript/Printer.hx +++ b/hscript/Printer.hx @@ -116,6 +116,11 @@ class Printer { return; } switch(Tools.expr(e)) { + case EPackage(n): + add('package'); + if(n != null) + add(' $n'); + add(';\n'); case EImport(c, n, u): add('${u ? 'using' : 'import'} $c'); if(n != null)