From 82e74d16edc4b331d67ca867c6666626ac320842 Mon Sep 17 00:00:00 2001 From: Andrea Righi Date: Mon, 5 Dec 2022 09:06:53 +0100 Subject: [PATCH] annotations: catch syntax errors in annotations Trigger a syntax error when a policy or note rule is not properly closed. Signed-off-by: Andrea Righi --- kconfig/annotations.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/kconfig/annotations.py b/kconfig/annotations.py index 90e58a9..92167f8 100644 --- a/kconfig/annotations.py +++ b/kconfig/annotations.py @@ -68,6 +68,7 @@ class Annotation(Config): # Skip empty, non-policy and non-note lines if re.match('.* policy<', line) or re.match('.* note<', line): try: + # Parse single policy or note rule conf = line.split(' ')[0] if conf in self.config: entry = self.config[conf] @@ -76,11 +77,13 @@ class Annotation(Config): m = re.match(r'.*policy<(.*)>', line) if m: entry['policy'] |= literal_eval(m.group(1)) - m = re.match(r'.*note<(.*?)>', line) - if m: - entry['note'] = "'" + m.group(1).replace("'", '') + "'" - if entry: - self.config[conf] = entry + else: + m = re.match(r'.*note<(.*?)>', line) + if m: + entry['note'] = "'" + m.group(1).replace("'", '') + "'" + else: + raise Exception('syntax error') + self.config[conf] = entry except Exception as e: raise Exception(str(e) + f', line = {line}') -- 2.31.1