From 521c8b3d5b4956706a1ca449c7d50001aed5c033 Mon Sep 17 00:00:00 2001 From: Nicolas Cannasse Date: Wed, 9 Jul 2008 11:09:28 +0000 Subject: [PATCH] fixed : isBlock tells if expr ends with } --- hscript/Parser.hx | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/hscript/Parser.hx b/hscript/Parser.hx index f44fdd9..c5d193e 100644 --- a/hscript/Parser.hx +++ b/hscript/Parser.hx @@ -106,19 +106,30 @@ class Parser { return null; } + function isBlock(e) { + return switch( e ) { + case EBlock(_): true; + case EFunction(_,e,_): isBlock(e); + case EVar(_,e): e != null && isBlock(e); + case EIf(_,e1,e2): if( e2 != null ) isBlock(e2) else isBlock(e1); + case EBinop(_,_,e): isBlock(e); + case EUnop(_,prefix,e): !prefix && isBlock(e); + case EWhile(_,e): isBlock(e); + case EFor(_,_,e): isBlock(e); + case EReturn(e): e != null && isBlock(e); + default: false; + } + } + function parseFullExpr(s) { var e = parseExpr(s); var tk = token(s); - if( tk != TSemicolon && tk != TEof ) - switch( e ) { - case EBlock(_): tokens.add(tk); - case EFunction(_,e,_): - switch(e) { - case EBlock(_): tokens.add(tk); - default: unexpected(tk); - } - default: unexpected(tk); - } + if( tk != TSemicolon && tk != TEof ) { + if( isBlock(e) ) + tokens.add(tk); + else + unexpected(tk); + } return e; }