summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorHarmen Stoppels <harmenstoppels@gmail.com>2023-10-09 07:18:27 +0200
committerGitHub <noreply@github.com>2023-10-09 07:18:27 +0200
commit08da9a854a53542e1f71d30ed8d14d6b7d18119f (patch)
treeab4695a2d82a290dea349268afe3e7602737b68b /lib
parent3a18fe04ccb81eafedbeaabebea0f315981b9f50 (diff)
downloadspack-08da9a854a53542e1f71d30ed8d14d6b7d18119f.tar.gz
spack-08da9a854a53542e1f71d30ed8d14d6b7d18119f.tar.bz2
spack-08da9a854a53542e1f71d30ed8d14d6b7d18119f.tar.xz
spack-08da9a854a53542e1f71d30ed8d14d6b7d18119f.zip
parser: use non-capturing groups (#40373)
Diffstat (limited to 'lib')
-rw-r--r--lib/spack/spack/parser.py46
1 files changed, 23 insertions, 23 deletions
diff --git a/lib/spack/spack/parser.py b/lib/spack/spack/parser.py
index d8f34d7e59..5e46ddb1b1 100644
--- a/lib/spack/spack/parser.py
+++ b/lib/spack/spack/parser.py
@@ -73,10 +73,10 @@ IS_WINDOWS = sys.platform == "win32"
#: Valid name for specs and variants. Here we are not using
#: the previous "w[\w.-]*" since that would match most
#: characters that can be part of a word in any language
-IDENTIFIER = r"([a-zA-Z_0-9][a-zA-Z_0-9\-]*)"
-DOTTED_IDENTIFIER = rf"({IDENTIFIER}(\.{IDENTIFIER})+)"
-GIT_HASH = r"([A-Fa-f0-9]{40})"
-GIT_VERSION = rf"((git\.({DOTTED_IDENTIFIER}|{IDENTIFIER}))|({GIT_HASH}))"
+IDENTIFIER = r"(?:[a-zA-Z_0-9][a-zA-Z_0-9\-]*)"
+DOTTED_IDENTIFIER = rf"(?:{IDENTIFIER}(?:\.{IDENTIFIER})+)"
+GIT_HASH = r"(?:[A-Fa-f0-9]{40})"
+GIT_VERSION = rf"(?:(?:git\.(?:{DOTTED_IDENTIFIER}|{IDENTIFIER}))|(?:{GIT_HASH}))"
NAME = r"[a-zA-Z_0-9][a-zA-Z_0-9\-.]*"
@@ -85,15 +85,15 @@ HASH = r"[a-zA-Z_0-9]+"
#: A filename starts either with a "." or a "/" or a "{name}/,
# or on Windows, a drive letter followed by a colon and "\"
# or "." or {name}\
-WINDOWS_FILENAME = r"(\.|[a-zA-Z0-9-_]*\\|[a-zA-Z]:\\)([a-zA-Z0-9-_\.\\]*)(\.json|\.yaml)"
-UNIX_FILENAME = r"(\.|\/|[a-zA-Z0-9-_]*\/)([a-zA-Z0-9-_\.\/]*)(\.json|\.yaml)"
+WINDOWS_FILENAME = r"(?:\.|[a-zA-Z0-9-_]*\\|[a-zA-Z]:\\)(?:[a-zA-Z0-9-_\.\\]*)(?:\.json|\.yaml)"
+UNIX_FILENAME = r"(?:\.|\/|[a-zA-Z0-9-_]*\/)(?:[a-zA-Z0-9-_\.\/]*)(?:\.json|\.yaml)"
if not IS_WINDOWS:
FILENAME = UNIX_FILENAME
else:
FILENAME = WINDOWS_FILENAME
-VALUE = r"([a-zA-Z_0-9\-+\*.,:=\~\/\\]+)"
-QUOTED_VALUE = r"[\"']+([a-zA-Z_0-9\-+\*.,:=\~\/\\\s]+)[\"']+"
+VALUE = r"(?:[a-zA-Z_0-9\-+\*.,:=\~\/\\]+)"
+QUOTED_VALUE = r"[\"']+(?:[a-zA-Z_0-9\-+\*.,:=\~\/\\\s]+)[\"']+"
VERSION = r"=?([a-zA-Z0-9_][a-zA-Z_0-9\-\.]*\b)"
VERSION_RANGE = rf"({VERSION}\s*:\s*{VERSION}(?!\s*=)|:\s*{VERSION}(?!\s*=)|{VERSION}\s*:|:)"
@@ -125,34 +125,34 @@ class TokenType(TokenBase):
"""
# Dependency
- DEPENDENCY = r"(\^)"
+ DEPENDENCY = r"(?:\^)"
# Version
- VERSION_HASH_PAIR = rf"(@({GIT_VERSION})=({VERSION}))"
- VERSION = rf"(@\s*({VERSION_LIST}))"
+ VERSION_HASH_PAIR = rf"(?:@(?:{GIT_VERSION})=(?:{VERSION}))"
+ VERSION = rf"(?:@\s*(?:{VERSION_LIST}))"
# Variants
- PROPAGATED_BOOL_VARIANT = rf"((\+\+|~~|--)\s*{NAME})"
- BOOL_VARIANT = rf"([~+-]\s*{NAME})"
- PROPAGATED_KEY_VALUE_PAIR = rf"({NAME}\s*==\s*({VALUE}|{QUOTED_VALUE}))"
- KEY_VALUE_PAIR = rf"({NAME}\s*=\s*({VALUE}|{QUOTED_VALUE}))"
+ PROPAGATED_BOOL_VARIANT = rf"(?:(?:\+\+|~~|--)\s*{NAME})"
+ BOOL_VARIANT = rf"(?:[~+-]\s*{NAME})"
+ PROPAGATED_KEY_VALUE_PAIR = rf"(?:{NAME}\s*==\s*(?:{VALUE}|{QUOTED_VALUE}))"
+ KEY_VALUE_PAIR = rf"(?:{NAME}\s*=\s*(?:{VALUE}|{QUOTED_VALUE}))"
# Compilers
- COMPILER_AND_VERSION = rf"(%\s*({NAME})([\s]*)@\s*({VERSION_LIST}))"
- COMPILER = rf"(%\s*({NAME}))"
+ COMPILER_AND_VERSION = rf"(?:%\s*(?:{NAME})(?:[\s]*)@\s*(?:{VERSION_LIST}))"
+ COMPILER = rf"(?:%\s*(?:{NAME}))"
# FILENAME
- FILENAME = rf"({FILENAME})"
+ FILENAME = rf"(?:{FILENAME})"
# Package name
- FULLY_QUALIFIED_PACKAGE_NAME = rf"({DOTTED_IDENTIFIER})"
- UNQUALIFIED_PACKAGE_NAME = rf"({IDENTIFIER})"
+ FULLY_QUALIFIED_PACKAGE_NAME = rf"(?:{DOTTED_IDENTIFIER})"
+ UNQUALIFIED_PACKAGE_NAME = rf"(?:{IDENTIFIER})"
# DAG hash
- DAG_HASH = rf"(/({HASH}))"
+ DAG_HASH = rf"(?:/(?:{HASH}))"
# White spaces
- WS = r"(\s+)"
+ WS = r"(?:\s+)"
class ErrorTokenType(TokenBase):
"""Enum with regexes for error analysis"""
# Unexpected character
- UNEXPECTED = r"(.[\s]*)"
+ UNEXPECTED = r"(?:.[\s]*)"
class Token: