// Copyright 2006 The RE2 Authors. All Rights Reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. // Format a regular expression structure as a string. // Tested by parse_test.cc #include <string.h> #include <string> #include "absl/log/absl_log.h" #include "absl/strings/str_format.h" #include "re2/regexp.h" #include "re2/walker-inl.h" #include "util/utf.h" namespace re2 { enum { … }; // Helper function. See description below. static void AppendCCRange(std::string* t, Rune lo, Rune hi); // Walker to generate string in s_. // The arg pointers are actually integers giving the // context precedence. // The child_args are always NULL. class ToStringWalker : public Regexp::Walker<int> { … }; std::string Regexp::ToString() { … } #define ToString … // Visits re before children are processed. // Appends ( if needed and passes new precedence to children. int ToStringWalker::PreVisit(Regexp* re, int parent_arg, bool* stop) { … } static void AppendLiteral(std::string *t, Rune r, bool foldcase) { … } // Visits re after children are processed. // For childless regexps, all the work is done here. // For regexps with children, append any unary suffixes or ). int ToStringWalker::PostVisit(Regexp* re, int parent_arg, int pre_arg, int* child_args, int nchild_args) { … } // Appends a rune for use in a character class to the string t. static void AppendCCChar(std::string* t, Rune r) { … } static void AppendCCRange(std::string* t, Rune lo, Rune hi) { … } } // namespace re2