1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
|
#ifndef COMPILER_STRINGPARSER_H_INCLUDED
#define COMPILER_STRINGPARSER_H_INCLUDED
#include <vector>
#include <components/interpreter/types.hpp>
#include "parser.hpp"
#include "tokenloc.hpp"
namespace Compiler
{
class Literals;
class StringParser : public Parser
{
Literals& mLiterals;
std::vector<Interpreter::Type_Code> mCode;
bool mSmashCase;
TokenLoc mTokenLoc;
bool mDiscard;
public:
StringParser(ErrorHandler& errorHandler, const Context& context, Literals& literals);
bool parseName(const std::string& name, const TokenLoc& loc, Scanner& scanner) override;
///< Handle a name token.
/// \return fetch another token?
bool parseKeyword(int keyword, const TokenLoc& loc, Scanner& scanner) override;
///< Handle a keyword token.
/// \return fetch another token?
bool parseInt(int value, const TokenLoc& loc, Scanner& scanner) override;
///< Handle an int token.
/// \return fetch another token?
void append(std::vector<Interpreter::Type_Code>& code);
///< Append code for parsed string.
void smashCase();
///< Transform all scanned strings to lower case
void reset() override;
///< Reset parser to clean state (this includes the smashCase function).
/// Returns TokenLoc object for string. If no string has been parsed, the TokenLoc
/// object will be default initialised.
const TokenLoc& getTokenLoc() const;
/// If parsing a string, do not add it to the literal table and do not create code
/// for it.
void discard();
};
}
#endif
|