Fix bug with converting "*.ino" to "*.cpp"

This commit is contained in:
Ivan Kravets committed 2015-05-23 14:02:05 +03:00
1 parent e22e4d23e4
commit f732d4088b
3 files changed
+18 -4

No files matched your search

+12 -3
View File
@@ -309,8 +309,8 @@ class InoToCPPConverter(object):
PROTOTYPE_RE = re.compile(
r"""^(
(?:\s*[a-z_\d]+){1,2} # return type
\s+[a-z_\d]+\s* # name of prototype
(\s*[a-z_\d]+){1,2} # return type
(\s+[a-z_\d]+\s*) # name of prototype
\([a-z_,\.\*\&\[\]\s\d]*\) # arguments
)\s*\{ # must end with {
""",
@@ -334,6 +334,15 @@ class InoToCPPConverter(object):
else:
return " "
def _parse_prototypes(self, contents):
prototypes = []
reserved_keywords = set(["if", "else", "while"])
for item in self.PROTOTYPE_RE.findall(contents):
if set([item[1].strip(), item[2].strip()]) & reserved_keywords:
continue
prototypes.append(item[0])
return prototypes
def append_prototypes(self, fname, contents, prototypes):
contents = self.STRIPCOMMENTS_RE.sub(self._replace_comments_callback,
contents)
@@ -358,7 +367,7 @@ class InoToCPPConverter(object):
data = []
for node in self.nodes:
ino_contents = node.get_text_contents()
prototypes += self.PROTOTYPE_RE.findall(ino_contents)
prototypes += self._parse_prototypes(ino_contents)
item = (basename(node.get_path()), ino_contents)
if self.is_main_node(ino_contents):