2010-06-27 17:20:21 +00:00
|
|
|
#ifndef COMPILER_FILEPARSER_H_INCLUDED
|
|
|
|
#define COMPILER_FILEPARSER_H_INCLUDED
|
|
|
|
|
2010-06-28 11:28:50 +00:00
|
|
|
#include "locals.hpp"
|
2010-06-27 17:20:21 +00:00
|
|
|
#include "parser.hpp"
|
2010-06-28 09:38:04 +00:00
|
|
|
#include "scriptparser.hpp"
|
2010-06-27 17:20:21 +00:00
|
|
|
|
|
|
|
namespace Compiler
|
|
|
|
{
|
2010-06-27 22:50:48 +00:00
|
|
|
// Top-level parser, to be used for global scripts, local scripts and targeted scripts
|
2022-09-22 18:26:05 +00:00
|
|
|
|
2010-06-27 17:20:21 +00:00
|
|
|
class FileParser : public Parser
|
|
|
|
{
|
2010-06-27 22:50:48 +00:00
|
|
|
enum State
|
|
|
|
{
|
2010-06-28 09:38:04 +00:00
|
|
|
BeginState,
|
|
|
|
NameState,
|
|
|
|
BeginCompleteState,
|
|
|
|
EndNameState,
|
2010-06-27 22:50:48 +00:00
|
|
|
EndCompleteState
|
|
|
|
};
|
2022-09-22 18:26:05 +00:00
|
|
|
|
2010-06-28 09:38:04 +00:00
|
|
|
ScriptParser mScriptParser;
|
2010-06-27 22:50:48 +00:00
|
|
|
State mState;
|
|
|
|
std::string mName;
|
2010-06-28 11:28:50 +00:00
|
|
|
Locals mLocals;
|
2022-09-22 18:26:05 +00:00
|
|
|
|
2010-06-27 17:20:21 +00:00
|
|
|
public:
|
|
|
|
FileParser(ErrorHandler& errorHandler, Context& context);
|
2022-09-22 18:26:05 +00:00
|
|
|
|
2010-06-27 22:50:48 +00:00
|
|
|
std::string getName() const;
|
|
|
|
///< Return script name.
|
2022-09-22 18:26:05 +00:00
|
|
|
|
2023-01-10 03:10:18 +00:00
|
|
|
Interpreter::Program getProgram() const;
|
2022-09-22 18:26:05 +00:00
|
|
|
|
2010-06-28 12:17:50 +00:00
|
|
|
const Locals& getLocals() const;
|
|
|
|
///< get local variable declarations.
|
2022-09-22 18:26:05 +00:00
|
|
|
|
2020-10-16 18:18:54 +00:00
|
|
|
bool parseName(const std::string& name, const TokenLoc& loc, Scanner& scanner) override;
|
2010-06-27 17:20:21 +00:00
|
|
|
///< Handle a name token.
|
|
|
|
/// \return fetch another token?
|
2022-09-22 18:26:05 +00:00
|
|
|
|
2020-10-16 18:18:54 +00:00
|
|
|
bool parseKeyword(int keyword, const TokenLoc& loc, Scanner& scanner) override;
|
2010-06-27 17:20:21 +00:00
|
|
|
///< Handle a keyword token.
|
|
|
|
/// \return fetch another token?
|
2022-09-22 18:26:05 +00:00
|
|
|
|
2020-10-16 18:18:54 +00:00
|
|
|
bool parseSpecial(int code, const TokenLoc& loc, Scanner& scanner) override;
|
2010-06-27 17:20:21 +00:00
|
|
|
///< Handle a special character token.
|
|
|
|
/// \return fetch another token?
|
2022-09-22 18:26:05 +00:00
|
|
|
|
2020-10-16 18:18:54 +00:00
|
|
|
void parseEOF(Scanner& scanner) override;
|
2010-06-27 17:20:21 +00:00
|
|
|
///< Handle EOF token.
|
2022-09-22 18:26:05 +00:00
|
|
|
|
2020-10-16 18:18:54 +00:00
|
|
|
void reset() override;
|
2010-06-27 22:50:48 +00:00
|
|
|
///< Reset parser to clean state.
|
2010-06-27 17:20:21 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|