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.
5 #ifndef CHROME_TOOLS_PROFILE_RESET_JTL_COMPILER_H_
6 #define CHROME_TOOLS_PROFILE_RESET_JTL_COMPILER_H_
10 #include "base/basictypes.h"
12 // Compiles text-based JTL source code into JTL byte-code.
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".
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 periods (.).
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".
25 // Whitespace does not matter, except for inside string literals. C++-style,
26 // double-slash-introduced comments are also supported.
28 // Example source code:
30 // // Store "x"=true if path "foo.bar" is found.
31 // go("foo").go("bar").store_bool("x", true);
33 // // Store "y"="1" if the above value is set.
34 // compare_stored_bool("x", true, false).store_hash("y", "1");
41 MISMATCHED_DOUBLE_QUOTES
,
43 INVALID_OPERATION_NAME
,
44 INVALID_ARGUMENT_COUNT
,
45 INVALID_ARGUMENT_TYPE
,
46 INVALID_ARGUMENT_VALUE
49 CompileError() : line_number(0), error_code(ERROR_NONE
) {}
50 CompileError(size_t line_number
,
51 const std::string
& context
,
53 : line_number(line_number
), context(context
), error_code(error_code
) {}
55 size_t line_number
; // 0-based.
60 // Compiles text-based JTL source code contained in |source_code| into JTL
61 // byte-code to |output_bytecode|. Variable, node names, and string literals
62 // will be hashed using the seed in |hash_seed|.
63 // On success, returns true. Otherwise, returns false and fills |error| with
64 // more information (if it is non-NULL).
65 static bool Compile(const std::string
& source_code
,
66 const std::string
& hash_seed
,
67 std::string
* output_bytecode
,
71 DISALLOW_IMPLICIT_CONSTRUCTORS(JtlCompiler
);
74 #endif // CHROME_TOOLS_PROFILE_RESET_JTL_COMPILER_H_