diff --git a/src/lexer/statements/select.ts b/src/lexer/statements/select.ts index 405c8250..15686707 100644 --- a/src/lexer/statements/select.ts +++ b/src/lexer/statements/select.ts @@ -1,7 +1,7 @@ import { Query } from "../../reader/query"; import { ILexer } from "../interface"; import { cleanUnquotedIdentifier } from "../lexer"; -import { TOKENS, Types } from "../tokens"; +import { Types } from "../tokens"; import { Keyword } from "../keywords"; import { Token } from "../token"; @@ -9,12 +9,14 @@ class Select implements ILexer { public options: string[] = []; public tokenise(query: Query): Query { + + const keywords = Object.keys(Keyword).map(keyword => keyword.toLowerCase()); let lastToken = ""; query.lines.forEach(line => { line.content.split(" ").forEach(word => { let item = word.toLowerCase(); - if (TOKENS.keyword.includes(item)) { + if (keywords.includes(item)) { line.tokens.push(new Token(Types.Keyword, item)); } else if (lastToken === Keyword.Select || lastToken === Keyword.From) { item = cleanUnquotedIdentifier(item); diff --git a/src/lexer/tokens.ts b/src/lexer/tokens.ts index 86728683..951b1a00 100644 --- a/src/lexer/tokens.ts +++ b/src/lexer/tokens.ts @@ -1,25 +1,3 @@ -export const TOKENS = { - keyword: [ - "select", - "delete", - "update", - "from", - "where", - "set", - "join", - "having", - "limit", - "else", - "if", - "begin" - ], - - comment: ["#", "--"], - boolean: ["true", "false", "null"], - conditional: ["and", "or"], - operator: ["+", "-", "/"] -}; - export enum Types { Keyword = "keyword", TableReference = "table_reference",