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 // Creates a new parser to parse |compacted_source_code|, which should already | |
19 // be stripped of all comments and whitespace (except inside string literals). | |
20 // Use RemoveCommentsAndAllWhitespace() to manufacture these arguments, also | |
21 // see its comments for a description of |newline_indices|. | |
22 JtlParser(const std::string& compacted_source_code, | |
23 const std::vector<size_t>& newline_indices); | |
24 ~JtlParser(); | |
25 | |
26 // Removes comments from |verbose_text| and compacts it into whitespace-free | |
27 // format. Elements in |newline_indices| will be monotonically increasing, | |
28 // and will refer to positions in |compacted_text| such that a new line has | |
battre
2013/10/01 12:18:26
such that |newline_indices[i]| indicates the numbe
engedy
2013/10/01 15:09:33
Added example to clarify.
| |
29 // been removed before that position. | |
30 // Returns true on success, false if there were unmatched quotes in a line, in | |
31 // which case |error_line_number| will be set accordingly if it is non-NULL. | |
32 static bool RemoveCommentsAndAllWhitespace( | |
33 const std::string& verbose_text, | |
34 std::string* compacted_text, | |
35 std::vector<size_t>* newline_indices, | |
36 size_t* error_line_number); | |
37 | |
38 // Returns true if the entire input has been successfully consumed. Note that | |
39 // even when this returns false, a subsequent call to ParseNextOperation() | |
40 // might still fail if the next operation cannot be parsed. | |
41 bool HasFinished(); | |
42 | |
43 // Fetches the |name| and the |argument_list| of the next operation, and also | |
44 // whether or not it |ends_the_sentence|, i.e. it is followed by the | |
45 // end-of-sentence separator. | |
46 // Returns false if there is a parsing error, in which case the values for the | |
47 // output parameters are undefined, and |this| parser shall no longer be used. | |
48 bool ParseNextOperation(std::string* name, | |
49 base::ListValue* argument_list, | |
50 bool* ends_the_sentence); | |
51 | |
52 // Returns the compacted source code that was passed in to the constructor. | |
53 const std::string& compacted_source() const { return compacted_source_; } | |
54 | |
55 // Returns at which line the character at position |compacted_index| in the | |
56 // |compacted_source()| was originally located. | |
57 size_t GetOriginalLineNumber(size_t compacted_index) const; | |
58 | |
59 size_t last_line_number() const; | |
battre
2013/10/01 12:18:26
If this is hacker_style it should be inlined. If t
engedy
2013/10/01 15:09:33
Changed to CamelCase, as this cannot be inlined du
| |
60 std::string last_context() const; | |
61 | |
62 private: | |
63 // Contains pre-compiled regular expressions and related state. Factored out | |
64 // to avoid this header depending on RE2 headers. | |
65 struct ParsingState; | |
66 | |
67 std::string compacted_source_; | |
68 std::vector<size_t> newline_indices_; | |
69 scoped_ptr<ParsingState> state_; | |
70 | |
71 DISALLOW_COPY_AND_ASSIGN(JtlParser); | |
72 }; | |
73 | |
74 #endif // CHROME_TOOLS_PROFILE_RESET_JTL_PARSER_H_ | |
OLD | NEW |