Index: src/Boo.Lang.Parser/wsaboo.g =================================================================== --- wsaboo.g (revision 2702) +++ wsaboo.g (working copy) @@ -1312,28 +1312,30 @@ try_stmt returns [TryStatement s] { s = null; - Block sblock = null; Block eblock = null; + Block lastBlock = null; }: - t:TRY { s = new TryStatement(SourceLocationFactory.ToLexicalInfo(t)); } - compound_stmt[s.ProtectedBlock] + t:TRY { s = new TryStatement(SourceLocationFactory.ToLexicalInfo(t)); } begin + {s.ProtectedBlock = new Block();} block[s.ProtectedBlock.Statements] { lastBlock = s.ProtectedBlock; } ( - exception_handler[s] + lastBlock = exception_handler[s] )* ( - etoken:ENSURE { eblock = new Block(SourceLocationFactory.ToLexicalInfo(etoken)); } - compound_stmt[eblock] - { s.EnsureBlock = eblock; } + etoken:ENSURE { eblock = new Block(SourceLocationFactory.ToLexicalInfo(etoken)); } begin + block[eblock.Statements] + { s.EnsureBlock = lastBlock = eblock; } )? + end[lastBlock] ; protected -exception_handler [TryStatement t] +exception_handler [TryStatement t] returns [Block lastBlock] { ExceptionHandler eh = null; TypeReference tr = null; + lastBlock = null; }: - c:EXCEPT (x:ID (AS tr=type_reference)?)? + c:EXCEPT (x:ID (AS tr=type_reference)?)? begin { eh = new ExceptionHandler(SourceLocationFactory.ToLexicalInfo(c)); @@ -1343,9 +1345,11 @@ eh.Declaration.Name = x.getText(); eh.Declaration.Type = tr; } + eh.Block = new Block(SourceLocationFactory.ToLexicalInfo(c)); } - compound_stmt[eh.Block] + block[eh.Block.Statements] { + lastBlock = eh.Block; t.ExceptionHandlers.Add(eh); } ; Index: tests/testcases/parser/wsa/try-1.boo =================================================================== --- try-1.boo (revision 2715) +++ try-1.boo (working copy) @@ -6,7 +6,6 @@ """ try: raise System.Exception('throw') -end except ex: Console.WriteLine('catch') end Index: tests/testcases/parser/wsa/try-2.boo =================================================================== --- try-2.boo (revision 2715) +++ try-2.boo (working copy) @@ -6,7 +6,6 @@ """ try: raise System.Exception('throw') -end except: Console.WriteLine('catch') end Index: tests/testcases/parser/wsa/try-3.boo =================================================================== --- try-3.boo (revision 0) +++ try-3.boo (revision 0) @@ -0,0 +1,15 @@ +""" +try: + raise System.Exception('throw') +except: + Console.WriteLine('catch') +ensure: + Console.WriteLine('finally') +""" +try: + raise System.Exception('throw') +except: + Console.WriteLine('catch') +ensure: + Console.WriteLine('finally') +end