mirror of https://github.com/AMT-Cheif/drift.git
Introduce special token class for keywords
This commit is contained in:
parent
4b0add64de
commit
3612c78241
|
@ -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));
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue