]> git.proxmox.com Git - mirror_edk2.git/blobdiff - BaseTools/Source/Python/Common/Parsing.py
BaseTools: remove local hex number regular expression
[mirror_edk2.git] / BaseTools / Source / Python / Common / Parsing.py
index 6ab91fbc33d4f2b0e64ed82cbaeb92e13587eef4..584fc7f3c3a03645da1bdfc4bcfc531fc09f4ff9 100644 (file)
@@ -1,8 +1,8 @@
 ## @file\r
 # This file is used to define common parsing related functions used in parsing INF/DEC/DSC process\r
 #\r
-# Copyright (c) 2008 ~ 2010, Intel Corporation\r
-# All rights reserved. This program and the accompanying materials\r
+# Copyright (c) 2008 - 2014, Intel Corporation. All rights reserved.<BR>\r
+# This program and the accompanying materials\r
 # are licensed and made available under the terms and conditions of the BSD License\r
 # which accompanies this distribution.  The full text of the license may be found at\r
 # http://opensource.org/licenses/bsd-license.php\r
@@ -18,70 +18,6 @@ from String import *
 from CommonDataClass.DataClass import *\r
 from DataType import *\r
 \r
-## ParseContent\r
-#\r
-# Parse content of a DSC/INF/DEC file\r
-#\r
-def ParseContent(Lines, ):\r
-    for Line in Lines:\r
-        LineNo = LineNo + 1\r
-        #\r
-        # Remove comments at tail and remove spaces again\r
-        #\r
-        Line = CleanString(Line)\r
-        if Line == '':\r
-            continue\r
-\r
-        #\r
-        # Find a new section tab\r
-        # First insert previous section items\r
-        # And then parse the content of the new section\r
-        #\r
-        if Line.startswith(TAB_SECTION_START) and Line.endswith(TAB_SECTION_END):\r
-            #\r
-            # Insert items data of previous section\r
-            #\r
-            self.InsertSectionItemsIntoDatabase(FileID, Filename, CurrentSection, SectionItemList, ArchList, ThirdList, IfDefList)\r
-            #\r
-            # Parse the new section\r
-            #\r
-            SectionItemList = []\r
-            ArchList = []\r
-            ThirdList = []\r
-\r
-            LineList = GetSplitValueList(Line[len(TAB_SECTION_START):len(Line) - len(TAB_SECTION_END)], TAB_COMMA_SPLIT)\r
-            for Item in LineList:\r
-                ItemList = GetSplitValueList(Item, TAB_SPLIT)\r
-                CurrentSection = ItemList[0]\r
-                if CurrentSection.upper() not in self.KeyList:\r
-                    RaiseParserError(Line, CurrentSection, Filename, '', LineNo)\r
-                ItemList.append('')\r
-                ItemList.append('')\r
-                if len(ItemList) > 5:\r
-                    RaiseParserError(Line, CurrentSection, Filename, '', LineNo)\r
-                else:\r
-                    if ItemList[1] != '' and ItemList[1].upper() not in ARCH_LIST_FULL:\r
-                        EdkLogger.error("Parser", PARSER_ERROR, "Invalid Arch definition '%s' found" % ItemList[1], File=Filename, Line=LineNo)\r
-                    ArchList.append(ItemList[1].upper())\r
-                    ThirdList.append(ItemList[2])\r
-\r
-            continue\r
-\r
-        #\r
-        # Not in any defined section\r
-        #\r
-        if CurrentSection == TAB_UNKNOWN:\r
-            ErrorMsg = "%s is not in any defined section" % Line\r
-            EdkLogger.error("Parser", PARSER_ERROR, ErrorMsg, File=Filename, Line=LineNo)\r
-\r
-        #\r
-        # Add a section item\r
-        #\r
-        SectionItemList.append([Line, LineNo])\r
-        # End of parse\r
-    #End of For\r
-\r
-\r
 ## ParseDefineMacro\r
 #\r
 # Search whole table to find all defined Macro and replaced them with the real values\r
@@ -291,17 +227,17 @@ def QueryInfItem(Table, Model, BelongsToItem):
 # @retval truple() A truple structure as (Family, ToolChain, Flag)\r
 #\r
 def GetBuildOption(String, File, LineNo = -1):\r
+    (Family, ToolChain, Flag) = ('', '', '')\r
     if String.find(TAB_EQUAL_SPLIT) < 0:\r
         RaiseParserError(String, 'BuildOptions', File, '[<Family>:]<ToolFlag>=Flag', LineNo)\r
-    (Family, ToolChain, Flag) = ('', '', '')\r
-    List = GetSplitValueList(String, TAB_EQUAL_SPLIT, MaxSplit = 1)\r
-    if List[0].find(':') > -1:\r
-        Family = List[0][ : List[0].find(':')].strip()\r
-        ToolChain = List[0][List[0].find(':') + 1 : ].strip()\r
     else:\r
-        ToolChain = List[0].strip()\r
-    Flag = List[1].strip()\r
-\r
+        List = GetSplitValueList(String, TAB_EQUAL_SPLIT, MaxSplit = 1)\r
+        if List[0].find(':') > -1:\r
+            Family = List[0][ : List[0].find(':')].strip()\r
+            ToolChain = List[0][List[0].find(':') + 1 : ].strip()\r
+        else:\r
+            ToolChain = List[0].strip()\r
+        Flag = List[1].strip()\r
     return (Family, ToolChain, Flag)\r
 \r
 ## Get Library Class\r
@@ -940,4 +876,39 @@ def GenMetaDatSectionItem(Key, Value, List):
     if Key not in List:\r
         List[Key] = [Value]\r
     else:\r
-        List[Key].append(Value)
\ No newline at end of file
+        List[Key].append(Value)\r
+\r
+## IsValidWord\r
+#\r
+# Check whether the word is valid.\r
+# <Word>   ::=  (a-zA-Z0-9_)(a-zA-Z0-9_-){0,} Alphanumeric characters with\r
+#               optional\r
+#               dash "-" and/or underscore "_" characters. No whitespace\r
+#               characters are permitted.\r
+#\r
+# @param Word:  The word string need to be checked.\r
+#\r
+def IsValidWord(Word):\r
+    if not Word:\r
+        return False\r
+    #\r
+    # The first char should be alpha, _ or Digit.\r
+    #\r
+    if not Word[0].isalnum() and \\r
+       not Word[0] == '_' and \\r
+       not Word[0].isdigit():\r
+        return False\r
+\r
+    LastChar = ''\r
+    for Char in Word[1:]:\r
+        if (not Char.isalpha()) and \\r
+           (not Char.isdigit()) and \\r
+           Char != '-' and \\r
+           Char != '_' and \\r
+           Char != '.':\r
+            return False\r
+        if Char == '.' and LastChar == '.':\r
+            return False\r
+        LastChar = Char\r
+\r
+    return True\r