| 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 lexer converts the character stream into a token stream. |
| 9 |
// The output of the lexer goes to the input of the parser. |
| 10 |
// |
| 11 |
// The "getNextToken()" will return "END" after the last non-end token and |
| 12 |
// it can be called more than one time after "END", it will return with "END". |
| 13 |
|
| 14 |
#pragma once |
| 15 |
|
| 16 |
#include "Token.hpp" |
| 17 |
#include "VerifyMacros.hpp" |
| 18 |
|
| 19 |
#include <boost/filesystem.hpp> |
| 20 |
|
| 21 |
namespace yade { |
| 22 |
namespace ymport { |
| 23 |
namespace foamfile { |
| 24 |
|
| 25 |
class Lexer { |
| 26 |
public: |
| 27 |
Lexer(const boost::filesystem::path& path); |
| 28 |
~Lexer(); |
| 29 |
|
| 30 |
Token getNextToken(); |
| 31 |
|
| 32 |
const boost::filesystem::path& path() const { return m_path; } |
| 33 |
std::uint32_t lineNumber() const { return m_lineNumber; } |
| 34 |
|
| 35 |
private: |
| 36 |
void readFullFile(); |
| 37 |
|
| 38 |
void removeSingleLineComments(); |
| 39 |
void removeMultiLineComments(); |
| 40 |
|
| 41 |
void consumeWhiteSpaces(); |
| 42 |
|
| 43 |
bool isWhiteSpace(char c); |
| 44 |
|
| 45 |
void error(const char* fmt, ...); |
| 46 |
|
| 47 |
std::uint32_t m_currentCharIndex { 0 }; |
| 48 |
std::uint32_t m_lineNumber { 1 }; |
| 49 |
boost::filesystem::path m_path; |
| 50 |
std::string m_data; |
| 51 |
const char* m_oldLocale; |
| 52 |
}; |
| 53 |
|
| 54 |
} // namespace foamfile |
| 55 |
} // namespace ymport |
| 56 |
} // namespace yade |