public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: Jaben Carsey <jaben.carsey@intel.com>
To: edk2-devel@lists.01.org
Cc: Yonghong Zhu <yonghong.zhu@intel.com>, Liming Gao <liming.gao@intel.com>
Subject: [PATCH v1 4/9] BaseTools: use new shared GUID regular expressions
Date: Fri, 16 Mar 2018 16:27:41 -0700	[thread overview]
Message-ID: <f163033efb19a9a46f8f051c1fdd4acec0389c84.1521242771.git.jaben.carsey@intel.com> (raw)
In-Reply-To: <cover.1521242771.git.jaben.carsey@intel.com>
In-Reply-To: <cover.1521242771.git.jaben.carsey@intel.com>

remove local variables that are GUID matching and replace with shared
expression.

Cc: Yonghong Zhu <yonghong.zhu@intel.com>
Cc: Liming Gao <liming.gao@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Jaben Carsey <jaben.carsey@intel.com>
---
 BaseTools/Source/Python/Common/Expression.py      |  3 +--
 BaseTools/Source/Python/Common/FdfParserLite.py   |  5 ++---
 BaseTools/Source/Python/Common/RangeExpression.py | 14 ++++++--------
 BaseTools/Source/Python/GenFds/FdfParser.py       |  3 +--
 4 files changed, 10 insertions(+), 15 deletions(-)

diff --git a/BaseTools/Source/Python/Common/Expression.py b/BaseTools/Source/Python/Common/Expression.py
index e76f09c367c1..c69c3cb1e84a 100644
--- a/BaseTools/Source/Python/Common/Expression.py
+++ b/BaseTools/Source/Python/Common/Expression.py
@@ -220,7 +220,6 @@ class ValueExpression(object):
 
     PcdPattern = re.compile(r'[_a-zA-Z][0-9A-Za-z_]*\.[_a-zA-Z][0-9A-Za-z_]*$')
     HexPattern = re.compile(r'0[xX][0-9a-fA-F]+$')
