diff --git a/components/codetools/codeatom.pas b/components/codetools/codeatom.pas index 5e244c81c8..83d6afd74c 100644 --- a/components/codetools/codeatom.pas +++ b/components/codetools/codeatom.pas @@ -49,6 +49,7 @@ type cafEdgedBracketOpen, cafEdgedBracketClose, cafWord, cafEnd ); + TCommonAtomFlags = set of TCommonAtomFlag; const AllCommonAtomWords = [cafWord, cafEnd]; diff --git a/components/codetools/pascalparsertool.pas b/components/codetools/pascalparsertool.pas index 22321a926a..5cc2047e14 100644 --- a/components/codetools/pascalparsertool.pas +++ b/components/codetools/pascalparsertool.pas @@ -219,7 +219,7 @@ type function ReadWithStatement(ExceptionOnError, CreateNodes: boolean): boolean; function ReadOnStatement(ExceptionOnError, CreateNodes: boolean): boolean; procedure ReadVariableType; - procedure ReadHintModifiers; + procedure ReadHintModifiers(const AllowedAtomsBehind: TCommonAtomFlags = [cafSemicolon]); function ReadTilTypeOfProperty(PropertyNode: TCodeTreeNode): boolean; function ReadTilGetterOfProperty(PropertyNode: TCodeTreeNode): boolean; procedure ReadGUID; @@ -3290,7 +3290,12 @@ begin ReadConstant(true,false,[]); end; end; + end; + // optional: hint modifier + ReadHintModifiers([cafSemicolon,cafEqual]); + + if (ParentNode.Desc=ctnVarSection) then begin // optional: initial value if CurPos.Flag=cafEqual then if ParentNode.Parent.Desc in AllCodeSections+[ctnProcedure] then begin @@ -3298,9 +3303,6 @@ begin end; end; - // optional: hint modifier - ReadHintModifiers; - HasSemicolon:=false; if CurPos.Flag=cafSemicolon then begin // read ; @@ -3378,8 +3380,9 @@ begin EndChildNode; end; -procedure TPascalParserTool.ReadHintModifiers; -// after reading cursor is at next atom +procedure TPascalParserTool.ReadHintModifiers( + const AllowedAtomsBehind: TCommonAtomFlags); +// after reading the cursor is at next atom, e.g. the semicolon function IsModifier: boolean; var @@ -3419,7 +3422,7 @@ begin ReadConstant(true,false,[]); CurNode.EndPos:=CurPos.StartPos; end; - if not (CurPos.Flag in [cafSemicolon,cafRoundBracketClose]) then + if not (CurPos.Flag in AllowedAtomsBehind) then SaveRaiseCharExpectedButAtomFound(';'); EndChildNode; if CurPos.Flag<>cafSemicolon then @@ -4590,7 +4593,8 @@ function TPascalParserTool.KeyWordFuncTypeDefault: boolean; Low(integer)..High(integer) 'a'..'z' } -var SubRangeOperatorFound: boolean; +var + SubRangeOperatorFound: boolean; procedure ReadTillTypeEnd; begin @@ -4701,7 +4705,6 @@ begin SaveRaiseException(ctsInvalidType); end; end; - ReadHintModifiers; EndChildNode; Result:=true; end; @@ -4879,7 +4882,7 @@ begin {$IFDEF VerboseRecordCase} debugln(['TPascalParserTool.KeyWordFuncTypeRecordCase Hint modifier: "',GetAtom,'"']); {$ENDIF} - ReadHintModifiers; + ReadHintModifiers([cafSemicolon,cafRoundBracketClose]); CurNode.EndPos:=CurPos.EndPos; EndChildNode; // close variable definition end;