BaseTools: use single RegExp for token matching
[mirror_edk2.git] / BaseTools / Source / Python / Common / FdfParserLite.py
index 66815d3e17fe53125ab93b5e418ec425ac1a33b5..255ca9633aa180abe4fd2603bc23ebee109fe08e 100644 (file)
@@ -49,6 +49,7 @@ InputMacroDict = {}
 AllMacroList = []\r
 \r
 FileExtensionPattern = re.compile(r'([a-zA-Z][a-zA-Z0-9]*)')\r
+TokenFindPattern = re.compile(r'([a-zA-Z0-9\-]+|\$\(TARGET\)|\*)_([a-zA-Z0-9\-]+|\$\(TOOL_CHAIN_TAG\)|\*)_([a-zA-Z0-9\-]+|\$\(ARCH\)|\*)')\r
 \r
 def GetRealFileLine (File, Line):\r
     \r
@@ -2094,8 +2095,7 @@ class FdfParser(object):
 \r
                 \r
         if self.__GetNextToken():\r
-            p = re.compile(r'([a-zA-Z0-9\-]+|\$\(TARGET\)|\*)_([a-zA-Z0-9\-]+|\$\(TOOL_CHAIN_TAG\)|\*)_([a-zA-Z0-9\-]+|\$\(ARCH\)|\*)')\r
-            if p.match(self.__Token):\r
+            if TokenFindPattern.match(self.__Token):\r
                 FfsInfObj.KeyStringList.append(self.__Token)\r
                 if not self.__IsToken(","):\r
                     return\r
@@ -2104,7 +2104,7 @@ class FdfParser(object):
                 return\r
                 \r
             while self.__GetNextToken():\r
-                if not p.match(self.__Token):\r
+                if not TokenFindPattern.match(self.__Token):\r
                     raise Warning("expected KeyString \"Target_Tag_Arch\" At Line ", self.FileName, self.CurrentLineNumber)\r
                 FfsInfObj.KeyStringList.append(self.__Token)\r
     \r
@@ -2252,12 +2252,11 @@ class FdfParser(object):
     def __GetFileOpts(self, FfsFileObj):\r
         \r
         if self.__GetNextToken():\r
-            Pattern = re.compile(r'([a-zA-Z0-9\-]+|\$\(TARGET\)|\*)_([a-zA-Z0-9\-]+|\$\(TOOL_CHAIN_TAG\)|\*)_([a-zA-Z0-9\-]+|\$\(ARCH\)|\*)')\r
-            if Pattern.match(self.__Token):\r
+            if TokenFindPattern.match(self.__Token):\r
                 FfsFileObj.KeyStringList.append(self.__Token)\r
                 if self.__IsToken(","):\r
                     while self.__GetNextToken():\r
-                        if not Pattern.match(self.__Token):\r
+                        if not TokenFindPattern.match(self.__Token):\r
                             raise Warning("expected KeyString \"Target_Tag_Arch\" At Line ", self.FileName, self.CurrentLineNumber)\r
                         FfsFileObj.KeyStringList.append(self.__Token)\r
 \r
@@ -2902,12 +2901,11 @@ class FdfParser(object):
         \r
         KeyStringList = []\r
         if self.__GetNextToken():\r
-            Pattern = re.compile(r'([a-zA-Z0-9\-]+|\$\(TARGET\)|\*)_([a-zA-Z0-9\-]+|\$\(TOOL_CHAIN_TAG\)|\*)_([a-zA-Z0-9\-]+|\$\(ARCH\)|\*)')\r
-            if Pattern.match(self.__Token):\r
+            if TokenFindPattern.match(self.__Token):\r
                 KeyStringList.append(self.__Token)\r
                 if self.__IsToken(","):\r
                     while self.__GetNextToken():\r
-                        if not Pattern.match(self.__Token):\r
+                        if not TokenFindPattern.match(self.__Token):\r
                             raise Warning("expected KeyString \"Target_Tag_Arch\" At Line ", self.FileName, self.CurrentLineNumber)\r
                         KeyStringList.append(self.__Token)\r
 \r