Ninja
manifest_parser.h
Go to the documentation of this file.
1 // Copyright 2011 Google Inc. All Rights Reserved.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #ifndef NINJA_MANIFEST_PARSER_H_
16 #define NINJA_MANIFEST_PARSER_H_
17 
18 #include "parser.h"
19 
20 #include <memory>
21 #include <vector>
22 
23 struct BindingEnv;
24 struct EvalString;
25 
29 };
30 
34 };
35 
38 };
39 
40 /// Parses .ninja files.
41 struct ManifestParser : public Parser {
42  ManifestParser(State* state, FileReader* file_reader,
44 
45  /// Parse a text string of input. Used by tests.
46  bool ParseTest(const std::string& input, std::string* err) {
47  quiet_ = true;
48  return Parse("input", input, err);
49  }
50 
51 private:
52  /// Parse a file, given its contents as a string.
53  bool Parse(const std::string& filename, const std::string& input,
54  std::string* err);
55 
56  /// Parse various statement types.
57  bool ParsePool(std::string* err);
58  bool ParseRule(std::string* err);
59  bool ParseLet(std::string* key, EvalString* val, std::string* err);
60  bool ParseEdge(std::string* err);
61  bool ParseDefault(std::string* err);
62 
63  /// Parse either a 'subninja' or 'include' line.
64  bool ParseFileInclude(bool new_scope, std::string* err);
65 
68  bool quiet_;
69 
70  // ins_/out_/validations_ are reused across invocations to ParseEdge(),
71  // to save on the otherwise constant memory reallocation.
72  // subparser_ is reused solely to get better reuse out ins_/outs_/validation_.
73  std::unique_ptr<ManifestParser> subparser_;
74  std::vector<EvalString> ins_, outs_, validations_;
75 };
76 
77 #endif // NINJA_MANIFEST_PARSER_H_
DupeEdgeAction
@ kDupeEdgeActionError
@ kDupeEdgeActionWarn
PhonyCycleAction
@ kPhonyCycleActionWarn
@ kPhonyCycleActionError
An Env which contains a mapping of variables to values as well as a pointer to a parent scope.
Definition: eval_env.h:93
A tokenized string that contains variable references.
Definition: eval_env.h:35
Interface for reading files from disk.
PhonyCycleAction phony_cycle_action_
Parses .ninja files.
BindingEnv * env_
bool ParseEdge(std::string *err)
std::unique_ptr< ManifestParser > subparser_
bool ParseRule(std::string *err)
bool Parse(const std::string &filename, const std::string &input, std::string *err)
Parse a file, given its contents as a string.
bool ParseTest(const std::string &input, std::string *err)
Parse a text string of input. Used by tests.
ManifestParserOptions options_
std::vector< EvalString > outs_
std::vector< EvalString > ins_
bool ParseDefault(std::string *err)
bool ParsePool(std::string *err)
Parse various statement types.
std::vector< EvalString > validations_
ManifestParser(State *state, FileReader *file_reader, ManifestParserOptions options=ManifestParserOptions())
bool ParseFileInclude(bool new_scope, std::string *err)
Parse either a 'subninja' or 'include' line.
bool ParseLet(std::string *key, EvalString *val, std::string *err)
Base class for parsers.
Definition: parser.h:26
Global state (file status) for a single run.
Definition: state.h:95