Ninja
|
00001 // Copyright 2011 Google Inc. All Rights Reserved. 00002 // 00003 // Licensed under the Apache License, Version 2.0 (the "License"); 00004 // you may not use this file except in compliance with the License. 00005 // You may obtain a copy of the License at 00006 // 00007 // http://www.apache.org/licenses/LICENSE-2.0 00008 // 00009 // Unless required by applicable law or agreed to in writing, software 00010 // distributed under the License is distributed on an "AS IS" BASIS, 00011 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00012 // See the License for the specific language governing permissions and 00013 // limitations under the License. 00014 00015 #ifndef NINJA_MANIFEST_PARSER_H_ 00016 #define NINJA_MANIFEST_PARSER_H_ 00017 00018 #include <string> 00019 00020 using namespace std; 00021 00022 #include "lexer.h" 00023 00024 struct BindingEnv; 00025 struct EvalString; 00026 struct State; 00027 00028 /// Parses .ninja files. 00029 struct ManifestParser { 00030 struct FileReader { 00031 virtual ~FileReader() {} 00032 virtual bool ReadFile(const string& path, string* content, string* err) = 0; 00033 }; 00034 00035 ManifestParser(State* state, FileReader* file_reader); 00036 00037 /// Load and parse a file. 00038 bool Load(const string& filename, string* err); 00039 00040 /// Parse a text string of input. Used by tests. 00041 bool ParseTest(const string& input, string* err) { 00042 return Parse("input", input, err); 00043 } 00044 00045 private: 00046 /// Parse a file, given its contents as a string. 00047 bool Parse(const string& filename, const string& input, string* err); 00048 00049 /// Parse various statement types. 00050 bool ParsePool(string* err); 00051 bool ParseRule(string* err); 00052 bool ParseLet(string* key, EvalString* val, string* err); 00053 bool ParseEdge(string* err); 00054 bool ParseDefault(string* err); 00055 00056 /// Parse either a 'subninja' or 'include' line. 00057 bool ParseFileInclude(bool new_scope, string* err); 00058 00059 /// If the next token is not \a expected, produce an error string 00060 /// saying "expectd foo, got bar". 00061 bool ExpectToken(Lexer::Token expected, string* err); 00062 00063 State* state_; 00064 BindingEnv* env_; 00065 FileReader* file_reader_; 00066 Lexer lexer_; 00067 }; 00068 00069 #endif // NINJA_MANIFEST_PARSER_H_