Browse Source

fcl-passrc: parse external typed const without expression if po_ExtConstWithoutExpr

git-svn-id: trunk@38884 -
Mattias Gaertner 7 years ago
parent
commit
3741378ec7
2 changed files with 44 additions and 6 deletions
  1. 43 5
      packages/fcl-passrc/src/pparser.pp
  2. 1 1
      packages/fcl-passrc/src/pscanner.pp

+ 43 - 5
packages/fcl-passrc/src/pparser.pp

@@ -3674,11 +3674,49 @@ begin
         ParseExc(nParserNoConstRangeAllowed,SParserNoConstRangeAllowed);
       end
     else if (Result.VarType<>nil)
-        and (po_ExtClassConstWithoutExpr in Options)
-        and (Parent is TPasClassType)
-        and TPasClassType(Parent).IsExternal
-        and (TPasClassType(Parent).ObjKind=okClass) then
-      // const without expression is allowed in external class
+        and (po_ExtConstWithoutExpr in Options) then
+      begin
+      if (Parent is TPasClassType)
+          and TPasClassType(Parent).IsExternal
+          and (TPasClassType(Parent).ObjKind=okClass) then
+        // typed const without expression is allowed in external class
+      else if CurToken=tkSemicolon then
+        begin
+        NextToken;
+        if CurTokenIsIdentifier('external') then
+          begin
+          // typed external const without expression is allowed
+          Result.IsConst:=true;
+          Include(Result.VarModifiers,vmExternal);
+          NextToken;
+          if CurToken in [tkString,tkIdentifier] then
+            begin
+            // external LibraryName;
+            // external LibraryName name ExportName;
+            // external name ExportName;
+            if not CurTokenIsIdentifier('name') then
+              Result.LibraryName:=DoParseExpression(Result);
+            if not CurTokenIsIdentifier('name') then
+              ParseExcSyntaxError;
+            NextToken;
+            if not (CurToken in [tkChar,tkString,tkIdentifier]) then
+              ParseExcTokenError(TokenInfos[tkString]);
+            Result.ExportName:=DoParseExpression(Parent);
+            end
+          else if CurToken=tkSemicolon then
+            // external;
+          else
+            ParseExcSyntaxError;
+          end
+        else
+          begin
+          UngetToken;
+          CheckToken(tkEqual);
+          end;
+        end
+      else
+        CheckToken(tkEqual);
+      end
     else
       CheckToken(tkEqual);
     UngetToken;

+ 1 - 1
packages/fcl-passrc/src/pscanner.pp

@@ -574,7 +574,7 @@ type
     po_CheckModeSwitches,    // error on unknown modeswitch with an error
     po_CheckCondFunction,    // error on unknown function in conditional expression, default: return '0'
     po_StopOnErrorDirective, // error on user $Error, $message error|fatal
-    po_ExtClassConstWithoutExpr, // allow const without expression in external class
+    po_ExtConstWithoutExpr,  // allow typed const without expression in external class and with external modifier
     po_StopOnUnitInterface   // parse only a unit name and stop at interface keyword
     );
   TPOptions = set of TPOption;