This commit is contained in:
mrexodia 2016-11-22 09:37:09 +01:00
parent 87003fef8d
commit c8ca8305e2
No known key found for this signature in database
GPG Key ID: FC89E0AAA0C1AAD8
4 changed files with 149 additions and 136 deletions

View File

@ -94,7 +94,8 @@ bool Lexer::Test(const std::function<void(const std::string & line)> & lexEnum,
toks.append(TokString(tok)); toks.append(TokString(tok));
appendCh(toks, ' '); appendCh(toks, ' ');
lexEnum(toks); lexEnum(toks);
} while (tok != tok_eof && tok != tok_error); }
while(tok != tok_eof && tok != tok_error);
if(tok != tok_error && tok != tok_eof) if(tok != tok_error && tok != tok_eof)
tok = reportError("lexer did not finish at the end of the file"); tok = reportError("lexer did not finish at the end of the file");
for(const auto & warning : mWarnings) for(const auto & warning : mWarnings)
@ -314,7 +315,8 @@ Lexer::Token Lexer::getToken()
if(mLastChar == '\n') if(mLastChar == '\n')
signalNewLine(); signalNewLine();
nextChar(); nextChar();
} while (!(mLastChar == EOF || mLastChar == '\n')); }
while(!(mLastChar == EOF || mLastChar == '\n'));
return getToken(); //interpret the next line return getToken(); //interpret the next line
} }
@ -325,7 +327,8 @@ Lexer::Token Lexer::getToken()
if(mLastChar == '\n') if(mLastChar == '\n')
signalNewLine(); signalNewLine();
nextChar(); nextChar();
} while (!(mLastChar == EOF || mLastChar == '*' && peekChar() == '/')); }
while(!(mLastChar == EOF || mLastChar == '*' && peekChar() == '/'));
if(mLastChar == EOF) //unexpected end of file if(mLastChar == EOF) //unexpected end of file
{ {
@ -437,11 +440,16 @@ std::string Lexer::TokString(const TokenState & ts)
{ {
switch(ts.Token) switch(ts.Token)
{ {
case tok_eof: return "tok_eof"; case tok_eof:
case tok_error: return StringUtils::sprintf("error(line %d, col %d, \"%s\")", ts.CurLine + 1, ts.LineIndex, mError.c_str()); return "tok_eof";
case tok_identifier: return ts.IdentifierStr; case tok_error:
case tok_number: return StringUtils::sprintf(mIsHexNumberVal ? "0x%llX" : "%llu", ts.NumberVal); return StringUtils::sprintf("error(line %d, col %d, \"%s\")", ts.CurLine + 1, ts.LineIndex, mError.c_str());
case tok_stringlit: return StringUtils::sprintf("\"%s\"", StringUtils::Escape(ts.StringLit).c_str()); case tok_identifier:
return ts.IdentifierStr;
case tok_number:
return StringUtils::sprintf(mIsHexNumberVal ? "0x%llX" : "%llu", ts.NumberVal);
case tok_stringlit:
return StringUtils::sprintf("\"%s\"", StringUtils::Escape(ts.StringLit).c_str());
case tok_charlit: case tok_charlit:
{ {
std::string s; std::string s;
@ -462,11 +470,16 @@ std::string Lexer::TokString(Token tok)
{ {
switch(tok) switch(tok)
{ {
case tok_eof: return "tok_eof"; case tok_eof:
case tok_error: return StringUtils::sprintf("error(line %d, col %d, \"%s\")", mState.CurLine + 1, mState.LineIndex, mError.c_str()); return "tok_eof";
case tok_identifier: return mState.IdentifierStr; case tok_error:
case tok_number: return StringUtils::sprintf(mIsHexNumberVal ? "0x%llX" : "%llu", mState.NumberVal); return StringUtils::sprintf("error(line %d, col %d, \"%s\")", mState.CurLine + 1, mState.LineIndex, mError.c_str());
case tok_stringlit: return StringUtils::sprintf("\"%s\"", StringUtils::Escape(mState.StringLit).c_str()); case tok_identifier:
return mState.IdentifierStr;
case tok_number:
return StringUtils::sprintf(mIsHexNumberVal ? "0x%llX" : "%llu", mState.NumberVal);
case tok_stringlit:
return StringUtils::sprintf("\"%s\"", StringUtils::Escape(mState.StringLit).c_str());
case tok_charlit: case tok_charlit:
{ {
std::string s; std::string s;