2010-07-01 14:40:03 +00:00
|
|
|
#ifndef COMPILER_STRINGPARSER_H_INCLUDED
|
|
|
|
#define COMPILER_STRINGPARSER_H_INCLUDED
|
|
|
|
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
#include <components/interpreter/types.hpp>
|
|
|
|
|
|
|
|
#include "parser.hpp"
|
2016-01-07 14:54:22 +00:00
|
|
|
#include "tokenloc.hpp"
|
2010-07-01 14:40:03 +00:00
|
|
|
|
|
|
|
namespace Compiler
|
|
|
|
{
|
|
|
|
class Literals;
|
2014-02-14 11:23:00 +00:00
|
|
|
|
2010-07-01 14:40:03 +00:00
|
|
|
class StringParser : public Parser
|
|
|
|
{
|
2022-09-22 18:26:05 +00:00
|
|
|
Literals& mLiterals;
|
|
|
|
std::vector<Interpreter::Type_Code> mCode;
|
|
|
|
bool mSmashCase;
|
|
|
|
TokenLoc mTokenLoc;
|
|
|
|
bool mDiscard;
|
2014-02-14 11:23:00 +00:00
|
|
|
|
2022-09-22 18:26:05 +00:00
|
|
|
public:
|
|
|
|
StringParser(ErrorHandler& errorHandler, const Context& context, Literals& literals);
|
2014-02-14 11:23:00 +00:00
|
|
|
|
2022-09-22 18:26:05 +00:00
|
|
|
bool parseName(const std::string& name, const TokenLoc& loc, Scanner& scanner) override;
|
|
|
|
///< Handle a name token.
|
|
|
|
/// \return fetch another token?
|
2010-07-01 14:40:03 +00:00
|
|
|
|
2022-09-22 18:26:05 +00:00
|
|
|
bool parseKeyword(int keyword, const TokenLoc& loc, Scanner& scanner) override;
|
|
|
|
///< Handle a keyword token.
|
|
|
|
/// \return fetch another token?
|
2010-07-01 14:40:03 +00:00
|
|
|
|
2022-09-22 18:26:05 +00:00
|
|
|
bool parseInt(int value, const TokenLoc& loc, Scanner& scanner) override;
|
|
|
|
///< Handle an int token.
|
|
|
|
/// \return fetch another token?
|
2015-08-05 15:20:01 +00:00
|
|
|
|
2022-09-22 18:26:05 +00:00
|
|
|
void append(std::vector<Interpreter::Type_Code>& code);
|
|
|
|
///< Append code for parsed string.
|
2021-10-21 14:54:32 +00:00
|
|
|
|
2022-09-22 18:26:05 +00:00
|
|
|
void smashCase();
|
|
|
|
///< Transform all scanned strings to lower case
|
2014-02-14 11:23:00 +00:00
|
|
|
|
2022-09-22 18:26:05 +00:00
|
|
|
void reset() override;
|
|
|
|
///< Reset parser to clean state (this includes the smashCase function).
|
2014-02-14 11:23:00 +00:00
|
|
|
|
2022-09-22 18:26:05 +00:00
|
|
|
/// Returns TokenLoc object for string. If no string has been parsed, the TokenLoc
|
|
|
|
/// object will be default initialised.
|
|
|
|
const TokenLoc& getTokenLoc() const;
|
2016-01-07 14:54:22 +00:00
|
|
|
|
2022-09-22 18:26:05 +00:00
|
|
|
/// If parsing a string, do not add it to the literal table and do not create code
|
|
|
|
/// for it.
|
|
|
|
void discard();
|
2010-07-01 14:40:03 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|