Browse Source

* Patch from Graeme Geldenhuys (bug 17237) extending scanner to report EOL and TAB

git-svn-id: trunk@15877 -
michael 15 years ago
parent
commit
a848b6fde2
2 changed files with 29 additions and 9 deletions
  1. 6 4
      packages/fcl-passrc/src/pparser.pp
  2. 23 5
      packages/fcl-passrc/src/pscanner.pp

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

@@ -92,16 +92,18 @@ uses Classes;
 var
   IsIdentStart: array[char] of boolean;
 
-type
+const
+  WhitespaceTokensToIgnore = [tkWhitespace, tkComment, tkLineEnding, tkTab];
 
+type
   TDeclType = (declNone, declConst, declResourcestring, declType, declVar, declThreadvar, declProperty);
 
   TProcType = (ptProcedure, ptFunction, ptOperator, ptConstructor, ptDestructor,
                ptClassProcedure, ptClassFunction);
 
                
-  TExprKind = (ek_Normal, ek_PropertyIndex);               
-               
+  TExprKind = (ek_Normal, ek_PropertyIndex);
+
   { TPasParser }
 
   TPasParser = class
@@ -291,7 +293,7 @@ begin
     try
       repeat
         FCurToken := Scanner.FetchToken;
-      until not (FCurToken in [tkWhitespace, tkComment]);
+      until not (FCurToken in WhitespaceTokensToIgnore);
     except
       on e: EScannerError do
         raise EParserError.Create(e.Message,

+ 23 - 5
packages/fcl-passrc/src/pscanner.pp

@@ -138,7 +138,10 @@ type
     tkvar,
     tkwhile,
     tkwith,
-    tkxor);
+    tkxor,
+    tkLineEnding,
+    tkTab
+    );
 
   TLineReader = class
   public
@@ -339,7 +342,9 @@ const
     'var',
     'while',
     'with',
-    'xor'
+    'xor',
+    'LineEnding',
+    'Tab'
   );
 
 function FilenameIsAbsolute(const TheFilename: string):boolean;
@@ -675,9 +680,9 @@ begin
     #0:         // Empty line
       begin
         FetchLine;
-        Result := tkWhitespace;
+        Result := tkLineEnding;
       end;
-    #9, ' ':
+    ' ':
       begin
         Result := tkWhitespace;
         repeat
@@ -688,7 +693,20 @@ begin
               FCurToken := Result;
               exit;
             end;
-        until not (TokenStr[0] in [#9, ' ']);
+        until not (TokenStr[0] in [' ']);
+      end;
+    #9:
+      begin
+        Result := tkTab;
+        repeat
+          Inc(TokenStr);
+          if TokenStr[0] = #0 then
+            if not FetchLine then
+            begin
+              FCurToken := Result;
+              exit;
+            end;
+        until not (TokenStr[0] in [#9]);
       end;
     '#', '''':
       Result:=DoFetchTextToken;