Explorar el Código

Disallow numbers as from targets

master
Dylan Baker hace 4 años
padre
commit
1bb4549390
Se han modificado 2 ficheros con 13 adiciones y 6 borrados
  1. 8
    6
      src/parser.ts
  2. 5
    0
      test/parser.test.ts

+ 8
- 6
src/parser.ts Ver fichero

44
       return args;
44
       return args;
45
     }
45
     }
46
 
46
 
47
-    const from =
48
-      this.currentToken().kind === TokenKind.FROM ? this.from() : null;
47
+    const currentToken = this.currentToken();
48
+    const from = currentToken.kind === TokenKind.FROM ? this.from() : null;
49
     if (isError(from)) {
49
     if (isError(from)) {
50
       return from;
50
       return from;
51
     }
51
     }
78
 
78
 
79
   private from(): AST.Secondary | Error {
79
   private from(): AST.Secondary | Error {
80
     this.eat(TokenKind.FROM);
80
     this.eat(TokenKind.FROM);
81
-    return this.alias();
81
+    return this.alias(this.identifier);
82
   }
82
   }
83
 
83
 
84
-  private alias(): AST.Secondary | Error {
85
-    const primary = this.primary();
84
+  private alias(fn: () => AST.Primary | Error = this.primary): AST.Secondary | Error {
85
+    const primary = fn.bind(this)();
86
     if (isError(primary)) {
86
     if (isError(primary)) {
87
       return primary;
87
       return primary;
88
     }
88
     }
137
       return token;
137
       return token;
138
     }
138
     }
139
 
139
 
140
-    return new Error(`Unexpected token ${token}`, token.line);
140
+    const repr = `{ kind: ${token.kind}${token.value ? `, value: ${token.value} }` : ""}`;
141
+
142
+    return new Error(`Unexpected token: ${repr}`, token.line);
141
   }
143
   }
142
 
144
 
143
   private currentToken(): Token {
145
   private currentToken(): Token {

+ 5
- 0
test/parser.test.ts Ver fichero

86
       }),
86
       }),
87
     ]);
87
     ]);
88
   });
88
   });
89
+
90
+  it("should not allow a number as a from target", () => {
91
+    const fn = () => parse("select 1 from 2");
92
+    expect(fn).to.throw("Unexpected token: { kind: NUMBER, value: 2 }");
93
+  });
89
 });
94
 });

Loading…
Cancelar
Guardar