diff --git a/hscript/Expr.hx b/hscript/Expr.hx index d195b60..f050259 100644 --- a/hscript/Expr.hx +++ b/hscript/Expr.hx @@ -56,7 +56,7 @@ enum Expr { #end EConst( c : Const ); EIdent( v : String ); - EVar( n : String, ?t : CType, ?e : Expr, ?isPublic : Bool, ?isStatic : Bool, ?isPrivate : Bool ); + EVar( n : String, ?t : CType, ?e : Expr, ?isPublic : Bool, ?isStatic : Bool, ?isPrivate : Bool, ?isFinal : Bool, ?isInline : Bool ); EParent( e : Expr ); EBlock( e : Array ); EField( e : Expr, f : String , ?safe : Bool ); @@ -68,7 +68,7 @@ enum Expr { EFor( v : String, it : Expr, e : Expr, ?ithv: String); EBreak; EContinue; - EFunction( args : Array, e : Expr, ?name : String, ?ret : CType, ?isPublic : Bool, ?isStatic : Bool, ?isOverride : Bool, ?isPrivate : Bool, ?isFinal : Bool ); + EFunction( args : Array, e : Expr, ?name : String, ?ret : CType, ?isPublic : Bool, ?isStatic : Bool, ?isOverride : Bool, ?isPrivate : Bool, ?isFinal : Bool, ?isInline : Bool ); EReturn( ?e : Expr ); EArray( e : Expr, index : Expr ); EArrayDecl( e : Array, ?wantedType: CType ); diff --git a/hscript/Parser.hx b/hscript/Parser.hx index 354b846..522b583 100644 --- a/hscript/Parser.hx +++ b/hscript/Parser.hx @@ -600,6 +600,7 @@ class Parser { var nextIsPublic:Bool = false; var nextIsPrivate:Bool = false; var nextIsFinal:Bool = false; + var nextIsInline:Bool = false; var nextType:CType = null; function parseStructure(id, ?oldPos:Int) { #if hscriptPos @@ -653,6 +654,10 @@ class Parser { var str = parseStructure("private"); // override private nextIsOverride = false; str; + case TId("inline"): + var str = parseStructure("inline"); // override inline + nextIsOverride = false; + str; default: unexpected(nextToken); nextIsOverride = false; @@ -686,6 +691,10 @@ class Parser { var str = parseStructure("private"); // static private nextIsStatic = false; str; + case TId("inline"): + var str = parseStructure("inline"); // static inline + nextIsStatic = false; + str; default: unexpected(nextToken); nextIsStatic = false; @@ -723,6 +732,10 @@ class Parser { // var str = parseStructure("private"); // public private // nextIsPublic = false; // str; + case TId("inline"): + var str = parseStructure("inline"); // public inline + nextIsPublic = false; + str; default: unexpected(nextToken); nextIsPublic = false; @@ -756,26 +769,69 @@ class Parser { var str = parseStructure("class"); // private class nextIsPrivate = false; str; + case TId("inline"): + var str = parseStructure("inline"); // private inline + nextIsPrivate = false; + str; default: unexpected(nextToken); nextIsPrivate = false; null; } - case "var" | "final": + case "inline": + nextIsInline = true; var nextToken = token(); switch(nextToken) { - case TId("class"): - nextIsFinal = true; - var str = parseStructure("class"); // var class - nextIsFinal = false; - return str; + case TId("static"): + var str = parseStructure("static"); // inline static + nextIsInline = false; + str; case TId("function"): - nextIsFinal = true; - var str = parseStructure("function"); // var function - nextIsFinal = false; - return str; + var str = parseStructure("function"); // inline function + nextIsInline = false; + str; + case TId("override"): + var str = parseStructure("override"); // inline override + nextIsInline = false; + str; + case TId("var"): + var str = parseStructure("var"); // inline var + nextIsInline = false; + str; + case TId("final"): + var str = parseStructure("final"); // inline final + nextIsInline = false; + str; + case TId("class"): + var str = parseStructure("class"); // inline class + nextIsInline = false; + str; + case TId("private"): // inline private + var str = parseStructure("private"); // inline private + nextIsInline = false; + str; default: - push(nextToken); + unexpected(nextToken); + nextIsInline = false; + null; + } + case "var" | "final": + if(id == "final") { + var nextToken = token(); + switch(nextToken) { + case TId("class"): + nextIsFinal = true; + var str = parseStructure("class"); // final class + nextIsFinal = false; + return str; + case TId("function"): + nextIsFinal = true; + var str = parseStructure("function"); // final function + nextIsFinal = false; + return str; + default: + push(nextToken); + } } var ident = getIdent(); var tk = token(); @@ -793,7 +849,7 @@ class Parser { else push(tk); nextType = null; - mk(EVar(ident, t, e, nextIsPublic, nextIsStatic, nextIsPrivate), p1, (e == null) ? tokenMax : pmax(e)); + mk(EVar(ident, t, e, nextIsPublic, nextIsStatic, nextIsPrivate, id == "final", nextIsInline), p1, (e == null) ? tokenMax : pmax(e)); case "while": var econd = parseExpr(); var e = parseExpr(); @@ -828,9 +884,9 @@ class Parser { case "break": mk(EBreak); case "continue": mk(EContinue); case "else": unexpected(TId(id)); - case "inline": - if( !maybe(TId("function")) ) unexpected(TId("inline")); - return parseStructure("function"); + //case "inline": + // if( !maybe(TId("function")) ) unexpected(TId("inline")); + // return parseStructure("function"); case "function": var tk = token(); var name = null; @@ -842,7 +898,7 @@ class Parser { var tk = token(); push(tk); - mk(EFunction(inf.args, inf.body, name, inf.ret, nextIsPublic, nextIsStatic, nextIsOverride, nextIsPrivate, nextIsFinal),p1,pmax(inf.body)); + mk(EFunction(inf.args, inf.body, name, inf.ret, nextIsPublic, nextIsStatic, nextIsOverride, nextIsPrivate, nextIsFinal, nextIsInline),p1,pmax(inf.body)); case "import": var oldReadPos = readPos; var tk = token();