1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-01 03:21:41 +00:00
OpenMW/components/compiler/discardparser.cpp

83 lines
1.8 KiB
C++
Raw Normal View History

#include "discardparser.hpp"
#include "scanner.hpp"
namespace Compiler
{
2022-09-22 18:26:05 +00:00
DiscardParser::DiscardParser(ErrorHandler& errorHandler, const Context& context)
: Parser(errorHandler, context)
, mState(StartState)
{
}
2022-09-22 18:26:05 +00:00
bool DiscardParser::parseInt(int value, const TokenLoc& loc, Scanner& scanner)
{
2022-09-22 18:26:05 +00:00
if (mState == StartState || mState == MinusState)
{
if (isEmpty())
mTokenLoc = loc;
start();
return false;
}
2022-09-22 18:26:05 +00:00
return Parser::parseInt(value, loc, scanner);
}
2022-09-22 18:26:05 +00:00
bool DiscardParser::parseFloat(float value, const TokenLoc& loc, Scanner& scanner)
{
2022-09-22 18:26:05 +00:00
if (mState == StartState || mState == MinusState)
{
if (isEmpty())
mTokenLoc = loc;
start();
return false;
}
2022-09-22 18:26:05 +00:00
return Parser::parseFloat(value, loc, scanner);
}
2022-09-22 18:26:05 +00:00
bool DiscardParser::parseName(const std::string& name, const TokenLoc& loc, Scanner& scanner)
{
2022-09-22 18:26:05 +00:00
if (mState == StartState)
{
if (isEmpty())
mTokenLoc = loc;
start();
return false;
}
2022-09-22 18:26:05 +00:00
return Parser::parseName(name, loc, scanner);
}
2022-09-22 18:26:05 +00:00
bool DiscardParser::parseSpecial(int code, const TokenLoc& loc, Scanner& scanner)
{
2022-09-22 18:26:05 +00:00
if (code == Scanner::S_minus && mState == StartState)
{
if (isEmpty())
mTokenLoc = loc;
start();
mState = MinusState;
return true;
}
2022-09-22 18:26:05 +00:00
return Parser::parseSpecial(code, loc, scanner);
}
void DiscardParser::reset()
{
mState = StartState;
mTokenLoc = TokenLoc();
Parser::reset();
}
const TokenLoc& DiscardParser::getTokenLoc() const
{
return mTokenLoc;
}
}