Handle comments
This commit is contained in:
parent
0e9c9abf7c
commit
e0941a9db8
|
@ -18,7 +18,7 @@ namespace Porygon::Parser {
|
||||||
while (true) {
|
while (true) {
|
||||||
Token *next = this->LexNext(this->Next());
|
Token *next = this->LexNext(this->Next());
|
||||||
auto nextKind = next->GetKind();
|
auto nextKind = next->GetKind();
|
||||||
if (nextKind != TokenKind::WhiteSpace)
|
if (nextKind != TokenKind::WhiteSpace && nextKind != TokenKind::Comment)
|
||||||
tokens.push_back(next);
|
tokens.push_back(next);
|
||||||
else
|
else
|
||||||
delete next;
|
delete next;
|
||||||
|
@ -54,6 +54,9 @@ namespace Porygon::Parser {
|
||||||
case '+':
|
case '+':
|
||||||
return new SimpleToken(TokenKind::PlusToken, this->_position - 1, 1);
|
return new SimpleToken(TokenKind::PlusToken, this->_position - 1, 1);
|
||||||
case '-':
|
case '-':
|
||||||
|
if (Lexer::Peek() == '-') {
|
||||||
|
return LexComment();
|
||||||
|
}
|
||||||
return new SimpleToken(TokenKind::MinusToken, this->_position - 1, 1);
|
return new SimpleToken(TokenKind::MinusToken, this->_position - 1, 1);
|
||||||
case '/':
|
case '/':
|
||||||
return new SimpleToken(TokenKind::SlashToken, this->_position - 1, 1);
|
return new SimpleToken(TokenKind::SlashToken, this->_position - 1, 1);
|
||||||
|
@ -318,4 +321,13 @@ namespace Porygon::Parser {
|
||||||
return new StringToken(stream.str(), start, end - start);
|
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* LexNumber(char16_t c);
|
||||||
Token* LexIdentifierOrKeyword();
|
Token* LexIdentifierOrKeyword();
|
||||||
Token* LexString(char16_t c);
|
Token* LexString(char16_t c);
|
||||||
|
Token* LexComment();
|
||||||
public:
|
public:
|
||||||
Porygon::Script* ScriptData;
|
Porygon::Script* ScriptData;
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,7 @@ namespace Porygon::Parser {
|
||||||
EndOfFile,
|
EndOfFile,
|
||||||
BadToken,
|
BadToken,
|
||||||
WhiteSpace,
|
WhiteSpace,
|
||||||
|
Comment,
|
||||||
|
|
||||||
PlusToken,
|
PlusToken,
|
||||||
MinusToken,
|
MinusToken,
|
||||||
|
|
Loading…
Reference in New Issue