All files / src/lexer/statements select.ts

100% Statements 16/16
87.5% Branches 7/8
100% Functions 3/3
100% Lines 16/16
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36    15x 15x       10x 10x 10x 53x   53x 23x 30x 17x   17x 17x           13x   53x       10x       15x  
import { Query } from "../../reader/query";
import { ILexer } from "../interface";
import { cleanUnquotedIdentifier } from "../lexer";
import { TOKENS, Keyword, Types } from "../tokens";
 
class Select implements ILexer {
  public tokenise(query: Query): Query {
    let lastToken = "";
    query.lines.forEach(line => {
      line.content.split(" ").forEach(word => {
        let item = word.toLowerCase();
 
        if (TOKENS.keyword.includes(item)) {
          line.tokens.push([Types.Keyword, item]);
        } else if (lastToken === Keyword.Select || lastToken === Keyword.From) {
          item = cleanUnquotedIdentifier(item);
 
          Eif (item.length > 0) {
            line.tokens.push([
              Types.TableReference,
              cleanUnquotedIdentifier(item)
            ]);
          }
        } else {
          line.tokens.push([Types.Unidentified, item]);
        }
        lastToken = item;
      });
    });
 
    return query;
  }
}
 
export { Select };