1 // Copyright 2011 Google Inc. All Rights Reserved.
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
7 // http://www.apache.org/licenses/LICENSE-2.0
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.
15 #ifndef NINJA_MANIFEST_PARSER_H_
16 #define NINJA_MANIFEST_PARSER_H_
33 /// Parses .ninja files.
34 struct ManifestParser {
36 virtual ~FileReader() {}
37 virtual bool ReadFile(const string& path, string* content, string* err) = 0;
40 ManifestParser(State* state, FileReader* file_reader,
41 DupeEdgeAction dupe_edge_action);
43 /// Load and parse a file.
44 bool Load(const string& filename, string* err, Lexer* parent = NULL);
46 /// Parse a text string of input. Used by tests.
47 bool ParseTest(const string& input, string* err) {
49 return Parse("input", input, err);
53 /// Parse a file, given its contents as a string.
54 bool Parse(const string& filename, const string& input, string* err);
56 /// Parse various statement types.
57 bool ParsePool(string* err);
58 bool ParseRule(string* err);
59 bool ParseLet(string* key, EvalString* val, string* err);
60 bool ParseEdge(string* err);
61 bool ParseDefault(string* err);
63 /// Parse either a 'subninja' or 'include' line.
64 bool ParseFileInclude(bool new_scope, string* err);
66 /// If the next token is not \a expected, produce an error string
67 /// saying "expectd foo, got bar".
68 bool ExpectToken(Lexer::Token expected, string* err);
72 FileReader* file_reader_;
74 DupeEdgeAction dupe_edge_action_;
78 #endif // NINJA_MANIFEST_PARSER_H_