2010-06-28 10:12:47 +00:00
|
|
|
#ifndef COMPILER_LINEPARSER_H_INCLUDED
|
|
|
|
#define COMPILER_LINEPARSER_H_INCLUDED
|
|
|
|
|
2010-06-28 12:07:55 +00:00
|
|
|
#include <vector>
|
2016-07-09 01:18:45 +00:00
|
|
|
#include <string>
|
2010-06-28 12:07:55 +00:00
|
|
|
|
|
|
|
#include <components/interpreter/types.hpp>
|
2016-07-09 01:18:45 +00:00
|
|
|
#include <components/misc/messageformatparser.hpp>
|
2010-06-28 12:07:55 +00:00
|
|
|
|
2010-06-28 10:12:47 +00:00
|
|
|
#include "parser.hpp"
|
2010-06-29 08:22:55 +00:00
|
|
|
#include "exprparser.hpp"
|
2010-06-28 10:12:47 +00:00
|
|
|
|
|
|
|
namespace Compiler
|
|
|
|
{
|
2010-06-28 11:28:50 +00:00
|
|
|
class Locals;
|
2010-06-28 14:48:19 +00:00
|
|
|
class Literals;
|
2010-08-22 09:14:14 +00:00
|
|
|
|
2010-06-28 10:12:47 +00:00
|
|
|
/// \brief Line parser, to be used in console scripts and as part of ScriptParser
|
2010-08-22 09:14:14 +00:00
|
|
|
|
2010-06-28 10:12:47 +00:00
|
|
|
class LineParser : public Parser
|
|
|
|
{
|
2010-06-28 10:32:08 +00:00
|
|
|
enum State
|
|
|
|
{
|
|
|
|
BeginState,
|
2012-06-16 12:29:55 +00:00
|
|
|
SetState, SetLocalVarState, SetGlobalVarState, SetPotentialMemberVarState,
|
|
|
|
SetMemberVarState, SetMemberVarState2,
|
2021-11-13 13:06:21 +00:00
|
|
|
MessageState, MessageButtonState,
|
2020-06-06 17:04:09 +00:00
|
|
|
EndState, PotentialExplicitState, ExplicitState, MemberState
|
2010-06-28 10:32:08 +00:00
|
|
|
};
|
2010-06-28 11:28:50 +00:00
|
|
|
|
2010-08-22 09:14:14 +00:00
|
|
|
Locals& mLocals;
|
2010-06-28 14:48:19 +00:00
|
|
|
Literals& mLiterals;
|
2010-06-28 12:07:55 +00:00
|
|
|
std::vector<Interpreter::Type_Code>& mCode;
|
2010-06-28 10:32:08 +00:00
|
|
|
State mState;
|
2010-06-28 16:27:45 +00:00
|
|
|
std::string mName;
|
2012-06-16 12:29:55 +00:00
|
|
|
std::string mMemberName;
|
2014-02-10 13:45:55 +00:00
|
|
|
bool mReferenceMember;
|
2010-08-22 09:14:14 +00:00
|
|
|
int mButtons;
|
2010-07-09 17:32:17 +00:00
|
|
|
std::string mExplicit;
|
2010-07-04 10:29:28 +00:00
|
|
|
char mType;
|
2010-06-29 08:22:55 +00:00
|
|
|
ExprParser mExprParser;
|
2010-07-21 11:34:52 +00:00
|
|
|
bool mAllowExpression;
|
2010-08-22 09:14:14 +00:00
|
|
|
|
2010-07-21 11:34:52 +00:00
|
|
|
void parseExpression (Scanner& scanner, const TokenLoc& loc);
|
2010-08-22 09:14:14 +00:00
|
|
|
|
2010-06-28 10:12:47 +00:00
|
|
|
public:
|
2010-08-22 09:14:14 +00:00
|
|
|
|
2014-02-14 11:23:00 +00:00
|
|
|
LineParser (ErrorHandler& errorHandler, const Context& context, Locals& locals,
|
2010-07-21 11:34:52 +00:00
|
|
|
Literals& literals, std::vector<Interpreter::Type_Code>& code,
|
|
|
|
bool allowExpression = false);
|
|
|
|
///< \param allowExpression Allow lines consisting of a naked expression
|
|
|
|
/// (result is send to the messagebox interface)
|
2010-08-22 09:14:14 +00:00
|
|
|
|
2020-10-16 18:18:54 +00:00
|
|
|
bool parseInt (int value, const TokenLoc& loc, Scanner& scanner) override;
|
2010-06-28 10:12:47 +00:00
|
|
|
///< Handle an int token.
|
|
|
|
/// \return fetch another token?
|
|
|
|
|
2020-10-16 18:18:54 +00:00
|
|
|
bool parseFloat (float value, const TokenLoc& loc, Scanner& scanner) override;
|
2010-06-28 10:12:47 +00:00
|
|
|
///< Handle a float token.
|
|
|
|
/// \return fetch another token?
|
|
|
|
|
2020-10-16 18:18:54 +00:00
|
|
|
bool parseName (const std::string& name, const TokenLoc& loc,
|
|
|
|
Scanner& scanner) override;
|
2010-06-28 10:12:47 +00:00
|
|
|
///< Handle a name token.
|
|
|
|
/// \return fetch another token?
|
|
|
|
|
2020-10-16 18:18:54 +00:00
|
|
|
bool parseKeyword (int keyword, const TokenLoc& loc, Scanner& scanner) override;
|
2010-06-28 10:12:47 +00:00
|
|
|
///< Handle a keyword token.
|
|
|
|
/// \return fetch another token?
|
|
|
|
|
2020-10-16 18:18:54 +00:00
|
|
|
bool parseSpecial (int code, const TokenLoc& loc, Scanner& scanner) override;
|
2010-06-28 10:12:47 +00:00
|
|
|
///< Handle a special character token.
|
|
|
|
/// \return fetch another token?
|
2010-08-22 09:14:14 +00:00
|
|
|
|
2020-10-16 18:18:54 +00:00
|
|
|
void reset() override;
|
2010-08-22 09:14:14 +00:00
|
|
|
///< Reset parser to clean state.
|
2010-06-28 10:12:47 +00:00
|
|
|
};
|
2016-07-09 01:18:45 +00:00
|
|
|
|
|
|
|
class GetArgumentsFromMessageFormat : public ::Misc::MessageFormatParser
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
std::string mArguments;
|
|
|
|
|
|
|
|
protected:
|
2020-10-16 18:18:54 +00:00
|
|
|
void visitedPlaceholder(Placeholder placeholder, char padding, int width, int precision, Notation notation) override;
|
|
|
|
void visitedCharacter(char c) override {}
|
2016-07-09 01:18:45 +00:00
|
|
|
|
|
|
|
public:
|
2022-05-20 23:21:55 +00:00
|
|
|
void process(std::string_view message) override
|
2016-07-09 01:18:45 +00:00
|
|
|
{
|
|
|
|
mArguments.clear();
|
|
|
|
::Misc::MessageFormatParser::process(message);
|
|
|
|
}
|
|
|
|
std::string getArguments() const { return mArguments; }
|
|
|
|
};
|
2010-06-28 10:12:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|