Remove a debug print
[bertos.git] / wizard / newParser.py
index 02035c79f8c9a4112b0041d4259963a68c2729d2..4b156449f5e6db7218885088938b43f26c36a244 100644 (file)
@@ -45,9 +45,10 @@ def loadModuleDefinition(first_comment):
             moduleDict[moduleDefinition["module_name"]]["configuration"] = ""
         if "module_description" in moduleDefinition.keys():
             moduleDict[moduleDefinition["module_name"]]["description"] = moduleDefinition["module_description"]
+        moduleDict[moduleDefinition["module_name"]]["enabled"] = False
     return toBeParsed, moduleDict
 
-def loadDefineList(commentList):
+def loadDefineLists(commentList):
     defineList = {}
     for comment in commentList:
         for num, line in enumerate(comment):
@@ -62,6 +63,40 @@ def loadDefineList(commentList):
             defineList[key] = (value,)
     return defineList
 
+def getDescriptionInformations(comment): 
+    """ 
+    Take the doxygen comment and strip the wizard informations, returning the tuple 
+    (comment, wizard_information) 
+    """
+    description = ""
+    information = {}
+    for num, line in enumerate(comment):
+        index = line.find("$WIZ$")
+        if index != -1:
+            description += " " + line[:index]
+            try:
+                exec line[index + len("$WIZ$ "):] in {}, information
+            except:
+                raise ParseError(num, line[index:])
+        else:
+            description += " " + line
+    return description.strip(), information
+
+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:
+        # 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))
+    return block
+
 class ParseError(Exception):
     def __init__(self, line_number, line):
         Exception.__init__(self)
@@ -70,9 +105,15 @@ class ParseError(Exception):
 
 def main():
     try:
-        commentList = getCommentList(open("test/to_parse.h", "r").read())
-        print loadModuleDefinition(commentList[0])
-        print loadDefineList(commentList[1:])
+        defineLists = {}
+        modules = {}
+        commentList = getCommentList(open("test/to_parse", "r").read())
+        toBeParsedm, moduleInfo = loadModuleDefinition(commentList[0])
+        modules.update(moduleInfo)
+        if toBeParsed:
+            defineLists.update(loadDefineList(commentList[1:]))
+        print modules
+        print defineLists
     except ParseError, err:
         print "Error: line %d - %s" % (err.line_number, err.line)