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