From 3612c78241311aec24650045827c5a3d98789194 Mon Sep 17 00:00:00 2001 From: Simon Binder Date: Tue, 27 Aug 2019 11:54:56 +0200 Subject: [PATCH] Introduce special token class for keywords --- sqlparser/lib/src/reader/tokenizer/scanner.dart | 2 +- sqlparser/lib/src/reader/tokenizer/token.dart | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/sqlparser/lib/src/reader/tokenizer/scanner.dart b/sqlparser/lib/src/reader/tokenizer/scanner.dart index 989d56bd..1dc48072 100644 --- a/sqlparser/lib/src/reader/tokenizer/scanner.dart +++ b/sqlparser/lib/src/reader/tokenizer/scanner.dart @@ -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)); } diff --git a/sqlparser/lib/src/reader/tokenizer/token.dart b/sqlparser/lib/src/reader/tokenizer/token.dart index e7e9f500..368f6adb 100644 --- a/sqlparser/lib/src/reader/tokenizer/token.dart +++ b/sqlparser/lib/src/reader/tokenizer/token.dart @@ -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;