Browse Source

passrc: added parsing label marks in the code blocks

git-svn-id: trunk@15903 -
dmitry 15 years ago
parent
commit
9b9a3ec725
2 changed files with 48 additions and 6 deletions
  1. 14 0
      packages/fcl-passrc/src/pastree.pp
  2. 34 6
      packages/fcl-passrc/src/pparser.pp

+ 14 - 0
packages/fcl-passrc/src/pastree.pp

@@ -759,6 +759,7 @@ type
   TPasImplTry = class;
   TPasImplExceptOn = class;
   TPasImplRaise = class;
+  TPasImplLabelMark = class;
 
   { TPasImplBlock }
 
@@ -782,6 +783,7 @@ type
     function AddTry: TPasImplTry;
     function AddExceptOn(const VarName, TypeName: string): TPasImplExceptOn;
     function AddRaise: TPasImplRaise;
+    function AddLabelMark(const Id: string): TPasImplLabelMark;
     function CloseOnSemicolon: boolean; virtual;
   public
     Elements: TList;    // TPasImplElement objects
@@ -958,6 +960,11 @@ type
     procedure Visit(obj: TPasElement); virtual;
   end;
 
+  TPasImplLabelMark = class(TPasImplElement)
+  public
+    LabelId:  AnsiString;
+  end;
+
 const
   AccessNames: array[TArgumentAccess] of string[6] = ('', 'const ', 'var ', 'out ');
   AllVisibilities: TPasMemberVisibilities =
@@ -1681,6 +1688,13 @@ begin
   AddElement(Result);
 end;
 
+function TPasImplBlock.AddLabelMark(const Id: string): TPasImplLabelMark;
+begin
+  Result:=TPasIMplLabelMark.Create('', Self);
+  Result.LabelId:=Id;
+  AddElement(Result);
+end;
+
 function TPasImplBlock.CloseOnSemicolon: boolean;
 begin
   Result:=false;

+ 34 - 6
packages/fcl-passrc/src/pparser.pp

@@ -2912,13 +2912,41 @@ begin
       end;
     else
       UngetToken;
-      Command:=ParseCommand;
-      //WriteLn(i,'COMMAND="',Command,'" Token=',CurTokenString);
+
+      Command:='';
+
+      NextToken;
+      // testing for label mark
+      if CurToken=tkIdentifier then
+      begin
+        Command:=CurTokenText;
+        NextToken;
+        // testing for the goto mark
+        if CurToken=tkColon then
+        begin
+          CurBlock.AddLabelMark(Command);
+        end
+        else
+        begin
+          Command:='';
+          UngetToken;
+          UngetToken;
+        end;
+      end else
+        UngetToken;
+
+
       if Command='' then
-        ParseExc(SParserSyntaxError);
-      CmdElem:=CurBlock.AddCommand(Command);
-      if NewImplElement=nil then NewImplElement:=CmdElem;
-      if CloseStatement(false) then break;
+      begin
+        // parsing the assignment statement or call expression
+        Command:=ParseCommand;
+        //WriteLn(i,'COMMAND="',Command,'" Token=',CurTokenString);
+        if Command='' then
+          ParseExc(SParserSyntaxError);
+        CmdElem:=CurBlock.AddCommand(Command);
+        if NewImplElement=nil then NewImplElement:=CmdElem;
+        if CloseStatement(false) then break;
+      end;
     end;
   end;
 end;