allow use of IDs as function arguments, even if the ID matches a keyword (Fixes #2830)

sceneinput
Marc Zinnschlag 10 years ago
parent 8c8c5328dc
commit cbf9f83b85

@ -353,7 +353,10 @@ namespace Compiler
if (extensions->isInstruction (keyword, argumentType, hasExplicit)) if (extensions->isInstruction (keyword, argumentType, hasExplicit))
{ {
// pretend this is not a keyword // pretend this is not a keyword
return parseName (loc.mLiteral, loc, scanner); 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);
} }
} }

@ -222,6 +222,23 @@ namespace Compiler
bool LineParser::parseKeyword (int keyword, const TokenLoc& loc, Scanner& scanner) bool LineParser::parseKeyword (int keyword, const TokenLoc& loc, Scanner& scanner)
{ {
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);
}
}
}
if (mState==SetMemberVarState) if (mState==SetMemberVarState)
{ {
mMemberName = loc.mLiteral; mMemberName = loc.mLiteral;

@ -4,9 +4,12 @@
#include <algorithm> #include <algorithm>
#include <iterator> #include <iterator>
#include <components/misc/stringops.hpp>
#include "scanner.hpp" #include "scanner.hpp"
#include "generator.hpp" #include "generator.hpp"
#include <components/misc/stringops.hpp> #include "context.hpp"
#include "extensions.hpp"
namespace Compiler namespace Compiler
{ {
@ -33,6 +36,25 @@ namespace Compiler
return Parser::parseName (name, loc, scanner); return Parser::parseName (name, loc, scanner);
} }
bool StringParser::parseKeyword (int keyword, const TokenLoc& loc, Scanner& scanner)
{
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);
}
}
return Parser::parseKeyword (keyword, loc, scanner);
}
bool StringParser::parseSpecial (int code, const TokenLoc& loc, Scanner& scanner) bool StringParser::parseSpecial (int code, const TokenLoc& loc, Scanner& scanner)
{ {
if (code==Scanner::S_comma && mState==StartState) if (code==Scanner::S_comma && mState==StartState)

@ -32,6 +32,10 @@ namespace Compiler
///< Handle a name token. ///< Handle a name token.
/// \return fetch another token? /// \return fetch another token?
virtual bool parseKeyword (int keyword, const TokenLoc& loc, Scanner& scanner);
///< Handle a keyword token.
/// \return fetch another token?
virtual bool parseSpecial (int code, const TokenLoc& loc, Scanner& scanner); virtual bool parseSpecial (int code, const TokenLoc& loc, Scanner& scanner);
///< Handle a special character token. ///< Handle a special character token.
/// \return fetch another token? /// \return fetch another token?

Loading…
Cancel
Save