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_COMPILER_H_ | |
6 #define CHROME_TOOLS_PROFILE_RESET_JTL_COMPILER_H_ | |
7 | |
8 #include <string> | |
9 | |
10 #include "base/basictypes.h" | |
11 | |
12 // Compiles text-based JTL source code into JTL byte-code. | |
13 // | |
14 // For an overview of JTL (JSON Traversal Language), and the exhaustive list of | |
15 // instructions, please see "chrome/browser/profile_resetter/jtl_foundation.h". | |
16 // | |
17 // The text-based JTL syntax itself much resembles C/C++. A program consists of | |
18 // zero or more sentences. Each sentence is terminated by a semi-colon (;), and | |
19 // is composed of *one* or more operations, separated by forward slashes (/). | |
20 // | |
21 // Each operation resembles a C/C++ function call and consists of an instruction | |
22 // name, and an optional argument list, which takes Boolean values and/or string | |
23 // literals. The text-based instruction names are defined in "jtl_compiler.cc". | |
24 // | |
25 // Whitespace does not matter, except for inside string literals. C++-style, | |
26 // double-slash-introduced comments are also supported. | |
27 // | |
28 // Example source code: | |
29 // | |
30 // // Store "x"=true path "foo.bar" is found. | |
battre
2013/10/01 12:18:26
nit: "if path..."
engedy
2013/10/01 15:09:33
Done.
| |
31 // node("foo")/node("bar")/store_bool("x", true); | |
32 // | |
33 // // Store "y"="1" if the above value is set. | |
34 // compare_stored_bool("x", true, false)/store_hash("y", "1"); | |
35 // | |
36 class JtlCompiler { | |
37 public: | |
38 struct CompileError { | |
39 enum ErrorCode { | |
40 NO_ERROR, | |
41 MISMATCHED_DOUBLE_QUOTES, | |
42 PARSING_ERROR, | |
43 INVALID_OPERATION_NAME, | |
44 INVALID_ARGUMENT_COUNT, | |
45 INVALID_ARGUMENT_TYPE, | |
46 }; | |
47 | |
48 CompileError() : line_number(0), error_code(NO_ERROR) {} | |
49 CompileError(size_t line_number, | |
50 const std::string& context, | |
51 ErrorCode error_code) | |
52 : line_number(line_number), context(context), error_code(error_code) {} | |
53 | |
54 size_t line_number; // 0-based. | |
55 std::string context; | |
56 ErrorCode error_code; | |
57 }; | |
58 | |
59 // Compiles text-based JTL source code contained in |source_code| into JTL | |
60 // byte-code to |output_bytecode|. Variable, node names, and string literals | |
61 // will be hashed using the seed in |hash_seed|. | |
62 // On success, returns true. Otherwise, returns false and fills |error| with | |
63 // more information (if it is non-NULL). | |
64 static bool Compile(const std::string& source_code, | |
65 const std::string& hash_seed, | |
66 std::string* output_bytecode, | |
67 CompileError* error); | |
68 | |
69 private: | |
70 DISALLOW_IMPLICIT_CONSTRUCTORS(JtlCompiler); | |
71 }; | |
72 | |
73 #endif // CHROME_TOOLS_PROFILE_RESET_JTL_COMPILER_H_ | |
OLD | NEW |