BaseTools: move RegEx to root of file and share it
make it easy to import and use by others Cc: Liming Gao <liming.gao@intel.com> Cc: Yonghong Zhu <yonghong.zhu@intel.com> Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Jaben Carsey <jaben.carsey@intel.com> Reviewed-by: Yonghong Zhu <yonghong.zhu@intel.com>
This commit is contained in:
committed by
Yonghong Zhu
parent
bfc8f5667a
commit
e6c2468a9e
@ -43,6 +43,7 @@ ERR_IN_OPERAND = 'Macro after IN operator can only be: $(FAMILY), $(ARC
|
|||||||
__ValidString = re.compile(r'[_a-zA-Z][_0-9a-zA-Z]*$')
|
__ValidString = re.compile(r'[_a-zA-Z][_0-9a-zA-Z]*$')
|
||||||
_ReLabel = re.compile('LABEL\((\w+)\)')
|
_ReLabel = re.compile('LABEL\((\w+)\)')
|
||||||
_ReOffset = re.compile('OFFSET_OF\((\w+)\)')
|
_ReOffset = re.compile('OFFSET_OF\((\w+)\)')
|
||||||
|
PcdPattern = re.compile(r'[_a-zA-Z][0-9A-Za-z_]*\.[_a-zA-Z][0-9A-Za-z_]*$')
|
||||||
|
|
||||||
## SplitString
|
## SplitString
|
||||||
# Split string to list according double quote
|
# Split string to list according double quote
|
||||||
@ -214,7 +215,6 @@ class ValueExpression(object):
|
|||||||
|
|
||||||
NonLetterOpLst = ['+', '-', '*', '/', '%', '&', '|', '^', '~', '<<', '>>', '!', '=', '>', '<', '?', ':']
|
NonLetterOpLst = ['+', '-', '*', '/', '%', '&', '|', '^', '~', '<<', '>>', '!', '=', '>', '<', '?', ':']
|
||||||
|
|
||||||
PcdPattern = re.compile(r'[_a-zA-Z][0-9A-Za-z_]*\.[_a-zA-Z][0-9A-Za-z_]*$')
|
|
||||||
|
|
||||||
SymbolPattern = re.compile("("
|
SymbolPattern = re.compile("("
|
||||||
"\$\([A-Z][A-Z0-9_]*\)|\$\(\w+\.\w+\)|\w+\.\w+|"
|
"\$\([A-Z][A-Z0-9_]*\)|\$\(\w+\.\w+\)|\w+\.\w+|"
|
||||||
@ -616,7 +616,7 @@ class ValueExpression(object):
|
|||||||
raise BadExpression(ERR_EMPTY_TOKEN)
|
raise BadExpression(ERR_EMPTY_TOKEN)
|
||||||
|
|
||||||
# PCD token
|
# PCD token
|
||||||
if self.PcdPattern.match(self._Token):
|
if PcdPattern.match(self._Token):
|
||||||
if self._Token not in self._Symb:
|
if self._Token not in self._Symb:
|
||||||
Ex = BadExpression(ERR_PCD_RESOLVE % self._Token)
|
Ex = BadExpression(ERR_PCD_RESOLVE % self._Token)
|
||||||
Ex.Pcd = self._Token
|
Ex.Pcd = self._Token
|
||||||
|
@ -16,6 +16,7 @@ from Common.GlobalData import *
|
|||||||
from CommonDataClass.Exceptions import BadExpression
|
from CommonDataClass.Exceptions import BadExpression
|
||||||
from CommonDataClass.Exceptions import WrnExpression
|
from CommonDataClass.Exceptions import WrnExpression
|
||||||
import uuid
|
import uuid
|
||||||
|
from Common.Expression import PcdPattern
|
||||||
|
|
||||||
ERR_STRING_EXPR = 'This operator cannot be used in string expression: [%s].'
|
ERR_STRING_EXPR = 'This operator cannot be used in string expression: [%s].'
|
||||||
ERR_SNYTAX = 'Syntax error, the rest of expression cannot be evaluated: [%s].'
|
ERR_SNYTAX = 'Syntax error, the rest of expression cannot be evaluated: [%s].'
|
||||||
@ -209,8 +210,6 @@ class RangeExpression(object):
|
|||||||
|
|
||||||
NonLetterOpLst = ['+', '-', '&', '|', '^', '!', '=', '>', '<']
|
NonLetterOpLst = ['+', '-', '&', '|', '^', '!', '=', '>', '<']
|
||||||
|
|
||||||
PcdPattern = re.compile(r'[_a-zA-Z][0-9A-Za-z_]*\.[_a-zA-Z][0-9A-Za-z_]*$')
|
|
||||||
|
|
||||||
RangePattern = re.compile(r'[0-9]+ - [0-9]+')
|
RangePattern = re.compile(r'[0-9]+ - [0-9]+')
|
||||||
|
|
||||||
def preProcessRangeExpr(self, expr):
|
def preProcessRangeExpr(self, expr):
|
||||||
@ -573,7 +572,7 @@ class RangeExpression(object):
|
|||||||
raise BadExpression(ERR_EMPTY_TOKEN)
|
raise BadExpression(ERR_EMPTY_TOKEN)
|
||||||
|
|
||||||
# PCD token
|
# PCD token
|
||||||
if self.PcdPattern.match(self._Token):
|
if PcdPattern.match(self._Token):
|
||||||
if self._Token not in self._Symb:
|
if self._Token not in self._Symb:
|
||||||
Ex = BadExpression(ERR_PCD_RESOLVE % self._Token)
|
Ex = BadExpression(ERR_PCD_RESOLVE % self._Token)
|
||||||
Ex.Pcd = self._Token
|
Ex.Pcd = self._Token
|
||||||
|
Reference in New Issue
Block a user