Merge pull request #114 from JaskoWojtek/master

Improve handling of braces in function definition (Thanks @JaskoWojtek !)
This commit is contained in:
Mark VanderVoord
2017-04-05 15:08:38 -04:00
committed by GitHub
2 changed files with 15 additions and 2 deletions
+1 -2
View File
@@ -94,8 +94,7 @@ class CMockHeaderParser
end
# remove nested pairs of braces because no function declarations will be inside of them (leave outer pair for function definition detection)
while source.gsub!(/\{[^\{\}]*\{[^\{\}]*\}[^\{\}]*\}/m, '{ }')
end
source.gsub!(/\{([^\{\}]*|\g<0>)*\}/m, '{ }')
# remove function definitions by stripping off the arguments right now
source.gsub!(/\([^\)]*\)\s*\{[^\}]*\}/m, ";")
+14
View File
@@ -325,6 +325,18 @@ describe CMockHeaderParser, "Verify CMockHeaderParser Module" do
"{\n" +
" bar((unsigned int) a);\n" +
" stripme(a);\n" +
"}\n" +
"uint32 func_with_decl_c(unsigned int);\n" +
"uint32 func_with_decl_c(unsigned int a)\n" +
"{\n" +
" if(a > 0)\n" +
" {\n" +
" return 1;\n" +
" }\n" +
" else\n"+
" {\n" +
" return 2;\n" +
" }\n" +
"}\n"
expected =
@@ -333,6 +345,8 @@ describe CMockHeaderParser, "Verify CMockHeaderParser Module" do
"uint32 func_with_decl_a", #okay. it's not going to be interpretted as another function
"uint32 func_with_decl_b(unsigned int)",
"uint32 func_with_decl_b", #okay. it's not going to be interpretted as another function
"uint32 func_with_decl_c(unsigned int)",
"uint32 func_with_decl_c", #okay. it's not going to be interpretted as another function
]
assert_equal(expected, @parser.import_source(source).map!{|s|s.strip})