ParserValidate.py revision 4fd606d1f5abe38e1f42c38de1d2e895166bd0f4
## @file ParserValidate.py
#
# Copyright (c) 2011, Intel Corporation. All rights reserved.<BR>
#
# 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
#
# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#
'''
PaserValidate
'''
import re
import platform
## __HexDigit() method
#
# Whether char input is a Hex data bit
#
# @param TempChar: The char to test
#
def __HexDigit(TempChar):
return True
else:
return False
## IsValidHex() method
#
# Whether char input is a Hex data.
#
# @param TempChar: The char to test
#
def IsValidHex(HexStr):
return False
return True
else:
return False
## Judge the input string is valid bool type or not.
#
# <TRUE> ::= {"TRUE"} {"true"} {"True"} {"0x1"} {"0x01"}
# <FALSE> ::= {"FALSE"} {"false"} {"False"} {"0x0"} {"0x00"}
# <BoolType> ::= {<TRUE>} {<FALSE>}
#
# @param BoolString: A string contained the value need to be judged.
#
def IsValidBoolType(BoolString):
#
# Valid Ture
#
if BoolString == 'TRUE' or \
BoolString == 'True' or \
BoolString == 'true' or \
BoolString == '0x1' or \
BoolString == '0x01':
return True
#
# Valid False
#
elif BoolString == 'FALSE' or \
BoolString == 'False' or \
BoolString == 'false' or \
BoolString == '0x0' or \
BoolString == '0x00':
return True
#
# Invalid bool type
#
else:
return False
## Is Valid Module Type List or not
#
# @param ModuleTypeList: A list contain ModuleType strings need to be
# judged.
#
for ModuleType in ModuleTypeList:
return IsValidInfMoudleType(ModuleType)
## Is Valid Module Type or not
#
# @param ModuleType: A string contain ModuleType need to be judged.
#
if ModuleType in MODULE_LIST:
return True
else:
return False
## Is Valid Component Type or not
#
# @param ComponentType: A string contain ComponentType need to be judged.
#
return True
else:
return False
## Is valid Tool Family or not
#
# @param ToolFamily: A string contain Tool Family need to be judged.
# Famlily := [A-Z]([a-zA-Z0-9])*
#
def IsValidToolFamily(ToolFamily):
return False
return True
## Is valid Tool TagName or not
#
# The TagName sample is MYTOOLS and VS2005.
#
# @param TagName: A string contain Tool TagName need to be judged.
#
def IsValidToolTagName(TagName):
return True
return True
if not IsValidWord(TagName):
return False
return True
## Is valid arch or not
#
# @param Arch The arch string need to be validated
# <OA> ::= (a-zA-Z)(A-Za-z0-9){0,}
# <arch> ::= {"IA32"} {"X64"} {"IPF"} {"EBC"} {<OA>}
# {"common"}
# @param Arch: Input arch
#
def IsValidArch(Arch):
if Arch == 'common':
return True
return False
return True
## Is valid family or not
#
# <Family> ::= {"MSFT"} {"GCC"} {"INTEL"} {<Usr>} {"*"}
# <Usr> ::= [A-Z][A-Za-z0-9]{0,}
#
# @param family: The family string need to be validated
#
def IsValidFamily(Family):
if Family == '*':
return True
if Family == '':
return True
return False
return True
## Is valid build option name or not
#
# @param BuildOptionName: The BuildOptionName string need to be validated
#
if not BuildOptionName:
return False
return False
return False
return False
return False
return False
return True
## IsValidToken
#
# Check if pattern string matches total token
#
# @param ReString: regular string
# @param Token: Token to be matched
#
## IsValidPath
#
# Check if path exist
#
# @param Path: Absolute path or relative path to be checked
# @param Root: Root path
#
return False
#
# If Path is absolute path.
# It should be in Root.
#
return False
return True
#
# Check illegal character
#
return False
return False
return False
#
# Check relative path
#
if not IsValidWord(Word):
return False
return True
## IsValidInstallPath
#
# Check if an install path valid or not.
#
# Absolute path or path starts with '.' or path contains '..' are invalid.
#
# @param Path: path to be checked
#
def IsValidInstallPath(Path):
return False
else:
return False
return False
return False
return False
return True
## IsValidCFormatGuid
#
# Check if GUID format has the from of {8,4,4,{2,2,2,2,2,2,2,2}}
#
# @param Guid: Guid to be checked
#
def IsValidCFormatGuid(Guid):
#
# Valid: { 0xf0b11735, 0x87a0, 0x4193, {0xb2, 0x66, 0x53, 0x8c, 0x38,
# 0xaf, 0x48, 0xce }}
# Invalid: { 0xf0b11735, 0x87a0, 0x4193, {0xb2, 0x66, 0x53, 0x8c, 0x38,
# 0xaf, 0x48, 0xce }} 0x123
# Invalid: { 0xf0b1 1735, 0x87a0, 0x4193, {0xb2, 0x66, 0x53, 0x8c, 0x38,
# 0xaf, 0x48, 0xce }}
#
',', 4, ',', 4, ',', 4, ',', 4, ',', 4, '}}']
Index = 0
Value = ''
SepValue = ''
if Char not in '{},\t ':
continue
if Value:
try:
#
# Index may out of bound
#
return False
Index += 1
SepValue = ''
return False
#
# Index may out of bound
#
return False
#
# Check if string can be converted to integer
# Throw exception if not
#
except BaseException:
#
# Exception caught means invalid format
#
return False
Value = ''
Index += 1
if Char in '{},':
## IsValidPcdType
#
# Check whether the PCD type is valid
#
# @param PcdTypeString: The PcdType string need to be checked.
#
def IsValidPcdType(PcdTypeString):
return True
else:
return False
## IsValidWord
#
# Check whether the word is valid.
# <Word> ::= (a-zA-Z0-9_)(a-zA-Z0-9_-){0,} Alphanumeric characters with
# optional
# 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.
#
return False
LastChar = ''
Char != '-' and \
Char != '_' and \
Char != '.':
return False
return False
return True
## IsValidSimpleWord
#
# Check whether the SimpleWord is valid.
# <SimpleWord> ::= (a-zA-Z0-9)(a-zA-Z0-9_-){0,}
# A word that cannot contain a period character.
#
# @param Word: The word string need to be checked.
#
def IsValidSimpleWord(Word):
if not Word:
return False
return False
return True
## IsValidDecVersion
#
# Check whether the decimal version is valid.
# <DecVersion> ::= (0-9){1,} ["." (0-9){1,}]
#
# @param Word: The word string need to be checked.
#
def IsValidDecVersion(Word):
else:
return False
return True
## IsValidHexVersion
#
# Check whether the hex version is valid.
# <HexVersion> ::= "0x" <Major> <Minor>
# <Major> ::= <HexDigit>{4}
# <Minor> ::= <HexDigit>{4}
#
# @param Word: The word string need to be checked.
#
def IsValidHexVersion(Word):
return False
return True
## IsValidBuildNumber
#
# Check whether the BUILD_NUMBER is valid.
# ["BUILD_NUMBER" "=" <Integer>{1,4} <EOL>]
#
# @param Word: The BUILD_NUMBER string need to be checked.
#
def IsValidBuildNumber(Word):
return False
return True
## IsValidDepex
#
# Check whether the Depex is valid.
#
# @param Word: The Depex string need to be checked.
#
def IsValidDepex(Word):
if Index > -1:
return False
return True
## IsValidNormalizedString
#
# Check
# <NormalizedString> ::= <DblQuote> [{<Word>} {<Space>}]{1,} <DblQuote>
# <Space> ::= 0x20
#
# @param String: string to be checked
#
if String == '':
return True
if Char == '\t':
return False
for Item in StringList:
if not Item:
continue
if not IsValidWord(Item):
return False
return True
## IsValidIdString
#
# Check whether the IdString is valid.
#
# @param IdString: The IdString need to be checked.
#
def IsValidIdString(String):
return True
return True
return True
return False
## IsValidVersionString
#
# Check whether the VersionString is valid.
# <AsciiString> ::= [ [<WhiteSpace>]{0,} [<AsciiChars>]{0,} ] {0,}
# <WhiteSpace> ::= {<Tab>} {<Space>}
# <Tab> ::= 0x09
# <Space> ::= 0x20
# <AsciiChars> ::= (0x21 - 0x7E)
#
# @param VersionString: The VersionString need to be checked.
#
for Char in VersionString:
return False
return True
## IsValidPcdValue
#
# Check whether the PcdValue is valid.
#
# @param VersionString: The PcdValue need to be checked.
#
def IsValidPcdValue(PcdValue):
return False
#
# <Boolean>
#
return True
#
# <Number> ::= {<Integer>} {<HexNumber>}
# <Integer> ::= {(0-9)} {(1-9)(0-9){1,}}
# <HexNumber> ::= "0x" <HexDigit>{1,}
# <HexDigit> ::= (a-fA-F0-9)
#
if IsValidHex(PcdValue):
return True
return True
return True
#
# <StringVal> ::= {<StringType>} {<Array>} {"$(" <MACRO> ")"}
# <StringType> ::= {<UnicodeString>} {<CString>}
#
if IsTrue:
return IsTrue
#
# <Array> ::= {<CArray>} {<NList>} {<CFormatGUID>}
# <CArray> ::= "{" [<NList>] <CArray>{0,} "}"
# <NList> ::= <HexByte> ["," <HexByte>]{0,}
# <HexDigit> ::= (a-fA-F0-9)
# <HexByte> ::= "0x" <HexDigit>{1,2}
#
return True
if AllValidFlag:
return True
#
# NList
#
if AllValidFlag:
return True
return False
## IsValidCVariableName
#
# Check whether the PcdValue is valid.
#
# @param VersionString: The PcdValue need to be checked.
#
def IsValidCVariableName(CName):
return False
return True
## IsValidIdentifier
#
# <Identifier> ::= <NonDigit> <Chars>{0,}
# <Chars> ::= (a-zA-Z0-9_)
# <NonDigit> ::= (a-zA-Z_)
#
# @param Ident: identifier to be checked
#
def IsValidIdentifier(Ident):
return False
return True
## IsValidDecVersionVal
#
# {(0-9){1,} "." (0-99)}
#
# @param Ver: version to be checked
#
def IsValidDecVersionVal(Ver):
return False
return True
## IsValidLibName
#
# (A-Z)(a-zA-Z0-9){0,} and could not be "NULL"
#
def IsValidLibName(LibName):
if LibName == 'NULL':
return False
return False
return True
# IsValidUserId
#
# <UserId> ::= (a-zA-Z)(a-zA-Z0-9_.){0,}
# Words that contain period "." must be encapsulated in double quotation marks.
#
def IsValidUserId(UserId):
return False
return False
return False
return True