From 3663cfe1d69a9bd57c3c52a33afeaf000d23b10a Mon Sep 17 00:00:00 2001 From: duplo Date: Wed, 25 Mar 2009 14:16:28 +0000 Subject: [PATCH] Retrieve also the index of the match's beginning git-svn-id: https://src.develer.com/svnoss/bertos/trunk@2416 38d2e660-2303-0410-9eaa-f027e97ec537 --- wizard/bertos_utils.py | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/wizard/bertos_utils.py b/wizard/bertos_utils.py index ceb75ab4..933d9ed5 100644 --- a/wizard/bertos_utils.py +++ b/wizard/bertos_utils.py @@ -358,14 +358,23 @@ def getDefinitionBlocks(text): Take a text and return a list of tuple (description, name-value). """ block = [] - block_tmp = re.findall(r"/\*{2}\s*([^*]*\*(?:[^/*][^*]*\*+)*)/\s*#define\s+((?:[^/]*?/?)+)\s*?(?:/{2,3}[^<].*?)?$", text, re.MULTILINE) - for comment, define in block_tmp: + block_tmp = re.finditer(r"/\*{2}\s*([^*]*\*(?:[^/*][^*]*\*+)*)/\s*#define\s+((?:[^/]*?/?)+)\s*?(?:/{2,3}[^<].*?)?$", text, re.MULTILINE) + for match in block_tmp: # Only the first element is needed - block.append(([re.findall(r"^\s*\* *(.*?)$", line, re.MULTILINE)[0] for line in comment.splitlines()], define)) - for comment, define in re.findall(r"/{3}\s*([^<].*?)\s*#define\s+((?:[^/]*?/?)+)\s*?(?:/{2,3}[^<].*?)?$", text, re.MULTILINE): - block.append(([comment], define)) - for define, comment in re.findall(r"#define\s*(.*?)\s*/{3}<\s*(.+?)\s*?(?:/{2,3}[^<].*?)?$", text, re.MULTILINE): - block.append(([comment], define)) + comment = match.group(1) + define = match.group(2) + start = match.start() + block.append(([re.findall(r"^\s*\* *(.*?)$", line, re.MULTILINE)[0] for line in comment.splitlines()], define, start)) + for match in re.finditer(r"/{3}\s*([^<].*?)\s*#define\s+((?:[^/]*?/?)+)\s*?(?:/{2,3}[^<].*?)?$", text, re.MULTILINE): + comment = match.group(1) + define = match.group(2) + start = match.start() + block.append(([comment], define, start)) + for match in re.finditer(r"#define\s*(.*?)\s*/{3}<\s*(.+?)\s*?(?:/{2,3}[^<].*?)?$", text, re.MULTILINE): + comment = match.group(2) + define = match.group(1) + start = match.start() + block.append(([comment], define, start)) return block def loadModuleData(project): @@ -433,7 +442,7 @@ def loadConfigurationInfos(path): "value_list": the name of the enum for enum parameters """ configuration_infos = {} - for comment, define in getDefinitionBlocks(open(path, "r").read()): + for comment, define, start in getDefinitionBlocks(open(path, "r").read()): name, value = formatParamNameValue(define) brief, description, informations = getDescriptionInformations(comment) configuration_infos[name] = {} -- 2.25.1