Changeset 104402 in webkit
- Timestamp:
- Jan 8, 2012 8:46:40 AM (12 years ago)
- Location:
- trunk/Tools
- Files:
-
- 2 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Tools/ChangeLog
r104401 r104402 1 2012-01-04 Kentaro Hara <haraken@chromium.org> 2 3 Rewrite the CSS parser of prepare-ChangeLog with unittests. 4 https://bugs.webkit.org/show_bug.cgi?id=75202 5 6 Reviewed by David Kilzer. 7 8 The current CSS parser can just parse simple CSSes like 9 10 foo bar baz { 11 property1: value; 12 property2: value; 13 } 14 15 , and cannot parse comments nor a CSS in which a selector and { 16 appears in different lines. This patch rewrites the CSS parser 17 (i.e. get_selector_line_ranges_for_css()) so that it can parse more CSSes 18 shown in css_unittests.css. 19 20 Test: Scripts/webkitperl/prepare-ChangeLog_unittest/resources/css_unittests.css 21 22 * Scripts/prepare-ChangeLog: 23 (get_selector_line_ranges_for_css): 24 * Scripts/webkitperl/prepare-ChangeLog_unittest/parser_unittests.pl: 25 * Scripts/webkitperl/prepare-ChangeLog_unittest/resources/css_unittests-expected.txt: Added. 26 * Scripts/webkitperl/prepare-ChangeLog_unittest/resources/css_unittests.css: Added. 27 (element1): 28 (element2): 29 (element3): 30 (element4.p): 31 (element5.p.q.r.s): 32 (element6#p): 33 (element7 element8): 34 (element9.p element10.q): 35 (element11#p element12#q): 36 (element13, element14): 37 (.p): 38 (#p): 39 (.p element15 #q element16.r element17#s): 40 (element18:target): 41 (element19): 42 (element20): 43 (element21): 44 (element22): 45 1 46 2012-01-04 Kentaro Hara <haraken@chromium.org> 2 47 -
trunk/Tools/Scripts/prepare-ChangeLog
r104401 r104402 1394 1394 # anything before an opening brace on a line. A selector starts at the line containing the opening 1395 1395 # brace and ends at the closing brace. 1396 # FIXME: Comments are parsed just like uncommented text.1397 1396 # 1398 1397 # Result is a list of triples: [ start_line, end_line, selector ]. … … 1406 1405 my $currentSelector = ""; 1407 1406 my $start = 0; 1407 my $inComment = 0; 1408 my $inBrace = 0; 1408 1409 1409 1410 while (<$fileHandle>) { 1410 if (/^[ \t]*(.*[^ \t])[ \t]*{/) { 1411 $currentSelector = $1; 1412 $start = $.; 1413 } 1414 if (index($_, "}") >= 0) { 1415 unless ($start) { 1416 warn "mismatched braces in $fileName\n"; 1417 next; 1418 } 1419 push(@ranges, [$start, $., $currentSelector]); 1420 $currentSelector = ""; 1421 $start = 0; 1422 next; 1411 foreach my $token (split m-(\{|\}|/\*|\*/)-, $_) { 1412 if ($token eq "{") { 1413 if (!$inComment) { 1414 warn "mismatched brace found in $fileName\n" if $inBrace; 1415 $inBrace = 1; 1416 } 1417 } elsif ($token eq "}") { 1418 if (!$inComment) { 1419 warn "mismatched brace found in $fileName\n" if !$inBrace; 1420 $inBrace = 0; 1421 push(@ranges, [$start, $., $currentSelector]); 1422 $currentSelector = ""; 1423 $start = 0; 1424 } 1425 } elsif ($token eq "/*") { 1426 $inComment = 1; 1427 } elsif ($token eq "*/") { 1428 warn "mismatched comment found in $fileName\n" if !$inComment; 1429 $inComment = 0; 1430 } else { 1431 if (!$inComment and !$inBrace and $token !~ /^[\s\t]*$/) { 1432 $token =~ s/^[\s\t]*|[\s\t]*$//g; 1433 $currentSelector = $token; 1434 $start = $.; 1435 } 1436 } 1423 1437 } 1424 1438 } -
trunk/Tools/Scripts/webkitperl/prepare-ChangeLog_unittest/parser_unittests.pl
r104400 r104402 33 33 use LoadAsModule qw(PrepareChangeLog prepare-ChangeLog); 34 34 35 my %testFiles = ("perl_unittests.pl" => "perl", 36 "python_unittests.py" => "python", 37 "java_unittests.java" => "java", 38 "cpp_unittests.cpp" => "cpp", 39 "javascript_unittests.js" => "javascript", 35 my %testFiles = ("perl_unittests.pl" => "get_function_line_ranges_for_perl", 36 "python_unittests.py" => "get_function_line_ranges_for_python", 37 "java_unittests.java" => "get_function_line_ranges_for_java", 38 "cpp_unittests.cpp" => "get_function_line_ranges_for_cpp", 39 "javascript_unittests.js" => "get_function_line_ranges_for_javascript", 40 "css_unittests.css" => "get_selector_line_ranges_for_css", 40 41 ); 41 42 … … 47 48 my $basename = $testFile; 48 49 $basename = $1 if $basename =~ /^(.*)\.[^\.]*$/; 49 push @testSet, { language=> $testFiles{$testFile},50 push @testSet, {method => $testFiles{$testFile}, 50 51 inputFile => File::Spec->catdir($FindBin::Bin, "resources", $testFile), 51 52 expectedFile => File::Spec->catdir($FindBin::Bin, "resources", $basename . "-expected.txt")}; … … 55 56 foreach my $test (@testSet) { 56 57 open FH, "< $test->{inputFile}" or die "Cannot open $test->{inputFile}: $!"; 57 my $parser = eval "\\&PrepareChangeLog:: get_function_line_ranges_for_$test->{language}";58 my $parser = eval "\\&PrepareChangeLog::$test->{method}"; 58 59 my @actualOutput = $parser->(\*FH, $test->{inputFile});; 59 60 close FH;
Note: See TracChangeset
for help on using the changeset viewer.