Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef CHROME_TOOLS_PROFILE_RESET_JTL_PARSER_H_ | |
| 6 #define CHROME_TOOLS_PROFILE_RESET_JTL_PARSER_H_ | |
| 7 | |
| 8 #include <string> | |
| 9 #include <vector> | |
| 10 | |
| 11 #include "base/basictypes.h" | |
| 12 #include "base/values.h" | |
| 13 | |
| 14 // Parses text-based JTL source code into a stream of operation names, arguments | |
| 15 // and separator kinds. | |
| 16 class JtlParser { | |
| 17 public: | |
| 18 explicit JtlParser(const std::string& compacted_source, | |
| 19 const std::vector<size_t>& newline_indices); | |
|
battre
2013/09/27 15:00:01
nit: no explicit needed.
engedy
2013/10/01 10:48:10
Done.
| |
| 20 ~JtlParser(); | |
| 21 | |
| 22 // Convenience method for compacting |source_code| first, and then creating a | |
| 23 // corresponding parser for it. | |
| 24 static JtlParser* Create(const std::string& source_code); | |
| 25 | |
| 26 // Removes comments from |verbose_text| and compacts it into whitespace-free | |
| 27 // format. For each newline character removed between the i-th and (i-1)-st | |
| 28 // retained character in |compacted_text|, |newline_indices| will contain the | |
| 29 // index 'i'. Elements in |newline_indices| will be monotonically increasing. | |
|
battre
2013/09/27 15:00:01
I don't understand this comment what goes into new
engedy
2013/10/01 10:48:10
Rephrased, please take another look.
| |
| 30 static void RemoveCommentsAndAllWhitespace( | |
| 31 const std::string& verbose_text, | |
| 32 std::string* compacted_text, | |
| 33 std::vector<size_t>* newline_indices); | |
| 34 | |
| 35 bool HasNextOperation(); | |
| 36 bool ParseNextOperation(std::string* name, | |
| 37 base::ListValue* args, | |
| 38 bool* ends_sentence); | |
|
battre
2013/09/27 15:00:01
Can you add a comment to this function? In particu
engedy
2013/10/01 10:48:10
Done.
| |
| 39 | |
| 40 // Returns on which line the retained character at position |compacted_index| | |
| 41 // was originally located. | |
| 42 size_t GetOriginalLineNumber(size_t compacted_index) const; | |
| 43 | |
| 44 const std::string& compacted_source() const { return compacted_source_; } | |
| 45 size_t last_line_number() const; | |
| 46 std::string last_context() const; | |
| 47 | |
| 48 private: | |
| 49 // Contains pre-compiled regular expressions and related state. Factored out | |
| 50 // to prevent this header from depending on RE2 headers. | |
| 51 struct ParsingState; | |
| 52 | |
| 53 std::string compacted_source_; | |
| 54 std::vector<size_t> newline_indices_; | |
| 55 scoped_ptr<ParsingState> state_; | |
| 56 | |
| 57 DISALLOW_COPY_AND_ASSIGN(JtlParser); | |
| 58 }; | |
| 59 | |
| 60 #endif // CHROME_TOOLS_PROFILE_RESET_JTL_PARSER_H_ | |
| OLD | NEW |