• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 struct BindingEnv;
21 struct EvalString;
22 
23 enum DupeEdgeAction {
24   kDupeEdgeActionWarn,
25   kDupeEdgeActionError,
26 };
27 
28 enum PhonyCycleAction {
29   kPhonyCycleActionWarn,
30   kPhonyCycleActionError,
31 };
32 
33 struct ManifestParserOptions {
ManifestParserOptionsManifestParserOptions34   ManifestParserOptions()
35       : dupe_edge_action_(kDupeEdgeActionWarn),
36         phony_cycle_action_(kPhonyCycleActionWarn) {}
37   DupeEdgeAction dupe_edge_action_;
38   PhonyCycleAction phony_cycle_action_;
39 };
40 
41 /// Parses .ninja files.
42 struct ManifestParser : public Parser {
43   ManifestParser(State* state, FileReader* file_reader,
44                  ManifestParserOptions options = ManifestParserOptions());
45 
46   /// Parse a text string of input.  Used by tests.
ParseTestManifestParser47   bool ParseTest(const std::string& input, std::string* err) {
48     quiet_ = true;
49     return Parse("input", input, err);
50   }
51 
52 private:
53   /// Parse a file, given its contents as a string.
54   bool Parse(const std::string& filename, const std::string& input,
55              std::string* err);
56 
57   /// Parse various statement types.
58   bool ParsePool(std::string* err);
59   bool ParseRule(std::string* err);
60   bool ParseLet(std::string* key, EvalString* val, std::string* err);
61   bool ParseEdge(std::string* err);
62   bool ParseDefault(std::string* err);
63 
64   /// Parse either a 'subninja' or 'include' line.
65   bool ParseFileInclude(bool new_scope, std::string* err);
66 
67   BindingEnv* env_;
68   ManifestParserOptions options_;
69   bool quiet_;
70 };
71 
72 #endif  // NINJA_MANIFEST_PARSER_H_
73