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

Unified Diff: chrome/tools/profile_reset/jtl_parser.h

Issue 24998003: Compiler for the JSON Traversal Language. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed linker errors on Win. Created 7 years, 2 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 | « chrome/tools/profile_reset/jtl_compiler_unittest.cc ('k') | chrome/tools/profile_reset/jtl_parser.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/tools/profile_reset/jtl_parser.h
diff --git a/chrome/tools/profile_reset/jtl_parser.h b/chrome/tools/profile_reset/jtl_parser.h
new file mode 100644
index 0000000000000000000000000000000000000000..e758211ecbc9449c00b0b3bf8aef479b0c1fd223
--- /dev/null
+++ b/chrome/tools/profile_reset/jtl_parser.h
@@ -0,0 +1,83 @@
+// Copyright 2013 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 CHROME_TOOLS_PROFILE_RESET_JTL_PARSER_H_
+#define CHROME_TOOLS_PROFILE_RESET_JTL_PARSER_H_
+
+#include <string>
+#include <vector>
+
+#include "base/basictypes.h"
+#include "base/memory/scoped_ptr.h"
+#include "base/values.h"
+
+// Parses text-based JTL source code into a stream of operation names, arguments
+// and separator kinds.
+class JtlParser {
+ public:
+ // Creates a new parser to parse |compacted_source_code|, which should already
+ // be stripped of all comments and whitespace (except inside string literals).
+ // Use RemoveCommentsAndAllWhitespace() to manufacture these arguments, also
+ // see its comments for a description of |newline_indices|.
+ JtlParser(const std::string& compacted_source_code,
+ const std::vector<size_t>& newline_indices);
+ ~JtlParser();
+
+ // Removes comments from |verbose_text| and compacts it into whitespace-free
+ // format (except inside string literals). Elements in |newline_indices| will
+ // be monotonically increasing and will refer to positions in |compacted_text|
+ // such that a new line has been removed before that position.
+ // Example:
+ // verbose_text = "H e l l o // my\n"
+ // " dear \n"
+ // "\n"
+ // "world\" ! \""
+ // compacted_text = "Hellodearworld\" ! \""
+ // 01234567890123...
+ // newline_indices = {5, 9, 9}
+ // Returns true on success, false if there were unmatched quotes in a line, in
+ // which case |error_line_number| will be set accordingly if it is non-NULL.
+ static bool RemoveCommentsAndAllWhitespace(
+ const std::string& verbose_text,
+ std::string* compacted_text,
+ std::vector<size_t>* newline_indices,
+ size_t* error_line_number);
+
+ // Returns true if the entire input has been successfully consumed. Note that
+ // even when this returns false, a subsequent call to ParseNextOperation()
+ // might still fail if the next operation cannot be parsed.
+ bool HasFinished();
+
+ // Fetches the |name| and the |argument_list| of the next operation, and also
+ // whether or not it |ends_the_sentence|, i.e. it is followed by the
+ // end-of-sentence separator.
+ // Returns false if there is a parsing error, in which case the values for the
+ // output parameters are undefined, and |this| parser shall no longer be used.
+ bool ParseNextOperation(std::string* name,
+ base::ListValue* argument_list,
+ bool* ends_the_sentence);
+
+ // Returns the compacted source code that was passed in to the constructor.
+ const std::string& compacted_source() const { return compacted_source_; }
+
+ // Returns at which line the character at position |compacted_index| in the
+ // |compacted_source()| was originally located.
+ size_t GetOriginalLineNumber(size_t compacted_index) const;
+
+ size_t GetLastLineNumber() const;
+ std::string GetLastContext() const;
+
+ private:
+ // Contains pre-compiled regular expressions and related state. Factored out
+ // to avoid this header depending on RE2 headers.
+ struct ParsingState;
+
+ std::string compacted_source_;
+ std::vector<size_t> newline_indices_;
+ scoped_ptr<ParsingState> state_;
+
+ DISALLOW_COPY_AND_ASSIGN(JtlParser);
+};
+
+#endif // CHROME_TOOLS_PROFILE_RESET_JTL_PARSER_H_
« no previous file with comments | « chrome/tools/profile_reset/jtl_compiler_unittest.cc ('k') | chrome/tools/profile_reset/jtl_parser.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698