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

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

View File

@ -1,6 +1,11 @@
Release History Release History
=============== ===============
2.0.1 (2015-??-??)
------------------
* Fixed bug with converting ``*.ino`` to ``*.cpp``
2.0.0 (2015-05-22) 2.0.0 (2015-05-22)
------------------ ------------------

View File

@ -1,7 +1,7 @@
# Copyright (C) Ivan Kravets <me@ikravets.com> # Copyright (C) Ivan Kravets <me@ikravets.com>
# See LICENSE for details. # See LICENSE for details.
VERSION = (2, 0, 0) VERSION = (2, 0, "1.dev0")
__version__ = ".".join([str(s) for s in VERSION]) __version__ = ".".join([str(s) for s in VERSION])
__title__ = "platformio" __title__ = "platformio"

View File

@ -309,8 +309,8 @@ class InoToCPPConverter(object):
PROTOTYPE_RE = re.compile( PROTOTYPE_RE = re.compile(
r"""^( r"""^(
(?:\s*[a-z_\d]+){1,2} # return type (\s*[a-z_\d]+){1,2} # return type
\s+[a-z_\d]+\s* # name of prototype (\s+[a-z_\d]+\s*) # name of prototype
\([a-z_,\.\*\&\[\]\s\d]*\) # arguments \([a-z_,\.\*\&\[\]\s\d]*\) # arguments
)\s*\{ # must end with { )\s*\{ # must end with {
""", """,
@ -334,6 +334,15 @@ class InoToCPPConverter(object):
else: else:
return " " 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): def append_prototypes(self, fname, contents, prototypes):
contents = self.STRIPCOMMENTS_RE.sub(self._replace_comments_callback, contents = self.STRIPCOMMENTS_RE.sub(self._replace_comments_callback,
contents) contents)
@ -358,7 +367,7 @@ class InoToCPPConverter(object):
data = [] data = []
for node in self.nodes: for node in self.nodes:
ino_contents = node.get_text_contents() 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) item = (basename(node.get_path()), ino_contents)
if self.is_main_node(ino_contents): if self.is_main_node(ino_contents):