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 <string>
19 
20 using namespace std;
21 
22 #include "lexer.h"
23 
24 struct BindingEnv;
25 struct EvalString;
26 struct FileReader;
27 struct State;
28 
32 };
33 
37 };
38 
41  : dupe_edge_action_(kDupeEdgeActionWarn),
42  phony_cycle_action_(kPhonyCycleActionWarn) {}
45 };
46 
47 /// Parses .ninja files.
49  ManifestParser(State* state, FileReader* file_reader,
51 
52  /// Load and parse a file.
53  bool Load(const string& filename, string* err, Lexer* parent = NULL);
54 
55  /// Parse a text string of input. Used by tests.
56  bool ParseTest(const string& input, string* err) {
57  quiet_ = true;
58  return Parse("input", input, err);
59  }
60 
61 private:
62  /// Parse a file, given its contents as a string.
63  bool Parse(const string& filename, const string& input, string* err);
64 
65  /// Parse various statement types.
66  bool ParsePool(string* err);
67  bool ParseRule(string* err);
68  bool ParseLet(string* key, EvalString* val, string* err);
69  bool ParseEdge(string* err);
70  bool ParseDefault(string* err);
71 
72  /// Parse either a 'subninja' or 'include' line.
73  bool ParseFileInclude(bool new_scope, string* err);
74 
75  /// If the next token is not \a expected, produce an error string
76  /// saying "expectd foo, got bar".
77  bool ExpectToken(Lexer::Token expected, string* err);
78 
84  bool quiet_;
85 };
86 
87 #endif // NINJA_MANIFEST_PARSER_H_
Definition: lexer.h:27
BindingEnv * env_
DupeEdgeAction
PhonyCycleAction phony_cycle_action_
Parses .ninja files.
An Env which contains a mapping of variables to values as well as a pointer to a parent scope...
Definition: eval_env.h:77
PhonyCycleAction
Token
Definition: lexer.h:32
ManifestParserOptions options_
Global state (file status) for a single run.
Definition: state.h:85
FileReader * file_reader_
A tokenized string that contains variable references.
Definition: eval_env.h:35
DupeEdgeAction dupe_edge_action_
bool ParseTest(const string &input, string *err)
Parse a text string of input. Used by tests.
Interface for reading files from disk.