Handle comments
This commit is contained in:
parent
0e9c9abf7c
commit
e0941a9db8
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -6,6 +6,7 @@ namespace Porygon::Parser {
|
|||
EndOfFile,
|
||||
BadToken,
|
||||
WhiteSpace,
|
||||
Comment,
|
||||
|
||||
PlusToken,
|
||||
MinusToken,
|
||||
|
|
Loading…
Reference in New Issue