Diff
Modified: trunk/Tools/ChangeLog (104401 => 104402)
--- trunk/Tools/ChangeLog 2012-01-08 16:21:17 UTC (rev 104401)
+++ trunk/Tools/ChangeLog 2012-01-08 16:46:40 UTC (rev 104402)
@@ -1,5 +1,50 @@
2012-01-04 Kentaro Hara <[email protected]>
+ Rewrite the CSS parser of prepare-ChangeLog with unittests.
+ https://bugs.webkit.org/show_bug.cgi?id=75202
+
+ Reviewed by David Kilzer.
+
+ The current CSS parser can just parse simple CSSes like
+
+ foo bar baz {
+ property1: value;
+ property2: value;
+ }
+
+ , and cannot parse comments nor a CSS in which a selector and {
+ appears in different lines. This patch rewrites the CSS parser
+ (i.e. get_selector_line_ranges_for_css()) so that it can parse more CSSes
+ shown in css_unittests.css.
+
+ Test: Scripts/webkitperl/prepare-ChangeLog_unittest/resources/css_unittests.css
+
+ * Scripts/prepare-ChangeLog:
+ (get_selector_line_ranges_for_css):
+ * Scripts/webkitperl/prepare-ChangeLog_unittest/parser_unittests.pl:
+ * Scripts/webkitperl/prepare-ChangeLog_unittest/resources/css_unittests-expected.txt: Added.
+ * Scripts/webkitperl/prepare-ChangeLog_unittest/resources/css_unittests.css: Added.
+ (element1):
+ (element2):
+ (element3):
+ (element4.p):
+ (element5.p.q.r.s):
+ (element6#p):
+ (element7 element8):
+ (element9.p element10.q):
+ (element11#p element12#q):
+ (element13, element14):
+ (.p):
+ (#p):
+ (.p element15 #q element16.r element17#s):
+ (element18:target):
+ (element19):
+ (element20):
+ (element21):
+ (element22):
+
+2012-01-04 Kentaro Hara <[email protected]>
+
The Perl parser of prepare-ChangeLog can parse here-documents
https://bugs.webkit.org/show_bug.cgi?id=73208
Modified: trunk/Tools/Scripts/prepare-ChangeLog (104401 => 104402)
--- trunk/Tools/Scripts/prepare-ChangeLog 2012-01-08 16:21:17 UTC (rev 104401)
+++ trunk/Tools/Scripts/prepare-ChangeLog 2012-01-08 16:46:40 UTC (rev 104402)
@@ -1393,7 +1393,6 @@
# Read a file and get all the line ranges of the things that look like CSS selectors. A selector is
# anything before an opening brace on a line. A selector starts at the line containing the opening
# brace and ends at the closing brace.
-# FIXME: Comments are parsed just like uncommented text.
#
# Result is a list of triples: [ start_line, end_line, selector ].
@@ -1405,21 +1404,36 @@
my $currentSelector = "";
my $start = 0;
+ my $inComment = 0;
+ my $inBrace = 0;
while (<$fileHandle>) {
- if (/^[ \t]*(.*[^ \t])[ \t]*{/) {
- $currentSelector = $1;
- $start = $.;
- }
- if (index($_, "}") >= 0) {
- unless ($start) {
- warn "mismatched braces in $fileName\n";
- next;
+ foreach my $token (split m-(\{|\}|/\*|\*/)-, $_) {
+ if ($token eq "{") {
+ if (!$inComment) {
+ warn "mismatched brace found in $fileName\n" if $inBrace;
+ $inBrace = 1;
+ }
+ } elsif ($token eq "}") {
+ if (!$inComment) {
+ warn "mismatched brace found in $fileName\n" if !$inBrace;
+ $inBrace = 0;
+ push(@ranges, [$start, $., $currentSelector]);
+ $currentSelector = "";
+ $start = 0;
+ }
+ } elsif ($token eq "/*") {
+ $inComment = 1;
+ } elsif ($token eq "*/") {
+ warn "mismatched comment found in $fileName\n" if !$inComment;
+ $inComment = 0;
+ } else {
+ if (!$inComment and !$inBrace and $token !~ /^[\s\t]*$/) {
+ $token =~ s/^[\s\t]*|[\s\t]*$//g;
+ $currentSelector = $token;
+ $start = $.;
+ }
}
- push(@ranges, [$start, $., $currentSelector]);
- $currentSelector = "";
- $start = 0;
- next;
}
}
Modified: trunk/Tools/Scripts/webkitperl/prepare-ChangeLog_unittest/parser_unittests.pl (104401 => 104402)
--- trunk/Tools/Scripts/webkitperl/prepare-ChangeLog_unittest/parser_unittests.pl 2012-01-08 16:21:17 UTC (rev 104401)
+++ trunk/Tools/Scripts/webkitperl/prepare-ChangeLog_unittest/parser_unittests.pl 2012-01-08 16:46:40 UTC (rev 104402)
@@ -32,11 +32,12 @@
use lib File::Spec->catdir($FindBin::Bin, "..");
use LoadAsModule qw(PrepareChangeLog prepare-ChangeLog);
-my %testFiles = ("perl_unittests.pl" => "perl",
- "python_unittests.py" => "python",
- "java_unittests.java" => "java",
- "cpp_unittests.cpp" => "cpp",
- "_javascript__unittests.js" => "_javascript_",
+my %testFiles = ("perl_unittests.pl" => "get_function_line_ranges_for_perl",
+ "python_unittests.py" => "get_function_line_ranges_for_python",
+ "java_unittests.java" => "get_function_line_ranges_for_java",
+ "cpp_unittests.cpp" => "get_function_line_ranges_for_cpp",
+ "_javascript__unittests.js" => "get_function_line_ranges_for_javascript",
+ "css_unittests.css" => "get_selector_line_ranges_for_css",
);
my $resetResults;
@@ -46,7 +47,7 @@
foreach my $testFile (sort keys %testFiles) {
my $basename = $testFile;
$basename = $1 if $basename =~ /^(.*)\.[^\.]*$/;
- push @testSet, {language => $testFiles{$testFile},
+ push @testSet, {method => $testFiles{$testFile},
inputFile => File::Spec->catdir($FindBin::Bin, "resources", $testFile),
expectedFile => File::Spec->catdir($FindBin::Bin, "resources", $basename . "-expected.txt")};
}
@@ -54,7 +55,7 @@
plan(tests => scalar @testSet);
foreach my $test (@testSet) {
open FH, "< $test->{inputFile}" or die "Cannot open $test->{inputFile}: $!";
- my $parser = eval "\\&PrepareChangeLog::get_function_line_ranges_for_$test->{language}";
+ my $parser = eval "\\&PrepareChangeLog::$test->{method}";
my @actualOutput = $parser->(\*FH, $test->{inputFile});;
close FH;
Added: trunk/Tools/Scripts/webkitperl/prepare-ChangeLog_unittest/resources/css_unittests-expected.txt (0 => 104402)
--- trunk/Tools/Scripts/webkitperl/prepare-ChangeLog_unittest/resources/css_unittests-expected.txt (rev 0)
+++ trunk/Tools/Scripts/webkitperl/prepare-ChangeLog_unittest/resources/css_unittests-expected.txt 2012-01-08 16:46:40 UTC (rev 104402)
@@ -0,0 +1,92 @@
+[
+ [
+ '20',
+ '21',
+ 'element1'
+ ],
+ [
+ '23',
+ '23',
+ 'element2'
+ ],
+ [
+ '25',
+ '27',
+ 'element3'
+ ],
+ [
+ '29',
+ '30',
+ 'element4.p'
+ ],
+ [
+ '32',
+ '33',
+ 'element5.p.q.r.s'
+ ],
+ [
+ '35',
+ '36',
+ 'element6#p'
+ ],
+ [
+ '38',
+ '39',
+ 'element7 element8'
+ ],
+ [
+ '41',
+ '42',
+ 'element9.p element10.q'
+ ],
+ [
+ '44',
+ '45',
+ 'element11#p element12#q'
+ ],
+ [
+ '47',
+ '48',
+ 'element13, element14'
+ ],
+ [
+ '50',
+ '51',
+ '.p'
+ ],
+ [
+ '53',
+ '55',
+ '#p'
+ ],
+ [
+ '57',
+ '58',
+ '.p element15 #q element16.r element17#s'
+ ],
+ [
+ '60',
+ '61',
+ 'element18:target'
+ ],
+ [
+ '63',
+ '65',
+ 'element19'
+ ],
+ [
+ '67',
+ '69',
+ 'element20'
+ ],
+ [
+ '71',
+ '74',
+ 'element21'
+ ],
+ [
+ '76',
+ '79',
+ 'element22'
+ ]
+]
Added: trunk/Tools/Scripts/webkitperl/prepare-ChangeLog_unittest/resources/css_unittests.css (0 => 104402)
--- trunk/Tools/Scripts/webkitperl/prepare-ChangeLog_unittest/resources/css_unittests.css (rev 0)
+++ trunk/Tools/Scripts/webkitperl/prepare-ChangeLog_unittest/resources/css_unittests.css 2012-01-08 16:46:40 UTC (rev 104402)
@@ -0,0 +1,85 @@
+/*
+ * Copyright (C) 2011 Google Inc. All rights reserved.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+element1 {
+}
+
+element2 { }
+
+element3
+{
+}
+
+element4.p {
+}
+
+element5.p.q.r.s {
+}
+
+element6#p {
+}
+
+element7 element8 {
+}
+
+element9.p element10.q {
+}
+
+element11#p element12#q {
+}
+
+element13, element14 {
+}
+
+.p {
+}
+
+#p {
+
+}
+
+.p element15 #q element16.r element17#s {
+}
+
+element18:target {
+}
+
+element19 {
+ property1: 123
+}
+
+element20 {
+ property1: 123;
+}
+
+element21 {
+ property1: 123;
+ property2: 456;
+}
+
+element22 {
+ property1: 123;
+ /* comment */
+}
+
+/*
+elementInsideComment {
+ property1: 123;
+}
+*/