Introduce special token class for keywords

This commit is contained in:
Simon Binder 2019-08-27 11:54:56 +02:00
parent 4b0add64de
commit 3612c78241
No known key found for this signature in database
GPG Key ID: 7891917E4147B8C0
2 changed files with 8 additions and 1 deletions

View File

@ -306,7 +306,7 @@ class Scanner {
// not escaped, so it could be a keyword
final text = _currentSpan.text.toUpperCase();
if (keywords.containsKey(text)) {
_addToken(keywords[text]);
tokens.add(KeywordToken(keywords[text], _currentSpan));
} else {
tokens.add(IdentifierToken(false, _currentSpan));
}

View File

@ -266,6 +266,13 @@ class IdentifierToken extends Token {
: super(TokenType.identifier, span);
}
/// Used for tokens that are keywords. We use this special class without any
/// additional properties to ease syntax highlighting, as it allows us to find
/// the keywords easily.
class KeywordToken extends Token {
KeywordToken(TokenType type, FileSpan span) : super(type, span);
}
class TokenizerError {
final String message;
final SourceLocation location;