Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(612)

Unified Diff: tools/gn/substitution_pattern.h

Issue 429423002: Refactor GN source expansions. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « tools/gn/substitution_list.cc ('k') | tools/gn/substitution_pattern.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/gn/substitution_pattern.h
diff --git a/tools/gn/substitution_pattern.h b/tools/gn/substitution_pattern.h
new file mode 100644
index 0000000000000000000000000000000000000000..70fc5eb375a00e4fcc909feaa0d648c9a62e7ea9
--- /dev/null
+++ b/tools/gn/substitution_pattern.h
@@ -0,0 +1,61 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef TOOLS_GN_SUBSTITUTION_PATTERN_H_
+#define TOOLS_GN_SUBSTITUTION_PATTERN_H_
+
+#include <string>
+#include <vector>
+
+#include "tools/gn/substitution_type.h"
+
+class Err;
+class ParseNode;
+class Value;
+
+// Represents a string with {{substitution_patterns}} in them.
+class SubstitutionPattern {
+ public:
+ struct Subrange {
+ Subrange();
+ Subrange(SubstitutionType t, const std::string& l = std::string());
+ ~Subrange();
+
+ SubstitutionType type;
+
+ // When type_ == LITERAL, this specifies the literal.
+ std::string literal;
+ };
+
+ SubstitutionPattern();
+ ~SubstitutionPattern();
+
+ // Parses the given string and fills in the pattern. The pattern must only
+ // be initialized once. On failure, returns false and sets the error.
+ bool Parse(const Value& value, Err* err);
+ bool Parse(const std::string& str, const ParseNode* origin, Err* err);
+
+ // Returns the pattern as a string with substitutions in them.
+ std::string AsString() const;
+
+ // Sets the bits in the given vector corresponding to the substitutions used
+ // by this pattern. SUBSTITUTION_LITERAL is ignored.
+ void FillRequiredTypes(bool required_types[SUBSTITUTION_NUM_TYPES]) const;
+
+ // Returns a vector listing the substitutions used by this pattern, not
+ // counting SUBSTITUTION_LITERAL.
+ const std::vector<SubstitutionType>& required_types() const {
+ return required_types_;
+ }
+
+ const std::vector<Subrange>& ranges() const { return ranges_; }
+ bool empty() const { return ranges_.empty(); }
+
+ private:
+ std::vector<Subrange> ranges_;
+
+ std::vector<SubstitutionType> required_types_;
+};
+
+#endif // TOOLS_GN_SUBSTITUTION_PATTERN_H_
« no previous file with comments | « tools/gn/substitution_list.cc ('k') | tools/gn/substitution_pattern.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698