From f55215f53af7025431156cdf2a635d8f10e6a475 Mon Sep 17 00:00:00 2001 From: michael Date: Sun, 29 Jan 2017 16:36:06 +0000 Subject: [PATCH] * Case else without semicolon in front (bug ID 31284) git-svn-id: trunk@35362 - --- packages/fcl-passrc/src/pparser.pp | 7 +++++- packages/fcl-passrc/tests/tcstatements.pas | 26 ++++++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/packages/fcl-passrc/src/pparser.pp b/packages/fcl-passrc/src/pparser.pp index 1b6a049a73..530ab3d328 100644 --- a/packages/fcl-passrc/src/pparser.pp +++ b/packages/fcl-passrc/src/pparser.pp @@ -3938,9 +3938,14 @@ begin CloseBlock; CloseStatement(false); end; + // Case ... else without semicolon in front. + end else if (CurBlock is TPasImplCaseStatement) then + begin + UngetToken; + CloseStatement(False); + exit; end else if (CurBlock is TPasImplWhileDo) then begin - //if .. then while .. do smt else .. CloseBlock; UngetToken; end else if (CurBlock is TPasImplForLoop) then diff --git a/packages/fcl-passrc/tests/tcstatements.pas b/packages/fcl-passrc/tests/tcstatements.pas index a8b30322e7..ebab1f2ebd 100644 --- a/packages/fcl-passrc/tests/tcstatements.pas +++ b/packages/fcl-passrc/tests/tcstatements.pas @@ -96,6 +96,7 @@ Type Procedure TestCaseElseBlock2Assignments; Procedure TestCaseIfCaseElse; Procedure TestCaseIfElse; + Procedure TestCaseElseNoSemicolon; Procedure TestRaise; Procedure TestRaiseEmpty; Procedure TestRaiseAt; @@ -1206,6 +1207,31 @@ begin AssertNotNull('If statement has else block',TPasImplIfElse(S.Elements[0]).ElseBranch); end; +procedure TTestStatementParser.TestCaseElseNoSemicolon; +Var + C : TPasImplCaseOf; + S : TPasImplCaseStatement; + B : TPasImplbeginBlock; + +begin + DeclareVar('integer'); + TestStatement(['case a of','1 : dosomething;','2 : dosomethingmore','else','a:=1;','end;']); + C:=AssertStatement('Case statement',TpasImplCaseOf) as TpasImplCaseOf; + AssertNotNull('Have case expression',C.CaseExpr); + AssertExpression('Case expression',C.CaseExpr,pekIdent,'a'); + AssertEquals('case label count',3,C.Elements.Count); + S:=TPasImplCaseStatement(C.Elements[0]); + AssertEquals('case 1',1,S.Expressions.Count); + AssertExpression('Case With identifier 1',TPasExpr(S.Expressions[0]),pekNumber,'1'); + S:=TPasImplCaseStatement(C.Elements[1]); + AssertEquals('case 2',1,S.Expressions.Count); + AssertExpression('Case With identifier 1',TPasExpr(S.Expressions[0]),pekNumber,'2'); + AssertEquals('third is else',TPasImplCaseElse,TObject(C.Elements[2]).ClassType); + AssertNotNull('Have else branch',C.ElseBranch); + AssertEquals('Correct else branch class',TPasImplCaseElse,C.ElseBranch.ClassType); + AssertEquals('1 statements in else branch ',1,TPasImplCaseElse(C.ElseBranch).Elements.Count); +end; + procedure TTestStatementParser.TestRaise; Var