Fix bug with order for "includes" in conversation from INO/PDE to CPP

This commit is contained in:
Ivan Kravets
2014-09-30 20:55:08 +03:00
parent 09761004dd
commit 2a7e67b8e4
2 changed files with 13 additions and 4 deletions

View File

@ -4,6 +4,8 @@ Release History
0.8.0 (?) 0.8.0 (?)
--------- ---------
* Fixed bug with order for includes in conversation from INO/PDE to CPP
0.7.0 (2014-09-24) 0.7.0 (2014-09-24)
------------------ ------------------

View File

@ -173,22 +173,29 @@ def ConvertInotoCpp(env):
continue continue
ino_contents = item.get_text_contents() ino_contents = item.get_text_contents()
# fetch prototypes re_includes = re.compile(r"^(#include\s+(?:\<|\")[^\r\n]+)",
regexp = re.compile( re.M | re.I)
includes = re_includes.findall(ino_contents)
prototypes = re.findall(
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]*\) # args \([a-z_,\.\*\&\[\]\s\d]*\) # args
)\s*\{ # must end with { )\s*\{ # must end with {
""", """,
ino_contents,
re.X | re.M | re.I re.X | re.M | re.I
) )
prototypes = regexp.findall(ino_contents) # print includes, prototypes
# print prototypes
# disable previous includes
ino_contents = re_includes.sub("//\g<1>", ino_contents)
# create new temporary C++ valid file # create new temporary C++ valid file
with open(cppfile, "w") as f: with open(cppfile, "w") as f:
f.write("#include <Arduino.h>\n") f.write("#include <Arduino.h>\n")
if includes:
f.write("%s\n" % "\n".join(includes))
if prototypes: if prototypes:
f.write("%s;\n" % ";\n".join(prototypes)) f.write("%s;\n" % ";\n".join(prototypes))
f.write("#line 1 \"%s\"\n" % basename(item.path)) f.write("#line 1 \"%s\"\n" % basename(item.path))