SpookyFM / hscript

Automatically exported from code.google.com/p/hscript
0 stars 0 forks source link

empty function cause parsing error #2

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
freewizard@FWDev-Pro matrix $ cat Bug.hx 
class Bug {
    public static function main():Void {
        (new hscript.Parser()).parseString("function ok(){ return 0; }\nok();");
        (new hscript.Parser()).parseString("function bug(){ \n }\nbug();");
    }
}

freewizard@FWDev-Pro matrix $ haxe -lib hscript -neko b.n -main Bug.hx && neko 
b.n 
Called from ? line 1
Called from Bug.hx line 4
Called from hscript/Parser.hx line 90
Called from hscript/Parser.hx line 108
Called from hscript/Parser.hx line 141
Called from hscript/Parser.hx line 114
Uncaught exception - EUnexpected(bug 
)

What is the expected output? What do you see instead?
empty function should be supported

What version of the product are you using? On what operating system?
HaXe 2.0.7 
hscript 1.5.2

Please provide any additional information below.

Original issue reported on code.google.com by freewiz...@gmail.com on 21 Feb 2011 at 1:45

GoogleCodeExporter commented 9 years ago
I'm using a workaround below, break some other cases (empty json object) however

--- 1,5,2/hscript/Parser.hx 2011-02-22 20:43:28.000000000 +0800
+++ 1,5,2,1/hscript/Parser.hx   2011-02-22 20:49:23.000000000 +0800
@@ -195,7 +195,7 @@
            tk = token();
            switch( tk ) {
            case TBrClose:
-               return parseExprNext(EObject([]));
+               return parseExprNext(EBlock([]));
            case TId(id):
                var tk2 = token();
                tokens.add(tk2);

Original comment by freewiz...@gmail.com on 22 Feb 2011 at 1:40

GoogleCodeExporter commented 9 years ago
This issue was closed by revision r35.

Original comment by ncanna...@gmail.com on 24 Feb 2011 at 6:58

GoogleCodeExporter commented 9 years ago
Nicolas, I suppose the test case and expect result should be:
        test("(function(){})()", null);

My workaround in Interp.hx in addition to r35:
        case EFunction(params,fexpr,name):
            var capturedLocals = duplicate(locals);
            var me = this;
            var f = function(args:Array<Dynamic>) {
                if( args.length != params.length ) throw "Invalid number of parameters";
                var old = me.locals;
                me.locals = me.duplicate(capturedLocals);
                for( i in 0...params.length )
                    me.locals.set(params[i],{ r : args[i] });
                var r = null;
                try {
-                   r = me.exprReturn(fexpr);
+                   switch(fexpr) {
+                       case EObject(v): r = (0==v.length) ? null : me.exprReturn(fexpr);
+                       default: r = me.exprReturn(fexpr);
+                   }
                } catch( e : Dynamic ) {

Original comment by freewiz...@gmail.com on 24 Feb 2011 at 7:39