Dylan Baker 6 лет назад
Родитель
Сommit
b2fe682f92
3 измененных файлов: 14 добавлений и 2 удалений
  1. 6
    0
      src/lexer.ts
  2. 2
    0
      src/token.ts
  3. 6
    2
      test/lexer.test.ts

+ 6
- 0
src/lexer.ts Просмотреть файл

43
     } else if (source.match(/^as/i)) {
43
     } else if (source.match(/^as/i)) {
44
       this.advance(2);
44
       this.advance(2);
45
       return new Token(TokenKind.AS, null, this.line);
45
       return new Token(TokenKind.AS, null, this.line);
46
+    } else if (source.match(/^and/i)) {
47
+      this.advance(3);
48
+      return new Token(TokenKind.AND, null, this.line);
49
+    } else if (source.match(/^or/i)) {
50
+      this.advance(2);
51
+      return new Token(TokenKind.OR, null, this.line);
46
     } else if (source.match(/^\+/)) {
52
     } else if (source.match(/^\+/)) {
47
       this.advance();
53
       this.advance();
48
       return new Token(TokenKind.PLUS, null, this.line);
54
       return new Token(TokenKind.PLUS, null, this.line);

+ 2
- 0
src/token.ts Просмотреть файл

1
 export enum TokenKind {
1
 export enum TokenKind {
2
+  AND = "AND",
2
   AS = "AS",
3
   AS = "AS",
3
   BACKTICK = "BACKTICK",
4
   BACKTICK = "BACKTICK",
4
   COMMA = "COMMA",
5
   COMMA = "COMMA",
9
   IDENTIFIER = "IDENTIFIER",
10
   IDENTIFIER = "IDENTIFIER",
10
   MINUS = "MINUS",
11
   MINUS = "MINUS",
11
   NUMBER = "NUMBER",
12
   NUMBER = "NUMBER",
13
+  OR = "OR",
12
   PLUS = "PLUS",
14
   PLUS = "PLUS",
13
   SELECT = "SELECT",
15
   SELECT = "SELECT",
14
   SEMICOLON = "SEMICOLON",
16
   SEMICOLON = "SEMICOLON",

+ 6
- 2
test/lexer.test.ts Просмотреть файл

11
 
11
 
12
 describe("Lexer", () => {
12
 describe("Lexer", () => {
13
   it("scans uppercase keywords", () => {
13
   it("scans uppercase keywords", () => {
14
-    const tokens = scan("SELECT FROM WHERE AS");
14
+    const tokens = scan("SELECT FROM WHERE AS AND OR");
15
     expect(tokens).to.deep.equal([
15
     expect(tokens).to.deep.equal([
16
       new Token(TokenKind.SELECT, null, 1),
16
       new Token(TokenKind.SELECT, null, 1),
17
       new Token(TokenKind.FROM, null, 1),
17
       new Token(TokenKind.FROM, null, 1),
18
       new Token(TokenKind.WHERE, null, 1),
18
       new Token(TokenKind.WHERE, null, 1),
19
       new Token(TokenKind.AS, null, 1),
19
       new Token(TokenKind.AS, null, 1),
20
+      new Token(TokenKind.AND, null, 1),
21
+      new Token(TokenKind.OR, null, 1),
20
       new Token(TokenKind.EOF, null, 1),
22
       new Token(TokenKind.EOF, null, 1),
21
     ]);
23
     ]);
22
   });
24
   });
23
 
25
 
24
   it("scans lowercase keywords", () => {
26
   it("scans lowercase keywords", () => {
25
-    const tokens = scan("select from where as");
27
+    const tokens = scan("select from where as and or");
26
     expect(tokens).to.deep.equal([
28
     expect(tokens).to.deep.equal([
27
       new Token(TokenKind.SELECT, null, 1),
29
       new Token(TokenKind.SELECT, null, 1),
28
       new Token(TokenKind.FROM, null, 1),
30
       new Token(TokenKind.FROM, null, 1),
29
       new Token(TokenKind.WHERE, null, 1),
31
       new Token(TokenKind.WHERE, null, 1),
30
       new Token(TokenKind.AS, null, 1),
32
       new Token(TokenKind.AS, null, 1),
33
+      new Token(TokenKind.AND, null, 1),
34
+      new Token(TokenKind.OR, null, 1),
31
       new Token(TokenKind.EOF, null, 1),
35
       new Token(TokenKind.EOF, null, 1),
32
     ]);
36
     ]);
33
   });
37
   });

Загрузка…
Отмена
Сохранить