Skip to content

Commit

Permalink
Sync from Google (#26854)
Browse files Browse the repository at this point in the history
* Internal refactor

PiperOrigin-RevId: 289008926

* Internal refactor

PiperOrigin-RevId: 289950482

* Revert entities.json

* prettify readme

* prettify again
  • Loading branch information
honeybadgerdontcare committed Feb 19, 2020
1 parent f3b5d77 commit abb47cd
Show file tree
Hide file tree
Showing 97 changed files with 23,460 additions and 113 deletions.
7 changes: 4 additions & 3 deletions validator/htmlparser/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@ limitations under the License.

# HTML Parser

This is an HTML5 compliant parser, created to be used by the [AMPHTML
Validator](https://github.com/ampproject/amphtml/tree/master/validator) to
standardize how AMPHTML documents should be parsed for validation.
This is an HTML5 compliant parser written in C++. It was created to be used by
the
[AMPHTML Validator](https://github.com/ampproject/amphtml/tree/master/validator)
to standardize how AMPHTML documents should be parsed for AMP validation.

It is maintained by the [AMP Working Group](https://amp.dev/community/working-groups/amp4email/):
[Caching](https://amp.dev/community/working-groups/caching/)
Expand Down
4 changes: 2 additions & 2 deletions validator/htmlparser/atomutil.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
// limitations under the license.
//

#include "htmlparser/atomutil.h"
#include "atomutil.h"

#include "htmlparser/hash.h"
#include "hash.h"

namespace htmlparser {

Expand Down
2 changes: 1 addition & 1 deletion validator/htmlparser/atomutil.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

#include <string>

#include "htmlparser/atom.h"
#include "atom.h"

namespace htmlparser {

Expand Down
4 changes: 2 additions & 2 deletions validator/htmlparser/atomutil_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
// limitations under the license.
//

#include "htmlparser/atomutil.h"
#include "atomutil.h"

#include "gtest/gtest.h"
#include "htmlparser/hash.h"
#include "hash.h"

TEST(AtomUtilTest, StringToAtom) {
// String to atom.
Expand Down
22 changes: 11 additions & 11 deletions validator/htmlparser/bin/atomgen.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@
#include <utility>
#include <vector>

#include "htmlparser/defer.h"
#include "htmlparser/fileutil.h"
#include "htmlparser/hash.h"
#include "htmlparser/strings.h"
#include "htmlparser/token.h"
#include "defer.h"
#include "fileutil.h"
#include "hash.h"
#include "strings.h"
#include "token.h"

namespace htmlparser {

Expand Down Expand Up @@ -183,17 +183,17 @@ int main(int argc, char** argv) {
};

if (!(FileUtil::ReadFileLines(
options, "htmlparser/data/htmltags.txt", &all_names) &&
options, "data/htmltags.txt", &all_names) &&
FileUtil::ReadFileLines(
options, "htmlparser/data/htmlattributes.txt",
options, "data/htmlattributes.txt",
&all_names) &&
FileUtil::ReadFileLines(
options, "htmlparser/data/javascriptevents.txt",
options, "data/javascriptevents.txt",
&all_names) &&
FileUtil::ReadFileLines(
options, "htmlparser/data/extras.txt", &all_names) &&
options, "data/extras.txt", &all_names) &&
FileUtil::ReadFileLines(
options, "htmlparser/data/amptags.txt", &all_names))) {
options, "data/amptags.txt", &all_names))) {
std::cerr << "Error reading input txt files." << std::endl;
return EXIT_FAILURE;
}
Expand Down Expand Up @@ -297,7 +297,7 @@ int main(int argc, char** argv) {
nameToTextOffset[s] = static_cast<uint32_t>(offset << 8 | s.size());
}

std::ofstream fd("htmlparser/atom.h");
std::ofstream fd("atom.h");
Defer ____([&]() {fd.close();});

fd << R"(//
Expand Down
8 changes: 4 additions & 4 deletions validator/htmlparser/bin/casetablegen.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
#include <sstream>
#include <utility>

#include "htmlparser/defer.h"
#include "htmlparser/fileutil.h"
#include "defer.h"
#include "fileutil.h"

const char kFileHeader[] =
R"HEADER(//
Expand Down Expand Up @@ -55,7 +55,7 @@ const char kFileHeader[] =
#include <algorithm>
#include <utility>
#include "htmlparser/comparators.h"
#include "comparators.h"
namespace htmlparser {
Expand Down Expand Up @@ -170,7 +170,7 @@ int main(int argc, char** argv) {
return EXIT_FAILURE;
}

std::ofstream fd("htmlparser/casetable.h");
std::ofstream fd("casetable.h");
htmlparser::Defer __([&]() {fd.close();});

fd << kFileHeader;
Expand Down
12 changes: 6 additions & 6 deletions validator/htmlparser/bin/entitytablegen.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@
#include <utility>
#include <vector>

#include "htmlparser/defer.h"
#include "htmlparser/fileutil.h"
#include "htmlparser/strings.h"
#include "defer.h"
#include "fileutil.h"
#include "strings.h"

const char kFileHeader[] =
R"HEADER(//
Expand Down Expand Up @@ -57,7 +57,7 @@ const char kFileHeader[] =
#include <string>
#include <string_view>
#include "htmlparser/comparators.h"
#include "comparators.h"
namespace htmlparser {
Expand Down Expand Up @@ -135,7 +135,7 @@ int main(int argc, char** argv) {
options.white_space_transform =
htmlparser::FileReadOptions::LineTransforms::StripWhitespace();
if (!htmlparser::FileUtil::ReadFileLines(
options, "htmlparser/data/entities.json", &lines)) {
options, "data/entities.json", &lines)) {
std::cerr << "Error reading input file." << std::endl;
return EXIT_FAILURE;
}
Expand All @@ -145,7 +145,7 @@ int main(int argc, char** argv) {
return EXIT_FAILURE;
}

std::ofstream fd("htmlparser/entity.h");
std::ofstream fd("entity.h");
htmlparser::Defer __([&]() {fd.close();});

fd << kFileHeader;
Expand Down
2 changes: 1 addition & 1 deletion validator/htmlparser/casetable.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#include <algorithm>
#include <utility>

#include "htmlparser/comparators.h"
#include "comparators.h"

namespace htmlparser {

Expand Down
4 changes: 2 additions & 2 deletions validator/htmlparser/casetable_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
// limitations under the license.
//

#include "htmlparser/casetable.h"
#include "casetable.h"

#include "gtest/gtest.h"
#include "htmlparser/strings.h"
#include "strings.h"

// Just one test to ensure table mapping is correct.
TEST(CasetableTest, TestTableMappingIsCorrect) {
Expand Down
4 changes: 2 additions & 2 deletions validator/htmlparser/doctype.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@
// limitations under the license.
//

#include "htmlparser/doctype.h"
#include "doctype.h"

#include <sstream>

#include "htmlparser/strings.h"
#include "strings.h"

namespace htmlparser {

Expand Down
2 changes: 1 addition & 1 deletion validator/htmlparser/doctype.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#include <string_view>
#include <tuple>

#include "htmlparser/node.h"
#include "node.h"

namespace htmlparser {

Expand Down
2 changes: 1 addition & 1 deletion validator/htmlparser/doctype_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
// limitations under the license.
//

#include "htmlparser/doctype.h"
#include "doctype.h"

#include "gtest/gtest.h"

Expand Down
2 changes: 1 addition & 1 deletion validator/htmlparser/elements.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

#include <array>

#include "htmlparser/atom.h"
#include "atom.h"

namespace htmlparser {

Expand Down
2 changes: 1 addition & 1 deletion validator/htmlparser/entity.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
#include <string>
#include <string_view>

#include "htmlparser/comparators.h"
#include "comparators.h"

namespace htmlparser {

Expand Down
2 changes: 1 addition & 1 deletion validator/htmlparser/entity_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
// limitations under the license.
//

#include "htmlparser/entity.h"
#include "entity.h"

#include "gtest/gtest.h"

Expand Down
2 changes: 1 addition & 1 deletion validator/htmlparser/error.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
// limitations under the license.
//

#include "htmlparser/error.h"
#include "error.h"

namespace htmlparser {

Expand Down
8 changes: 4 additions & 4 deletions validator/htmlparser/fileutil.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
// limitations under the license.
//

#include "htmlparser/fileutil.h"
#include "fileutil.h"

#include <glob.h>

Expand All @@ -23,9 +23,9 @@
#include <iostream>
#include <sstream>

#include "htmlparser/defer.h"
#include "htmlparser/error.h"
#include "htmlparser/strings.h"
#include "defer.h"
#include "error.h"
#include "strings.h"

namespace htmlparser {

Expand Down
2 changes: 1 addition & 1 deletion validator/htmlparser/fileutil_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
// limitations under the license.
//

#include "htmlparser/fileutil.h"
#include "fileutil.h"

#include <vector>

Expand Down
6 changes: 3 additions & 3 deletions validator/htmlparser/foreign.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@
// limitations under the license.
//

#include "htmlparser/foreign.h"
#include "foreign.h"

#include <algorithm>

#include "htmlparser/comparators.h"
#include "htmlparser/strings.h"
#include "comparators.h"
#include "strings.h"

namespace htmlparser {

Expand Down
2 changes: 1 addition & 1 deletion validator/htmlparser/foreign.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#include <string>
#include <string_view>

#include "htmlparser/node.h"
#include "node.h"

namespace htmlparser {

Expand Down
18 changes: 9 additions & 9 deletions validator/htmlparser/htmldataset_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@
#include <vector>

#include "gtest/gtest.h"
#include "htmlparser/atomutil.h"
#include "htmlparser/defer.h"
#include "htmlparser/fileutil.h"
#include "htmlparser/node.h"
#include "htmlparser/parser.h"
#include "htmlparser/renderer.h"
#include "htmlparser/strings.h"
#include "htmlparser/testconstants.h"
#include "htmlparser/tokenizer.h"
#include "atomutil.h"
#include "defer.h"
#include "fileutil.h"
#include "node.h"
#include "parser.h"
#include "renderer.h"
#include "strings.h"
#include "testconstants.h"
#include "tokenizer.h"

using namespace htmlparser;

Expand Down
2 changes: 1 addition & 1 deletion validator/htmlparser/navigator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
// limitations under the license.
//

#include "htmlparser/navigator.h"
#include "navigator.h"

namespace htmlparser {

Expand Down
2 changes: 1 addition & 1 deletion validator/htmlparser/navigator.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

#include <string>

#include "htmlparser/node.h"
#include "node.h"

namespace htmlparser {

Expand Down
6 changes: 3 additions & 3 deletions validator/htmlparser/navigator_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@
// limitations under the license.
//

#include "htmlparser/navigator.h"
#include "navigator.h"

#include <iostream>

#include "gtest/gtest.h"
#include "htmlparser/node.h"
#include "htmlparser/parser.h"
#include "node.h"
#include "parser.h"

using namespace htmlparser;

Expand Down
6 changes: 3 additions & 3 deletions validator/htmlparser/node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@
// limitations under the license.
//

#include "htmlparser/node.h"
#include "node.h"

#include <algorithm>
#include <functional>
#include <sstream>

#include "base/logging.h"
#include "htmlparser/atomutil.h"
#include "htmlparser/elements.h"
#include "atomutil.h"
#include "elements.h"

namespace htmlparser {

Expand Down

0 comments on commit abb47cd

Please sign in to comment.