Skip to content

Commit

Permalink
Remove TOKENS constant and replace with Keywords
Browse files Browse the repository at this point in the history
  • Loading branch information
Joe Reynolds committed May 8, 2019
1 parent 9c86d22 commit 0d63649
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 24 deletions.
6 changes: 4 additions & 2 deletions src/lexer/statements/select.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
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";

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);
Expand Down
22 changes: 0 additions & 22 deletions src/lexer/tokens.ts
Original file line number Diff line number Diff line change
@@ -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",
Expand Down

0 comments on commit 0d63649

Please sign in to comment.