mirror of
https://github.com/OpenMW/openmw.git
synced 2025-01-16 15:29:55 +00:00
modified comma handling to be morse consistent with original script language
This commit is contained in:
parent
5fb4abae4f
commit
8bb2a6039d
4 changed files with 50 additions and 16 deletions
|
@ -177,11 +177,13 @@ namespace Compiler
|
|||
ExprParser::ExprParser (ErrorHandler& errorHandler, Context& context, Locals& locals,
|
||||
Literals& literals)
|
||||
: Parser (errorHandler, context), mLocals (locals), mLiterals (literals),
|
||||
mNextOperand (true)
|
||||
mNextOperand (true), mFirst (true)
|
||||
{}
|
||||
|
||||
bool ExprParser::parseInt (int value, const TokenLoc& loc, Scanner& scanner)
|
||||
{
|
||||
mFirst = false;
|
||||
|
||||
if (mNextOperand)
|
||||
{
|
||||
pushIntegerLiteral (value);
|
||||
|
@ -194,6 +196,8 @@ namespace Compiler
|
|||
|
||||
bool ExprParser::parseFloat (float value, const TokenLoc& loc, Scanner& scanner)
|
||||
{
|
||||
mFirst = false;
|
||||
|
||||
if (mNextOperand)
|
||||
{
|
||||
pushFloatLiteral (value);
|
||||
|
@ -207,11 +211,15 @@ namespace Compiler
|
|||
bool ExprParser::parseName (const std::string& name, const TokenLoc& loc,
|
||||
Scanner& scanner)
|
||||
{
|
||||
mFirst = false;
|
||||
|
||||
return Parser::parseName (name, loc, scanner);
|
||||
}
|
||||
|
||||
bool ExprParser::parseKeyword (int keyword, const TokenLoc& loc, Scanner& scanner)
|
||||
{
|
||||
mFirst = false;
|
||||
|
||||
if (keyword==Scanner::K_getsquareroot && mNextOperand)
|
||||
{
|
||||
mTokenLoc = loc;
|
||||
|
@ -230,16 +238,27 @@ namespace Compiler
|
|||
{
|
||||
if (code==Scanner::S_comma)
|
||||
{
|
||||
// end marker
|
||||
mTokenLoc = loc;
|
||||
|
||||
if (mFirst)
|
||||
{
|
||||
// leading comma
|
||||
mFirst = false;
|
||||
return true;
|
||||
}
|
||||
|
||||
// end marker
|
||||
scanner.putbackSpecial (code, loc);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
mFirst = false;
|
||||
|
||||
if (code==Scanner::S_newline)
|
||||
{
|
||||
// end marker
|
||||
mTokenLoc = loc;
|
||||
scanner.putbackNewline (loc);
|
||||
scanner.putbackSpecial (code, loc);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -286,6 +305,7 @@ namespace Compiler
|
|||
mOperators.clear();
|
||||
mNextOperand = true;
|
||||
mCode.clear();
|
||||
mFirst = true;
|
||||
}
|
||||
|
||||
char ExprParser::append (std::vector<Interpreter::Type_Code>& code)
|
||||
|
|
|
@ -22,6 +22,7 @@ namespace Compiler
|
|||
bool mNextOperand;
|
||||
TokenLoc mTokenLoc;
|
||||
std::vector<Interpreter::Type_Code> mCode;
|
||||
bool mFirst;
|
||||
|
||||
int getPriority (char op) const;
|
||||
|
||||
|
|
|
@ -43,10 +43,17 @@ namespace Compiler
|
|||
|
||||
bool Scanner::scanToken (Parser& parser)
|
||||
{
|
||||
if (mNewline)
|
||||
switch (mPutback)
|
||||
{
|
||||
mNewline = false;
|
||||
return parser.parseSpecial (S_newline, mPutbackLoc, *this);
|
||||
case Putback_Special:
|
||||
{
|
||||
mPutback = Putback_None;
|
||||
return parser.parseSpecial (mPutbackCode, mPutbackLoc, *this);
|
||||
}
|
||||
|
||||
case Putback_None:
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
char c;
|
||||
|
@ -419,20 +426,20 @@ namespace Compiler
|
|||
// constructor
|
||||
|
||||
Scanner::Scanner (ErrorHandler& errorHandler, std::istream& inputStream)
|
||||
: mErrorHandler (errorHandler), mStream (inputStream), mNewline (false)
|
||||
: mErrorHandler (errorHandler), mStream (inputStream), mPutback (Putback_None)
|
||||
{
|
||||
}
|
||||
|
||||
void Scanner::scan (Parser& parser)
|
||||
{
|
||||
mNewline = false;
|
||||
while (scanToken (parser));
|
||||
}
|
||||
|
||||
void Scanner::putbackNewline (const TokenLoc& loc)
|
||||
void Scanner::putbackSpecial (int code, const TokenLoc& loc)
|
||||
{
|
||||
mNewline = true;
|
||||
mPutbackLoc = loc;
|
||||
mPutback = Putback_Special;
|
||||
mPutbackCode = code;
|
||||
mPutbackLoc = loc;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -18,11 +18,17 @@ namespace Compiler
|
|||
|
||||
class Scanner
|
||||
{
|
||||
enum putback_type
|
||||
{
|
||||
Putback_None, Putback_Special,
|
||||
};
|
||||
|
||||
ErrorHandler& mErrorHandler;
|
||||
TokenLoc mLoc;
|
||||
TokenLoc mPrevLoc;
|
||||
std::istream& mStream;
|
||||
bool mNewline;
|
||||
putback_type mPutback;
|
||||
int mPutbackCode;
|
||||
TokenLoc mPutbackLoc;
|
||||
|
||||
public:
|
||||
|
@ -81,9 +87,9 @@ namespace Compiler
|
|||
|
||||
void scan (Parser& parser);
|
||||
///< Scan a token and deliver it to the parser.
|
||||
|
||||
void putbackNewline (const TokenLoc& loc);
|
||||
///< put back a newline token
|
||||
|
||||
void putbackSpecial (int code, const TokenLoc& loc);
|
||||
///< put back a special token
|
||||
};
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue