Make mark verification occur in expression compilation

This commit is contained in:
Max Berkowitz 2024-04-26 00:34:48 -04:00 committed by GitHub
parent 917af40c60
commit fbfb4ebf58
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 8 additions and 1 deletions

View File

@ -200,12 +200,19 @@ class Expression:
self.code = code
@classmethod
def compile(self, input: str) -> "Expression":
def compile(self, input: str, mark: bool = False) -> "Expression":
"""Compile a match expression.
:param input: The input expression - one line.
"""
astexpr = expression(Scanner(input))
if mark:
for node in ast.walk(astexpr):
#if the node is an identifier, i.e. a mark name
if isinstance(node, ast.Name):
MARK_GEN.verify_mark(node.id[len(IDENT_PREFIX):])
code: types.CodeType = compile(
astexpr,
filename="<pytest match expression>",