diff options
author | Brad King <brad.king@kitware.com> | 2015-07-02 17:12:44 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2019-04-18 12:21:44 (GMT) |
commit | d71880839246046cf0b1b662abf91687ea91f9b9 (patch) | |
tree | 5b88a492a01b92dd6aae8062918e56a2355ab4c5 /src/parser.h | |
parent | 215a190a57efddcd114658f8b24d57f58c217d88 (diff) | |
download | Ninja-d71880839246046cf0b1b662abf91687ea91f9b9.zip Ninja-d71880839246046cf0b1b662abf91687ea91f9b9.tar.gz Ninja-d71880839246046cf0b1b662abf91687ea91f9b9.tar.bz2 |
Factor out a base class of ManifestParser
Create a Parser base class that holds parser functionality not specific
to the build manifest file format. This will allow it to be re-used for
other parsers later.
Diffstat (limited to 'src/parser.h')
-rw-r--r-- | src/parser.h | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/src/parser.h b/src/parser.h new file mode 100644 index 0000000..e2d2b97 --- /dev/null +++ b/src/parser.h @@ -0,0 +1,50 @@ +// Copyright 2018 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#ifndef NINJA_PARSER_H_ +#define NINJA_PARSER_H_ + +#include <string> + +using namespace std; + +#include "lexer.h" + +struct FileReader; +struct State; + +/// Base class for parsers. +struct Parser { + Parser(State* state, FileReader* file_reader) + : state_(state), file_reader_(file_reader) {} + + /// Load and parse a file. + bool Load(const string& filename, string* err, Lexer* parent = NULL); + +protected: + /// If the next token is not \a expected, produce an error string + /// saying "expected foo, got bar". + bool ExpectToken(Lexer::Token expected, string* err); + + State* state_; + FileReader* file_reader_; + Lexer lexer_; + +private: + /// Parse a file, given its contents as a string. + virtual bool Parse(const string& filename, const string& input, + string* err) = 0; +}; + +#endif // NINJA_PARSER_H_ |