2010-06-28 10:12:47 +00:00
|
|
|
#include "lineparser.hpp"
|
|
|
|
|
2014-08-24 08:17:15 +00:00
|
|
|
#include <memory>
|
|
|
|
|
2014-02-10 12:01:52 +00:00
|
|
|
#include <components/misc/stringops.hpp>
|
|
|
|
|
2010-06-28 10:12:47 +00:00
|
|
|
#include "scanner.hpp"
|
2010-06-28 10:32:08 +00:00
|
|
|
#include "context.hpp"
|
|
|
|
#include "errorhandler.hpp"
|
2010-06-28 10:47:11 +00:00
|
|
|
#include "skipparser.hpp"
|
2010-06-28 11:28:50 +00:00
|
|
|
#include "locals.hpp"
|
2010-06-28 16:27:45 +00:00
|
|
|
#include "generator.hpp"
|
2010-07-03 18:35:59 +00:00
|
|
|
#include "extensions.hpp"
|
2014-02-10 12:01:52 +00:00
|
|
|
#include "declarationparser.hpp"
|
2014-07-27 09:51:53 +00:00
|
|
|
#include "exception.hpp"
|
2010-06-28 10:12:47 +00:00
|
|
|
|
|
|
|
namespace Compiler
|
|
|
|
{
|
2010-07-21 11:34:52 +00:00
|
|
|
void LineParser::parseExpression (Scanner& scanner, const TokenLoc& loc)
|
|
|
|
{
|
|
|
|
mExprParser.reset();
|
2010-08-22 09:14:14 +00:00
|
|
|
|
2010-07-21 11:34:52 +00:00
|
|
|
if (!mExplicit.empty())
|
|
|
|
{
|
|
|
|
mExprParser.parseName (mExplicit, loc, scanner);
|
2012-06-16 11:21:01 +00:00
|
|
|
if (mState==MemberState)
|
|
|
|
mExprParser.parseSpecial (Scanner::S_member, loc, scanner);
|
|
|
|
else
|
|
|
|
mExprParser.parseSpecial (Scanner::S_ref, loc, scanner);
|
2010-07-21 11:34:52 +00:00
|
|
|
}
|
2010-08-22 09:14:14 +00:00
|
|
|
|
2010-07-21 11:34:52 +00:00
|
|
|
scanner.scan (mExprParser);
|
2010-08-22 09:14:14 +00:00
|
|
|
|
2010-07-21 11:34:52 +00:00
|
|
|
char type = mExprParser.append (mCode);
|
2010-08-22 09:14:14 +00:00
|
|
|
mState = EndState;
|
|
|
|
|
2010-07-21 11:34:52 +00:00
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
case 'l':
|
2010-08-22 09:14:14 +00:00
|
|
|
|
2018-09-11 10:05:44 +00:00
|
|
|
Generator::report (mCode, mLiterals, "%d");
|
2010-07-21 11:34:52 +00:00
|
|
|
break;
|
2010-08-22 09:14:14 +00:00
|
|
|
|
2010-07-21 11:34:52 +00:00
|
|
|
case 'f':
|
2010-08-22 09:14:14 +00:00
|
|
|
|
2011-04-26 20:07:27 +00:00
|
|
|
Generator::report (mCode, mLiterals, "%f");
|
2010-07-21 11:34:52 +00:00
|
|
|
break;
|
2010-08-22 09:14:14 +00:00
|
|
|
|
2010-07-21 11:34:52 +00:00
|
|
|
default:
|
2010-08-22 09:14:14 +00:00
|
|
|
|
2010-07-21 11:34:52 +00:00
|
|
|
throw std::runtime_error ("unknown expression result type");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-14 11:23:00 +00:00
|
|
|
LineParser::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)
|
2010-06-28 14:48:19 +00:00
|
|
|
: Parser (errorHandler, context), mLocals (locals), mLiterals (literals), mCode (code),
|
2015-05-01 00:24:27 +00:00
|
|
|
mState (BeginState), mReferenceMember(false), mButtons(0), mType(0),
|
|
|
|
mExprParser (errorHandler, context, locals, literals), mAllowExpression (allowExpression)
|
2010-06-28 10:12:47 +00:00
|
|
|
{}
|
|
|
|
|
|
|
|
bool LineParser::parseInt (int value, const TokenLoc& loc, Scanner& scanner)
|
2010-08-22 09:14:14 +00:00
|
|
|
{
|
2010-07-21 11:34:52 +00:00
|
|
|
if (mAllowExpression && mState==BeginState)
|
|
|
|
{
|
|
|
|
scanner.putbackInt (value, loc);
|
|
|
|
parseExpression (scanner, loc);
|
|
|
|
return true;
|
|
|
|
}
|
2010-08-22 09:14:14 +00:00
|
|
|
|
2010-06-28 10:12:47 +00:00
|
|
|
return Parser::parseInt (value, loc, scanner);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool LineParser::parseFloat (float value, const TokenLoc& loc, Scanner& scanner)
|
|
|
|
{
|
2010-07-21 11:34:52 +00:00
|
|
|
if (mAllowExpression && mState==BeginState)
|
|
|
|
{
|
|
|
|
scanner.putbackFloat (value, loc);
|
|
|
|
parseExpression (scanner, loc);
|
|
|
|
return true;
|
|
|
|
}
|
2010-08-22 09:14:14 +00:00
|
|
|
|
2010-06-28 10:12:47 +00:00
|
|
|
return Parser::parseFloat (value, loc, scanner);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool LineParser::parseName (const std::string& name, const TokenLoc& loc,
|
|
|
|
Scanner& scanner)
|
|
|
|
{
|
2014-02-12 08:10:05 +00:00
|
|
|
if (mState==PotentialEndState)
|
|
|
|
{
|
2014-03-22 18:01:41 +00:00
|
|
|
getErrorHandler().warning ("stray string argument (ignoring it)", loc);
|
2014-02-12 08:10:05 +00:00
|
|
|
mState = EndState;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-06-28 16:27:45 +00:00
|
|
|
if (mState==SetState)
|
|
|
|
{
|
2013-01-09 19:51:52 +00:00
|
|
|
std::string name2 = Misc::StringUtils::lowerCase (name);
|
2012-06-16 12:29:55 +00:00
|
|
|
mName = name2;
|
2010-07-04 10:29:28 +00:00
|
|
|
|
|
|
|
// local variable?
|
2010-06-29 06:09:12 +00:00
|
|
|
char type = mLocals.getType (name2);
|
2010-06-28 16:27:45 +00:00
|
|
|
if (type!=' ')
|
|
|
|
{
|
2012-06-16 12:29:55 +00:00
|
|
|
mType = type;
|
2010-06-28 16:27:45 +00:00
|
|
|
mState = SetLocalVarState;
|
|
|
|
return true;
|
|
|
|
}
|
2010-08-22 09:14:14 +00:00
|
|
|
|
2010-07-04 10:29:28 +00:00
|
|
|
type = getContext().getGlobalType (name2);
|
|
|
|
if (type!=' ')
|
|
|
|
{
|
|
|
|
mType = type;
|
|
|
|
mState = SetGlobalVarState;
|
|
|
|
return true;
|
2010-08-22 09:14:14 +00:00
|
|
|
}
|
|
|
|
|
2012-06-16 12:29:55 +00:00
|
|
|
mState = SetPotentialMemberVarState;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mState==SetMemberVarState)
|
|
|
|
{
|
2014-08-24 15:46:08 +00:00
|
|
|
mMemberName = Misc::StringUtils::lowerCase (name);
|
2014-02-10 13:45:55 +00:00
|
|
|
std::pair<char, bool> type = getContext().getMemberType (mMemberName, mName);
|
2012-06-16 12:29:55 +00:00
|
|
|
|
2014-02-10 13:45:55 +00:00
|
|
|
if (type.first!=' ')
|
2012-06-16 12:29:55 +00:00
|
|
|
{
|
|
|
|
mState = SetMemberVarState2;
|
2014-02-10 13:45:55 +00:00
|
|
|
mType = type.first;
|
|
|
|
mReferenceMember = type.second;
|
2012-06-16 12:29:55 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-06-28 16:27:45 +00:00
|
|
|
getErrorHandler().error ("unknown variable", loc);
|
|
|
|
SkipParser skip (getErrorHandler(), getContext());
|
|
|
|
scanner.scan (skip);
|
2010-08-22 09:14:14 +00:00
|
|
|
return false;
|
2010-06-28 16:27:45 +00:00
|
|
|
}
|
2010-08-22 09:14:14 +00:00
|
|
|
|
2010-06-30 10:04:26 +00:00
|
|
|
if (mState==MessageState || mState==MessageCommaState)
|
|
|
|
{
|
2016-07-09 01:18:45 +00:00
|
|
|
GetArgumentsFromMessageFormat processor;
|
|
|
|
processor.process(name);
|
|
|
|
std::string arguments = processor.getArguments();
|
2010-07-01 14:40:03 +00:00
|
|
|
|
|
|
|
if (!arguments.empty())
|
|
|
|
{
|
|
|
|
mExprParser.reset();
|
2014-05-27 19:08:29 +00:00
|
|
|
mExprParser.parseArguments (arguments, scanner, mCode);
|
2010-07-01 14:40:03 +00:00
|
|
|
}
|
|
|
|
|
2010-08-22 09:14:14 +00:00
|
|
|
mName = name;
|
|
|
|
mButtons = 0;
|
|
|
|
|
|
|
|
mState = MessageButtonState;
|
|
|
|
return true;
|
2010-06-30 10:04:26 +00:00
|
|
|
}
|
2010-08-22 09:14:14 +00:00
|
|
|
|
|
|
|
if (mState==MessageButtonState || mState==MessageButtonCommaState)
|
|
|
|
{
|
|
|
|
Generator::pushString (mCode, mLiterals, name);
|
|
|
|
mState = MessageButtonState;
|
|
|
|
++mButtons;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-08-30 12:44:23 +00:00
|
|
|
if (mState==BeginState && getContext().isId (name))
|
|
|
|
{
|
|
|
|
mState = PotentialExplicitState;
|
2013-01-09 19:51:52 +00:00
|
|
|
mExplicit = Misc::StringUtils::lowerCase (name);
|
2010-08-30 12:44:23 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-07-21 11:34:52 +00:00
|
|
|
if (mState==BeginState && mAllowExpression)
|
|
|
|
{
|
2013-01-09 19:51:52 +00:00
|
|
|
std::string name2 = Misc::StringUtils::lowerCase (name);
|
2010-08-22 09:14:14 +00:00
|
|
|
|
2010-07-21 11:34:52 +00:00
|
|
|
char type = mLocals.getType (name2);
|
2010-08-22 09:14:14 +00:00
|
|
|
|
2010-07-21 11:34:52 +00:00
|
|
|
if (type!=' ')
|
|
|
|
{
|
|
|
|
scanner.putbackName (name, loc);
|
|
|
|
parseExpression (scanner, loc);
|
2010-08-22 09:14:14 +00:00
|
|
|
return true;
|
2010-07-21 11:34:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type = getContext().getGlobalType (name2);
|
2010-08-22 09:14:14 +00:00
|
|
|
|
2010-07-21 11:34:52 +00:00
|
|
|
if (type!=' ')
|
|
|
|
{
|
|
|
|
scanner.putbackName (name, loc);
|
|
|
|
parseExpression (scanner, loc);
|
2010-08-22 09:14:14 +00:00
|
|
|
return true;
|
|
|
|
}
|
2010-07-21 11:34:52 +00:00
|
|
|
}
|
2010-08-22 09:14:14 +00:00
|
|
|
|
2010-06-28 10:12:47 +00:00
|
|
|
return Parser::parseName (name, loc, scanner);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool LineParser::parseKeyword (int keyword, const TokenLoc& loc, Scanner& scanner)
|
|
|
|
{
|
2015-08-05 15:20:01 +00:00
|
|
|
if (mState==MessageState || mState==MessageCommaState)
|
|
|
|
{
|
|
|
|
if (const Extensions *extensions = getContext().getExtensions())
|
|
|
|
{
|
|
|
|
std::string argumentType; // ignored
|
|
|
|
bool hasExplicit = false; // ignored
|
|
|
|
if (extensions->isInstruction (keyword, argumentType, hasExplicit))
|
|
|
|
{
|
|
|
|
// pretend this is not a keyword
|
|
|
|
std::string name = loc.mLiteral;
|
|
|
|
if (name.size()>=2 && name[0]=='"' && name[name.size()-1]=='"')
|
|
|
|
name = name.substr (1, name.size()-2);
|
|
|
|
return parseName (name, loc, scanner);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-14 08:06:06 +00:00
|
|
|
if (mState==SetMemberVarState)
|
|
|
|
{
|
|
|
|
mMemberName = loc.mLiteral;
|
|
|
|
std::pair<char, bool> type = getContext().getMemberType (mMemberName, mName);
|
|
|
|
|
|
|
|
if (type.first!=' ')
|
|
|
|
{
|
|
|
|
mState = SetMemberVarState2;
|
|
|
|
mType = type.first;
|
|
|
|
mReferenceMember = type.second;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-12 19:23:47 +00:00
|
|
|
if (mState==SetPotentialMemberVarState && keyword==Scanner::K_to)
|
|
|
|
{
|
|
|
|
getErrorHandler().warning ("unknown variable (ignoring set instruction)", loc);
|
|
|
|
SkipParser skip (getErrorHandler(), getContext());
|
|
|
|
scanner.scan (skip);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-02-12 08:23:23 +00:00
|
|
|
if (mState==SetState)
|
|
|
|
{
|
|
|
|
// allow keywords to be used as variable names when assigning a value to a variable.
|
|
|
|
return parseName (loc.mLiteral, loc, scanner);
|
|
|
|
}
|
|
|
|
|
2010-07-09 17:32:17 +00:00
|
|
|
if (mState==BeginState || mState==ExplicitState)
|
|
|
|
{
|
|
|
|
switch (keyword)
|
2010-08-22 09:14:14 +00:00
|
|
|
{
|
2010-07-09 17:32:17 +00:00
|
|
|
case Scanner::K_enable:
|
2010-08-22 09:14:14 +00:00
|
|
|
|
2010-07-09 17:32:17 +00:00
|
|
|
Generator::enable (mCode, mLiterals, mExplicit);
|
2014-02-12 08:10:05 +00:00
|
|
|
mState = PotentialEndState;
|
2010-08-22 09:14:14 +00:00
|
|
|
return true;
|
|
|
|
|
2010-07-09 17:32:17 +00:00
|
|
|
case Scanner::K_disable:
|
2010-08-22 09:14:14 +00:00
|
|
|
|
2010-07-09 17:32:17 +00:00
|
|
|
Generator::disable (mCode, mLiterals, mExplicit);
|
2014-02-12 08:10:05 +00:00
|
|
|
mState = PotentialEndState;
|
2010-08-22 09:14:14 +00:00
|
|
|
return true;
|
2014-07-17 06:35:28 +00:00
|
|
|
|
|
|
|
case Scanner::K_startscript:
|
|
|
|
|
|
|
|
mExprParser.parseArguments ("c", scanner, mCode);
|
|
|
|
Generator::startScript (mCode, mLiterals, mExplicit);
|
|
|
|
mState = EndState;
|
|
|
|
return true;
|
2014-07-23 10:33:35 +00:00
|
|
|
|
|
|
|
case Scanner::K_stopscript:
|
|
|
|
|
|
|
|
mExprParser.parseArguments ("c", scanner, mCode);
|
|
|
|
Generator::stopScript (mCode);
|
|
|
|
mState = EndState;
|
|
|
|
return true;
|
2010-07-09 17:32:17 +00:00
|
|
|
}
|
2010-08-22 09:14:14 +00:00
|
|
|
|
2010-07-09 20:01:24 +00:00
|
|
|
// check for custom extensions
|
|
|
|
if (const Extensions *extensions = getContext().getExtensions())
|
|
|
|
{
|
|
|
|
std::string argumentType;
|
2010-08-22 09:14:14 +00:00
|
|
|
|
2014-02-11 13:55:31 +00:00
|
|
|
bool hasExplicit = mState==ExplicitState;
|
|
|
|
if (extensions->isInstruction (keyword, argumentType, hasExplicit))
|
2010-07-09 20:01:24 +00:00
|
|
|
{
|
2014-02-11 13:55:31 +00:00
|
|
|
if (!hasExplicit && mState==ExplicitState)
|
|
|
|
{
|
|
|
|
getErrorHandler().warning ("stray explicit reference (ignoring it)", loc);
|
|
|
|
mExplicit.clear();
|
|
|
|
}
|
|
|
|
|
2014-07-27 09:51:53 +00:00
|
|
|
try
|
|
|
|
{
|
2014-08-24 08:17:15 +00:00
|
|
|
// workaround for broken positioncell instructions.
|
|
|
|
/// \todo add option to disable this
|
2017-04-28 15:30:26 +00:00
|
|
|
std::unique_ptr<ErrorDowngrade> errorDowngrade (nullptr);
|
2014-08-24 08:17:15 +00:00
|
|
|
if (Misc::StringUtils::lowerCase (loc.mLiteral)=="positioncell")
|
|
|
|
errorDowngrade.reset (new ErrorDowngrade (getErrorHandler()));
|
|
|
|
|
2014-07-27 09:51:53 +00:00
|
|
|
std::vector<Interpreter::Type_Code> code;
|
2014-12-17 14:03:05 +00:00
|
|
|
int optionals = mExprParser.parseArguments (argumentType, scanner, code, keyword);
|
2014-09-09 11:55:10 +00:00
|
|
|
mCode.insert (mCode.end(), code.begin(), code.end());
|
2014-07-27 09:51:53 +00:00
|
|
|
extensions->generateInstructionCode (keyword, mCode, mLiterals,
|
|
|
|
mExplicit, optionals);
|
|
|
|
}
|
2014-09-23 02:33:09 +00:00
|
|
|
catch (const SourceException&)
|
2014-07-27 09:51:53 +00:00
|
|
|
{
|
|
|
|
// Ignore argument exceptions for positioncell.
|
|
|
|
/// \todo add option to disable this
|
|
|
|
if (Misc::StringUtils::lowerCase (loc.mLiteral)=="positioncell")
|
|
|
|
{
|
|
|
|
SkipParser skip (getErrorHandler(), getContext());
|
|
|
|
scanner.scan (skip);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
throw;
|
|
|
|
}
|
2010-08-22 09:14:14 +00:00
|
|
|
|
2010-07-09 20:01:24 +00:00
|
|
|
mState = EndState;
|
|
|
|
return true;
|
|
|
|
}
|
2010-08-22 09:14:14 +00:00
|
|
|
}
|
|
|
|
|
2010-07-21 11:34:52 +00:00
|
|
|
if (mAllowExpression)
|
|
|
|
{
|
|
|
|
if (keyword==Scanner::K_getdisabled || keyword==Scanner::K_getdistance)
|
|
|
|
{
|
|
|
|
scanner.putbackKeyword (keyword, loc);
|
|
|
|
parseExpression (scanner, loc);
|
2012-06-16 11:21:01 +00:00
|
|
|
mState = EndState;
|
2010-08-22 09:14:14 +00:00
|
|
|
return true;
|
2010-07-21 11:34:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (const Extensions *extensions = getContext().getExtensions())
|
|
|
|
{
|
|
|
|
char returnType;
|
|
|
|
std::string argumentType;
|
2010-08-22 09:14:14 +00:00
|
|
|
|
2014-02-12 12:53:59 +00:00
|
|
|
bool hasExplicit = !mExplicit.empty();
|
|
|
|
|
|
|
|
if (extensions->isFunction (keyword, returnType, argumentType, hasExplicit))
|
2010-07-21 11:34:52 +00:00
|
|
|
{
|
2014-02-12 12:53:59 +00:00
|
|
|
if (!hasExplicit && !mExplicit.empty())
|
|
|
|
{
|
|
|
|
getErrorHandler().warning ("stray explicit reference (ignoring it)", loc);
|
|
|
|
mExplicit.clear();
|
|
|
|
}
|
|
|
|
|
2010-07-21 11:34:52 +00:00
|
|
|
scanner.putbackKeyword (keyword, loc);
|
|
|
|
parseExpression (scanner, loc);
|
2012-06-16 11:21:01 +00:00
|
|
|
mState = EndState;
|
2010-08-22 09:14:14 +00:00
|
|
|
return true;
|
2010-07-21 11:34:52 +00:00
|
|
|
}
|
2010-08-22 09:14:14 +00:00
|
|
|
}
|
2010-07-21 11:34:52 +00:00
|
|
|
}
|
2010-07-09 17:32:17 +00:00
|
|
|
}
|
2010-08-22 09:14:14 +00:00
|
|
|
|
2014-02-11 13:55:31 +00:00
|
|
|
if (mState==ExplicitState)
|
|
|
|
{
|
|
|
|
// drop stray explicit reference
|
|
|
|
getErrorHandler().warning ("stray explicit reference (ignoring it)", loc);
|
|
|
|
mState = BeginState;
|
|
|
|
mExplicit.clear();
|
|
|
|
}
|
|
|
|
|
2010-06-28 10:32:08 +00:00
|
|
|
if (mState==BeginState)
|
|
|
|
{
|
|
|
|
switch (keyword)
|
|
|
|
{
|
2014-02-10 12:01:52 +00:00
|
|
|
case Scanner::K_short:
|
|
|
|
case Scanner::K_long:
|
|
|
|
case Scanner::K_float:
|
|
|
|
{
|
|
|
|
if (!getContext().canDeclareLocals())
|
|
|
|
{
|
|
|
|
getErrorHandler().error (
|
|
|
|
"local variables can't be declared in this context", loc);
|
|
|
|
SkipParser skip (getErrorHandler(), getContext());
|
|
|
|
scanner.scan (skip);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
DeclarationParser declaration (getErrorHandler(), getContext(), mLocals);
|
|
|
|
if (declaration.parseKeyword (keyword, loc, scanner))
|
|
|
|
scanner.scan (declaration);
|
|
|
|
|
2014-07-27 18:49:57 +00:00
|
|
|
return false;
|
2014-02-10 12:01:52 +00:00
|
|
|
}
|
|
|
|
|
2010-06-28 16:27:45 +00:00
|
|
|
case Scanner::K_set: mState = SetState; return true;
|
2015-12-03 10:14:58 +00:00
|
|
|
|
|
|
|
case Scanner::K_messagebox:
|
|
|
|
|
|
|
|
mState = MessageState;
|
|
|
|
scanner.enableStrictKeywords();
|
|
|
|
return true;
|
2010-08-22 09:14:14 +00:00
|
|
|
|
2010-06-30 10:04:26 +00:00
|
|
|
case Scanner::K_return:
|
2010-08-22 09:14:14 +00:00
|
|
|
|
2010-06-30 10:04:26 +00:00
|
|
|
Generator::exit (mCode);
|
|
|
|
mState = EndState;
|
|
|
|
return true;
|
2010-08-22 09:14:14 +00:00
|
|
|
|
2010-07-04 14:00:32 +00:00
|
|
|
case Scanner::K_stopscript:
|
|
|
|
|
2014-05-27 19:08:29 +00:00
|
|
|
mExprParser.parseArguments ("c", scanner, mCode);
|
2010-07-04 14:00:32 +00:00
|
|
|
Generator::stopScript (mCode);
|
|
|
|
mState = EndState;
|
2010-08-22 09:14:14 +00:00
|
|
|
return true;
|
2014-02-12 07:42:42 +00:00
|
|
|
|
|
|
|
case Scanner::K_else:
|
|
|
|
|
2014-03-22 18:01:41 +00:00
|
|
|
getErrorHandler().warning ("stray else (ignoring it)", loc);
|
2014-02-12 07:42:42 +00:00
|
|
|
mState = EndState;
|
|
|
|
return true;
|
|
|
|
|
|
|
|
case Scanner::K_endif:
|
|
|
|
|
2014-03-22 18:01:41 +00:00
|
|
|
getErrorHandler().warning ("stray endif (ignoring it)", loc);
|
2014-02-12 07:42:42 +00:00
|
|
|
mState = EndState;
|
|
|
|
return true;
|
2014-02-12 12:45:01 +00:00
|
|
|
|
|
|
|
case Scanner::K_begin:
|
|
|
|
|
2014-03-22 18:01:41 +00:00
|
|
|
getErrorHandler().warning ("stray begin (ignoring it)", loc);
|
2014-02-12 12:45:01 +00:00
|
|
|
mState = EndState;
|
|
|
|
return true;
|
2010-06-28 10:32:08 +00:00
|
|
|
}
|
|
|
|
}
|
2010-06-28 16:27:45 +00:00
|
|
|
else if (mState==SetLocalVarState && keyword==Scanner::K_to)
|
|
|
|
{
|
2010-06-29 08:22:55 +00:00
|
|
|
mExprParser.reset();
|
|
|
|
scanner.scan (mExprParser);
|
2010-08-22 09:14:14 +00:00
|
|
|
|
2010-06-29 08:22:55 +00:00
|
|
|
std::vector<Interpreter::Type_Code> code;
|
2010-06-29 14:11:19 +00:00
|
|
|
char type = mExprParser.append (code);
|
2010-08-22 09:14:14 +00:00
|
|
|
|
2010-06-29 08:22:55 +00:00
|
|
|
Generator::assignToLocal (mCode, mLocals.getType (mName),
|
|
|
|
mLocals.getIndex (mName), code, type);
|
2010-08-22 09:14:14 +00:00
|
|
|
|
2010-06-29 08:22:55 +00:00
|
|
|
mState = EndState;
|
2010-06-28 16:27:45 +00:00
|
|
|
return true;
|
|
|
|
}
|
2010-07-04 10:29:28 +00:00
|
|
|
else if (mState==SetGlobalVarState && keyword==Scanner::K_to)
|
|
|
|
{
|
|
|
|
mExprParser.reset();
|
|
|
|
scanner.scan (mExprParser);
|
2010-08-22 09:14:14 +00:00
|
|
|
|
2010-07-04 10:29:28 +00:00
|
|
|
std::vector<Interpreter::Type_Code> code;
|
|
|
|
char type = mExprParser.append (code);
|
2010-08-22 09:14:14 +00:00
|
|
|
|
2010-07-04 10:29:28 +00:00
|
|
|
Generator::assignToGlobal (mCode, mLiterals, mType, mName, code, type);
|
2010-08-22 09:14:14 +00:00
|
|
|
|
2010-07-04 10:29:28 +00:00
|
|
|
mState = EndState;
|
|
|
|
return true;
|
|
|
|
}
|
2012-06-16 12:29:55 +00:00
|
|
|
else if (mState==SetMemberVarState2 && keyword==Scanner::K_to)
|
|
|
|
{
|
|
|
|
mExprParser.reset();
|
|
|
|
scanner.scan (mExprParser);
|
|
|
|
|
|
|
|
std::vector<Interpreter::Type_Code> code;
|
|
|
|
char type = mExprParser.append (code);
|
|
|
|
|
2014-02-10 13:45:55 +00:00
|
|
|
Generator::assignToMember (mCode, mLiterals, mType, mMemberName, mName, code, type,
|
|
|
|
!mReferenceMember);
|
2012-06-16 12:29:55 +00:00
|
|
|
|
|
|
|
mState = EndState;
|
|
|
|
return true;
|
|
|
|
}
|
2010-08-22 09:14:14 +00:00
|
|
|
|
2010-07-21 11:34:52 +00:00
|
|
|
if (mAllowExpression)
|
|
|
|
{
|
|
|
|
if (keyword==Scanner::K_getsquareroot || keyword==Scanner::K_menumode ||
|
|
|
|
keyword==Scanner::K_random || keyword==Scanner::K_scriptrunning ||
|
|
|
|
keyword==Scanner::K_getsecondspassed)
|
|
|
|
{
|
|
|
|
scanner.putbackKeyword (keyword, loc);
|
|
|
|
parseExpression (scanner, loc);
|
2012-06-16 11:21:01 +00:00
|
|
|
mState = EndState;
|
2010-08-22 09:14:14 +00:00
|
|
|
return true;
|
|
|
|
}
|
2010-07-21 11:34:52 +00:00
|
|
|
}
|
2010-08-22 09:14:14 +00:00
|
|
|
|
2010-06-28 10:12:47 +00:00
|
|
|
return Parser::parseKeyword (keyword, loc, scanner);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool LineParser::parseSpecial (int code, const TokenLoc& loc, Scanner& scanner)
|
|
|
|
{
|
2014-12-13 14:43:40 +00:00
|
|
|
if (mState==EndState && code==Scanner::S_open)
|
|
|
|
{
|
|
|
|
getErrorHandler().warning ("stray '[' or '(' at the end of the line (ignoring it)",
|
|
|
|
loc);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-02-12 08:10:05 +00:00
|
|
|
if (code==Scanner::S_newline &&
|
|
|
|
(mState==EndState || mState==BeginState || mState==PotentialEndState))
|
2010-06-28 10:32:08 +00:00
|
|
|
return false;
|
2010-08-22 09:14:14 +00:00
|
|
|
|
2010-06-30 10:04:26 +00:00
|
|
|
if (code==Scanner::S_comma && mState==MessageState)
|
|
|
|
{
|
|
|
|
mState = MessageCommaState;
|
|
|
|
return true;
|
|
|
|
}
|
2010-08-22 09:14:14 +00:00
|
|
|
|
2010-07-09 17:32:17 +00:00
|
|
|
if (code==Scanner::S_ref && mState==PotentialExplicitState)
|
|
|
|
{
|
|
|
|
mState = ExplicitState;
|
|
|
|
return true;
|
|
|
|
}
|
2010-08-22 09:14:14 +00:00
|
|
|
|
2018-06-12 15:52:16 +00:00
|
|
|
if (code==Scanner::S_member && mState==PotentialExplicitState && mAllowExpression)
|
2012-06-16 11:21:01 +00:00
|
|
|
{
|
|
|
|
mState = MemberState;
|
|
|
|
parseExpression (scanner, loc);
|
|
|
|
mState = EndState;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-08-22 09:14:14 +00:00
|
|
|
if (code==Scanner::S_newline && mState==MessageButtonState)
|
|
|
|
{
|
|
|
|
Generator::message (mCode, mLiterals, mName, mButtons);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (code==Scanner::S_comma && mState==MessageButtonState)
|
|
|
|
{
|
|
|
|
mState = MessageButtonCommaState;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-06-16 12:29:55 +00:00
|
|
|
if (code==Scanner::S_member && mState==SetPotentialMemberVarState)
|
|
|
|
{
|
|
|
|
mState = SetMemberVarState;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-07-21 11:34:52 +00:00
|
|
|
if (mAllowExpression && mState==BeginState &&
|
2015-09-26 09:30:35 +00:00
|
|
|
(code==Scanner::S_open || code==Scanner::S_minus || code==Scanner::S_plus))
|
2010-07-21 11:34:52 +00:00
|
|
|
{
|
|
|
|
scanner.putbackSpecial (code, loc);
|
|
|
|
parseExpression (scanner, loc);
|
2012-06-16 11:21:01 +00:00
|
|
|
mState = EndState;
|
2010-08-22 09:14:14 +00:00
|
|
|
return true;
|
2010-07-21 11:34:52 +00:00
|
|
|
}
|
2010-08-22 09:14:14 +00:00
|
|
|
|
2010-06-28 10:12:47 +00:00
|
|
|
return Parser::parseSpecial (code, loc, scanner);
|
|
|
|
}
|
2010-08-22 09:14:14 +00:00
|
|
|
|
2010-06-28 10:12:47 +00:00
|
|
|
void LineParser::reset()
|
|
|
|
{
|
2010-06-28 10:32:08 +00:00
|
|
|
mState = BeginState;
|
2010-06-28 16:27:45 +00:00
|
|
|
mName.clear();
|
2010-07-09 17:32:17 +00:00
|
|
|
mExplicit.clear();
|
2010-06-28 10:12:47 +00:00
|
|
|
}
|
2016-07-09 01:18:45 +00:00
|
|
|
|
2018-08-12 21:45:03 +00:00
|
|
|
void GetArgumentsFromMessageFormat::visitedPlaceholder(Placeholder placeholder, char /*padding*/, int /*width*/, int /*precision*/, Notation /*notation*/)
|
2016-07-09 01:18:45 +00:00
|
|
|
{
|
|
|
|
switch (placeholder)
|
|
|
|
{
|
|
|
|
case StringPlaceholder:
|
|
|
|
mArguments += 'S';
|
|
|
|
break;
|
|
|
|
case IntegerPlaceholder:
|
|
|
|
mArguments += 'l';
|
|
|
|
break;
|
|
|
|
case FloatPlaceholder:
|
|
|
|
mArguments += 'f';
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-06-28 10:12:47 +00:00
|
|
|
}
|