Fix memory leak related to lexer skipping whitespace.
This commit is contained in:
parent
4a034bc051
commit
b2fa857c9b
|
@ -6,7 +6,7 @@
|
|||
#include "Lexer.hpp"
|
||||
|
||||
Lexer::Lexer(string scriptString, class Script* script) {
|
||||
this -> ScriptString = std::move(scriptString);
|
||||
this -> _scriptString = std::move(scriptString);
|
||||
this -> ScriptData = script;
|
||||
this -> Position = 0;
|
||||
}
|
||||
|
@ -18,6 +18,8 @@ vector<IToken*> Lexer::Lex() {
|
|||
auto nextKind = next -> GetKind();
|
||||
if (nextKind != TokenKind::WhiteSpace)
|
||||
tokens.push_back(next);
|
||||
else
|
||||
delete next;
|
||||
if (nextKind == TokenKind::EndOfFile)
|
||||
break;
|
||||
}
|
||||
|
@ -25,9 +27,9 @@ vector<IToken*> Lexer::Lex() {
|
|||
}
|
||||
|
||||
char Lexer::Peek(){
|
||||
if (Lexer::Position > this -> ScriptString.length())
|
||||
if (Lexer::Position > this -> _scriptString.length())
|
||||
return '\0';
|
||||
return this -> ScriptString[Lexer::Position];
|
||||
return this -> _scriptString[Lexer::Position];
|
||||
}
|
||||
|
||||
char Lexer::Next(){
|
||||
|
@ -164,7 +166,7 @@ IToken * Lexer::LexIdentifierOrKeyword() {
|
|||
}
|
||||
}
|
||||
|
||||
string s = this -> ScriptString.substr(start, end - start + 1);
|
||||
string s = this -> _scriptString.substr(start, end - start + 1);
|
||||
switch (const_hash(s.c_str())){
|
||||
case const_hash("and"): return new SimpleToken(TokenKind::AndKeyword, start, 3);
|
||||
case const_hash("break"): return new SimpleToken(TokenKind::BreakKeyword, start, 5);
|
||||
|
@ -222,7 +224,7 @@ IToken* Lexer::LexString(char c){
|
|||
return new SimpleToken(TokenKind::BadToken, start, end -start + 1);
|
||||
}
|
||||
|
||||
string s = this -> ScriptString.substr(start + 1, end - start);
|
||||
string s = this -> _scriptString.substr(start + 1, end - start);
|
||||
stringstream stream;
|
||||
for (int i = 0; i < s.size(); i++){
|
||||
c = s[i];
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
using namespace std;
|
||||
|
||||
class Lexer {
|
||||
string ScriptString;
|
||||
string _scriptString;
|
||||
#ifdef TESTS_BUILD
|
||||
public:
|
||||
#endif
|
||||
|
@ -17,8 +17,8 @@ public:
|
|||
char Next();
|
||||
IToken* LexNext(char c);
|
||||
IToken* LexNumber(char c);
|
||||
IToken *LexIdentifierOrKeyword();
|
||||
IToken *LexString(char c);
|
||||
IToken* LexIdentifierOrKeyword();
|
||||
IToken* LexString(char c);
|
||||
public:
|
||||
Script* ScriptData;
|
||||
|
||||
|
|
Loading…
Reference in New Issue