diff --git a/lib/cmock_header_parser.rb b/lib/cmock_header_parser.rb index 6ec1555..98e1dd6 100644 --- a/lib/cmock_header_parser.rb +++ b/lib/cmock_header_parser.rb @@ -5,8 +5,7 @@ class CMockHeaderParser def initialize(source, cfg) @funcs = [] @c_attributes = cfg.attributes - @declaration_parse_matcher = /([\d\w\s\*\(\),]+??)\(([\d\w\s\*\(\),\.]*)\)/m - @braces_matcher = /(\{|\})/m + @declaration_parse_matcher = /([\d\w\s\*\(\),]+??)\(([\d\w\s\*\(\),\.]*)\)$/m import_source(source) end @@ -26,12 +25,12 @@ class CMockHeaderParser def import_source(source) source.gsub!(/\s*\\\s*/m, ' ') # smush multiline into single line - source.gsub!(/\/\/.*$/, '') # remove line comments source.gsub!(/\/\*.*?\*\//m, '') # remove block comments + source.gsub!(/\/\/.*$/, '') # remove line comments source.gsub!(/#.*/, '') # remove preprocessor statements source.gsub!(/typedef.*/, '') # remove typedef statements - @src_lines = source.split(/;/) + @src_lines = source.split(/\s*;\s*/) @src_lines.delete_if {|line| line.strip.length == 0} # remove blank lines end diff --git a/test/unit/cmock_header_parser_test.rb b/test/unit/cmock_header_parser_test.rb index b458ad6..efaa8c1 100644 --- a/test/unit/cmock_header_parser_test.rb +++ b/test/unit/cmock_header_parser_test.rb @@ -27,7 +27,7 @@ class CMockHeaderParserTest < Test::Unit::TestCase expected = [ " abcd", - "\n\nwho \n" + "who \n" ] assert_equal(expected, @parser.src_lines) @@ -38,14 +38,14 @@ class CMockHeaderParserTest < Test::Unit::TestCase " abcd;\n" + "/* hello;*/\n" + "who /* is you\n" + - "whatdya say? */\n" + + "// embedded line comment */\n" + "/* shizzzle*/" @parser = CMockHeaderParser.new(source, @config) expected = [ " abcd", - "\n\nwho \n" + "who \n" ] assert_equal(expected, @parser.src_lines) @@ -121,7 +121,9 @@ class CMockHeaderParserTest < Test::Unit::TestCase "void FunkyChicken (\n uint la,\n int de,\n bool da);\n" + "void\n shiz(void);\n" + "void tat();\n" + - "#define get_foo() \\\n (Thing)foo())" # should extract no function declarations + # following lines should yield no function declarations + "#define get_foo() \\\n (Thing)foo())\n" + + "array_type[((U8)10)];\n" @parser = CMockHeaderParser.new(source, @config) parsed_stuff = @parser.parse