-    RegGuidPattern = re.compile(r'[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}')
 
     SymbolPattern = re.compile("("
                                  "\$\([A-Z][A-Z0-9_]*\)|\$\(\w+\.\w+\)|\w+\.\w+|"
@@ -731,7 +730,7 @@ class ValueExpression(object):
         self._Token = ''
         if Expr:
             Ch = Expr[0]
-            Match = self.RegGuidPattern.match(Expr)
+            Match = gGuidPattern.match(Expr)
             if Match and not Expr[Match.end():Match.end()+1].isalnum() \
                 and Expr[Match.end():Match.end()+1] != '_':
                 self._Idx += Match.end()
diff --git a/BaseTools/Source/Python/Common/FdfParserLite.py b/BaseTools/Source/Python/Common/FdfParserLite.py
index 330422ad59d2..773f3b1a708f 100644
--- a/BaseTools/Source/Python/Common/FdfParserLite.py
+++ b/BaseTools/Source/Python/Common/FdfParserLite.py
@@ -1,7 +1,7 @@
 ## @file
 # parse FDF file
 #
-#  Copyright (c) 2007 - 2017, Intel Corporation. All rights reserved.<BR>
+#  Copyright (c) 2007 - 2018, 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
@@ -933,8 +933,7 @@ class FdfParser(object):
         
         if not self.__GetNextToken():
             return False
-        p = re.compile('[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}')
-        if p.match(self.__Token) != None:
+        if gGuidPattern.match(self.__Token) != None:
             return True
         else:
             self.__UndoToken()
diff --git a/BaseTools/Source/Python/Common/RangeExpression.py b/BaseTools/Source/Python/Common/RangeExpression.py
index b6c929fd885b..bbcbd6b767e0 100644
--- a/BaseTools/Source/Python/Common/RangeExpression.py
+++ b/BaseTools/Source/Python/Common/RangeExpression.py
@@ -1,7 +1,7 @@
 # # @file
 # This file is used to parse and evaluate range expression in Pcd declaration.
 #
-# Copyright (c) 2015, Intel Corporation. All rights reserved.<BR>
+# Copyright (c) 2015 - 2018, 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
@@ -211,8 +211,6 @@ class RangeExpression(object):
 
     PcdPattern = re.compile(r'[_a-zA-Z][0-9A-Za-z_]*\.[_a-zA-Z][0-9A-Za-z_]*$')
     HexPattern = re.compile(r'0[xX][0-9a-fA-F]+')
-    RegGuidPattern = re.compile(r'[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}')
-    ExRegGuidPattern = re.compile(r'[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$')
     
     SymbolPattern = re.compile("("
                                  "\$\([A-Z][A-Z0-9_]*\)|\$\(\w+\.\w+\)|\w+\.\w+|"
@@ -348,18 +346,18 @@ class RangeExpression(object):
     def Eval(self, Operator, Oprand1, Oprand2 = None):
         
         if Operator in ["!", "NOT", "not"]:
-            if not self.RegGuidPattern.match(Oprand1.strip()):
+            if not gGuidPattern.match(Oprand1.strip()):
                 raise BadExpression(ERR_STRING_EXPR % Operator)
             return self.NegtiveRange(Oprand1)
         else:
             if Operator in ["==", ">=", "<=", ">", "<", '^']:
                 return self.EvalRange(Operator, Oprand1)
             elif Operator == 'and' :
-                if not self.ExRegGuidPattern.match(Oprand1.strip()) or not self.ExRegGuidPattern.match(Oprand2.strip()):
+                if not gGuidPatternEnd.match(Oprand1.strip()) or not gGuidPatternEnd.match(Oprand2.strip()):
                     raise BadExpression(ERR_STRING_EXPR % Operator)
                 return self.Rangeintersection(Oprand1, Oprand2)    
             elif Operator == 'or':
-                if not self.ExRegGuidPattern.match(Oprand1.strip()) or not self.ExRegGuidPattern.match(Oprand2.strip()):
+                if not gGuidPatternEnd.match(Oprand1.strip()) or not gGuidPatternEnd.match(Oprand2.strip()):
                     raise BadExpression(ERR_STRING_EXPR % Operator)
                 return self.Rangecollections(Oprand1, Oprand2)
             else:
@@ -417,7 +415,7 @@ class RangeExpression(object):
         # check if the expression does not need to evaluate
         if RealValue and Depth == 0:
             self._Token = self._Expr
-            if self.ExRegGuidPattern.match(self._Expr):
+            if gGuidPatternEnd.match(self._Expr):
                 return [self.operanddict[self._Expr] ]
 
             self._Idx = 0
@@ -664,7 +662,7 @@ class RangeExpression(object):
         self._Token = ''
         if Expr:
             Ch = Expr[0]
-            Match = self.RegGuidPattern.match(Expr)
+            Match = gGuidPattern.match(Expr)
             if Match and not Expr[Match.end():Match.end() + 1].isalnum() \
                 and Expr[Match.end():Match.end() + 1] != '_':
                 self._Idx += Match.end()
diff --git a/BaseTools/Source/Python/GenFds/FdfParser.py b/BaseTools/Source/Python/GenFds/FdfParser.py
index 03183e398bdb..b8be1251ef52 100644
--- a/BaseTools/Source/Python/GenFds/FdfParser.py
+++ b/BaseTools/Source/Python/GenFds/FdfParser.py
@@ -1150,8 +1150,7 @@ class FdfParser:
 
         if not self.__GetNextToken():
             return False
-        p = re.compile('[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}')
-        if p.match(self.__Token) != None:
+        if gGuidPattern.match(self.__Token) != None:
             return True
         else:
             self.__UndoToken()
-- 
2.16.2.windows.1



  parent reply	other threads:[~2018-03-16 23:21 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-03-16 23:27 [PATCH v1 0/9] BaseTools: refactor variables and regular expressions Jaben Carsey
2018-03-16 23:27 ` [PATCH v1 1/9] BaseTools: FdfParser and FdfParserLite share reg exp Jaben Carsey
2018-03-28 13:05   ` Zhu, Yonghong
2018-03-16 23:27 ` [PATCH v1 2/9] BaseTools: GlobalData share same MACRO name definition Jaben Carsey
2018-03-16 23:27 ` [PATCH v1 3/9] BaseTools: add GUID pattern to global data Jaben Carsey
2018-03-16 23:27 ` Jaben Carsey [this message]
2018-03-16 23:27 ` [PATCH v1 5/9] BaseTools: Regular Expressions refactor out the hex char for later reuse Jaben Carsey
2018-03-16 23:27 ` [PATCH v1 6/9] BaseTools: Add new RegExp for future use Jaben Carsey
2018-03-16 23:27 ` [PATCH v1 7/9] BaseTools: Use precompiled RegExp Jaben Carsey
2018-03-16 23:27 ` [PATCH v1 8/9] BaseTools: GlobalData Add a regular expression for a hex number Jaben Carsey
2018-03-16 23:27 ` [PATCH v1 9/9] BaseTools: remove local hex number regular expression Jaben Carsey

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=f163033efb19a9a46f8f051c1fdd4acec0389c84.1521242771.git.jaben.carsey@intel.com \
    --to=devel@edk2.groups.io \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox