From 3c02ca5750acf9af814cc12b4ad0547d452ed831 Mon Sep 17 00:00:00 2001 From: Steffen Smolka Date: Fri, 5 Mar 2021 08:36:09 -0800 Subject: [PATCH] Use abseil-version of RE2. (#60) PiperOrigin-RevId: 361105743 Co-authored-by: PINS Team --- gutils/protocol_buffer_matchers.cc | 4 ++-- p4_constraints/backend/constraint_info.cc | 3 +-- p4_constraints/frontend/lexer.cc | 19 ++++++++++--------- p4_constraints/frontend/lexer.h | 4 ++-- p4_constraints_deps.bzl | 8 ++++---- 5 files changed, 19 insertions(+), 19 deletions(-) diff --git a/gutils/protocol_buffer_matchers.cc b/gutils/protocol_buffer_matchers.cc index 180c214..825d889 100644 --- a/gutils/protocol_buffer_matchers.cc +++ b/gutils/protocol_buffer_matchers.cc @@ -178,7 +178,7 @@ class IgnoreFieldPathCriteria }; namespace { -bool Consume(re2::StringPiece* s, re2::StringPiece x) { +bool Consume(absl::string_view* s, absl::string_view x) { // We use the implementation of ABSL's StartsWith here until we can pick up a // dependency on Abseil. if (x.empty() || @@ -209,7 +209,7 @@ ParseFieldPathOrDie(const std::string& relative_field_path, const RE2 field_subscript_regex(R"(([^.()[\]]+)\[(\d+)\])"); const RE2 extension_regex(R"(\(([^)]+)\))"); - re2::StringPiece input(relative_field_path); + absl::string_view input(relative_field_path); while (!input.empty()) { // Consume a dot, except on the first iteration. if (input.size() < relative_field_path.size() && !Consume(&input, ".")) { diff --git a/p4_constraints/backend/constraint_info.cc b/p4_constraints/backend/constraint_info.cc index e7c26d8..cd13d72 100644 --- a/p4_constraints/backend/constraint_info.cc +++ b/p4_constraints/backend/constraint_info.cc @@ -33,7 +33,6 @@ #include "p4_constraints/frontend/lexer.h" #include "p4_constraints/frontend/parser.h" #include "re2/re2.h" -#include "re2/stringpiece.h" namespace p4_constraints { @@ -62,7 +61,7 @@ absl::StatusOr> ParseTableConstraint( ast::SourceLocation location; int line = 0; absl::string_view constraint = ""; - for (re2::StringPiece annotation : table.preamble().annotations()) { + for (absl::string_view annotation : table.preamble().annotations()) { if (RE2::Consume(&annotation, file_annotation, location.mutable_file_path())) continue; diff --git a/p4_constraints/frontend/lexer.cc b/p4_constraints/frontend/lexer.cc index 7fca091..3014dbd 100644 --- a/p4_constraints/frontend/lexer.cc +++ b/p4_constraints/frontend/lexer.cc @@ -18,12 +18,12 @@ #include #include +#include "absl/strings/string_view.h" #include "glog/logging.h" #include "p4_constraints/ast.h" #include "p4_constraints/ast.pb.h" #include "p4_constraints/frontend/token.h" #include "re2/re2.h" -#include "re2/stringpiece.h" namespace p4_constraints { @@ -31,7 +31,7 @@ namespace { // Consumes characters from the input until the string "*/" appears or the input // is exhausted, updating the given SourceLocation accordingly. -void SwallowMultiLineComment(re2::StringPiece* input, +void SwallowMultiLineComment(absl::string_view* input, ast::SourceLocation* location) { static const LazyRE2 kCommentRegexp{ // Important: the ordering matters, since the first matching case applies! @@ -40,9 +40,9 @@ void SwallowMultiLineComment(re2::StringPiece* input, // (first case) did not match. "|((?:\\r\\n?)|\\n)" // Newline. }; - re2::StringPiece end_of_comment = ""; - re2::StringPiece comment = ""; - re2::StringPiece newline = ""; + absl::string_view end_of_comment = ""; + absl::string_view comment = ""; + absl::string_view newline = ""; while (RE2::Consume(input, *kCommentRegexp, &end_of_comment, &comment, &newline)) { if (!end_of_comment.empty()) { @@ -93,8 +93,9 @@ const LazyRE2 kTokenPattern{ }; // Access capture group in kTokenPattern by name. -re2::StringPiece CaptureByName(const std::string& group_name, - const std::vector& captures) { +absl::string_view CaptureByName( + const std::string& group_name, + const std::vector& captures) { auto iter = kTokenPattern->NamedCapturingGroups().find(group_name); if (iter != kTokenPattern->NamedCapturingGroups().end()) { return captures[iter->second]; @@ -106,7 +107,7 @@ re2::StringPiece CaptureByName(const std::string& group_name, } // namespace -std::vector Tokenize(re2::StringPiece input, +std::vector Tokenize(absl::string_view input, ast::SourceLocation start_location) { // Output. std::vector tokens; @@ -119,7 +120,7 @@ std::vector Tokenize(re2::StringPiece input, const int capture_count = kTokenPattern->NumberOfCapturingGroups() + 1; // We will have RE2 store the strings matched by each capturing group here. - std::vector captures(capture_count); + std::vector captures(capture_count); while (kTokenPattern->Match(input, 0, input.size(), RE2::Anchor::ANCHOR_START, captures.data(), capture_count)) { diff --git a/p4_constraints/frontend/lexer.h b/p4_constraints/frontend/lexer.h index e31d376..11e70e2 100644 --- a/p4_constraints/frontend/lexer.h +++ b/p4_constraints/frontend/lexer.h @@ -37,9 +37,9 @@ #include +#include "absl/strings/string_view.h" #include "p4_constraints/ast.pb.h" #include "p4_constraints/frontend/token.h" -#include "re2/stringpiece.h" namespace p4_constraints { @@ -47,7 +47,7 @@ namespace p4_constraints { // is total; syntax errors are signaled by emitting an UNEXPECTED_CHAR token. // The final token in the returned token sequence is guaranteed to be an // END_OF_INPUT or UNEXPECTED_CHAR token. -std::vector Tokenize(re2::StringPiece input, +std::vector Tokenize(absl::string_view input, ast::SourceLocation start_location); } // namespace p4_constraints diff --git a/p4_constraints_deps.bzl b/p4_constraints_deps.bzl index 87f0006..40b97f8 100644 --- a/p4_constraints_deps.bzl +++ b/p4_constraints_deps.bzl @@ -35,11 +35,11 @@ def p4_constraints_deps(): sha256 = "6dd0f6b20094910fbb7f1f7908688df01af2d4f6c5c21331b9f636048674aebf", ) if not native.existing_rule("com_googlesource_code_re2"): - http_archive( + git_repository( name = "com_googlesource_code_re2", - url = "https://github.com/google/re2/archive/2020-07-06.tar.gz", - strip_prefix = "re2-2020-07-06", - sha256 = "2e9489a31ae007c81e90e8ec8a15d62d58a9c18d4fd1603f6441ef248556b41f", + # Newest commit on `abseil` branch on 2021-03-05. + commit = "72f110e82ccf3a9ae1c9418bfb447c3ba1cf95c2", + remote = "https://github.com/google/re2", ) if not native.existing_rule("rules_proto"): http_archive(