Handle comments

This commit is contained in:
Deukhoofd 2019-09-01 20:18:32 +02:00
parent 0e9c9abf7c
commit e0941a9db8
Signed by: Deukhoofd
GPG Key ID: ADF2E9256009EDCE
3 changed files with 15 additions and 1 deletions

View File

@ -18,7 +18,7 @@ namespace Porygon::Parser {
while (true) {
Token *next = this->LexNext(this->Next());
auto nextKind = next->GetKind();
if (nextKind != TokenKind::WhiteSpace)
if (nextKind != TokenKind::WhiteSpace && nextKind != TokenKind::Comment)
tokens.push_back(next);
else
delete next;
@ -54,6 +54,9 @@ namespace Porygon::Parser {
case '+':
return new SimpleToken(TokenKind::PlusToken, this->_position - 1, 1);
case '-':
if (Lexer::Peek() == '-') {
return LexComment();
}
return new SimpleToken(TokenKind::MinusToken, this->_position - 1, 1);
case '/':
return new SimpleToken(TokenKind::SlashToken, this->_position - 1, 1);
@ -318,4 +321,13 @@ namespace Porygon::Parser {
return new StringToken(stream.str(), start, end - start);
}
Token *Lexer::LexComment() {
auto start = Lexer::_position;
while (Lexer::Next() != '\n'){
continue;
}
auto length = Lexer::_position - start;
return new SimpleToken(TokenKind::Comment, start, length);
}
}

View File

@ -21,6 +21,7 @@ namespace Porygon::Parser{
Token* LexNumber(char16_t c);
Token* LexIdentifierOrKeyword();
Token* LexString(char16_t c);
Token* LexComment();
public:
Porygon::Script* ScriptData;

View File

@ -6,6 +6,7 @@ namespace Porygon::Parser {
EndOfFile,
BadToken,
WhiteSpace,
Comment,
PlusToken,
MinusToken,