| 1 |
/************************************************************************* |
| 2 |
* 2022 Tóth János * |
| 3 |
* * |
| 4 |
* This program is free software; it is licensed under the terms of the * |
| 5 |
* GNU General Public License v2 or later. See file LICENSE for details. * |
| 6 |
*************************************************************************/ |
| 7 |
|
| 8 |
// The parser interprets the syntax of the file and parses the values of the tokens. |
| 9 |
// This is the base class and implements all the common functions. |
| 10 |
|
| 11 |
#pragma once |
| 12 |
|
| 13 |
#include "Lexer.hpp" |
| 14 |
#include "Token.hpp" |
| 15 |
|
| 16 |
#include <memory> |
| 17 |
#include <string> |
| 18 |
|
| 19 |
namespace yade { |
| 20 |
namespace ymport { |
| 21 |
namespace foamfile { |
| 22 |
|
| 23 |
class Parser { |
| 24 |
public: |
| 25 |
Parser(const boost::filesystem::path& path, const std::string& klass, const std::string& object); |
| 26 |
virtual ~Parser() {}; |
| 27 |
|
| 28 |
virtual void parse() = 0; |
| 29 |
|
| 30 |
protected: |
| 31 |
void expect(Token token); |
| 32 |
|
| 33 |
void skip(int n); |
| 34 |
void skipUntil(Token token); |
| 35 |
|
| 36 |
std::string getWord(); |
| 37 |
int getInt(); |
| 38 |
double getDouble(); |
| 39 |
double getNumber(); |
| 40 |
|
| 41 |
void parseHeader(); |
| 42 |
|
| 43 |
void error(const char* fmt, ...); |
| 44 |
|
| 45 |
std::unique_ptr<Lexer> m_lexer { nullptr }; |
| 46 |
std::string m_klass; |
| 47 |
std::string m_object; |
| 48 |
}; |
| 49 |
|
| 50 |
} // namespace foamfile |
| 51 |
} // namespace ymport |
| 52 |
} // namespace yade |