Skip to content

Commit 8e45068

Browse files
committed
Merge branch 'master' of https://github.com/martin-pabst/SQL-IDE
2 parents a209523 + 059683a commit 8e45068

File tree

2 files changed

+69
-4
lines changed

2 files changed

+69
-4
lines changed

src/client/compiler/parser/Parser.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1355,13 +1355,13 @@ export class Parser {
13551355
let type: SQLBaseType;
13561356

13571357
if (this.cct.tt == TokenType.keywordEnum) {
1358+
this.nextToken();
13581359

13591360
if(this.expect(TokenType.leftBracket, true)){
1360-
this.nextToken();
13611361

13621362
let constants: ConstantNode[] = [];
13631363
//@ts-ignore
1364-
while(this.cct.tt != TokenType.rightBracket && !this.isEnd()){
1364+
while(!this.comesToken(TokenType.rightBracket, true) && !this.isEnd()){
13651365

13661366
let constant = this.parseConstant();
13671367
if(constant != null) constants.push(constant);

src/client/compiler/parser/SQLTypes.ts

Lines changed: 67 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { TokenType } from "../lexer/Token.js";
22

3-
type CheckFunction = (columnIdentifier: string, parameterValues: number[]) => string;
4-
type OutputFunction = (value: any, parameterValues: number[]) => string;
3+
type CheckFunction = (columnIdentifier: string, parameterValues: any[]) => string;
4+
type OutputFunction = (value: any, parameterValues: any[]) => string;
55

66
export abstract class SQLType {
77

@@ -173,6 +173,71 @@ export class SQLBaseType extends SQLType {
173173

174174
}
175175

176+
class SQLNumberEnumType extends SQLBaseType {
177+
178+
constructor(public values: string[]){
179+
super("enum", [],
180+
(ci, pv) => `check(${ci} in (${(<string[]>pv).join(', ')}))`,
181+
(v: string, pv) => v,
182+
["decimal", "integer", "double", "float"]
183+
)
184+
}
185+
186+
getBinaryResultType(operator: TokenType, secondType: SQLType): SQLType {
187+
return operator == TokenType.concatenation ? SQLBaseType.getBaseType('double') : null;
188+
}
189+
190+
getUnaryResultType(operator: TokenType): SQLType {
191+
return null;
192+
}
193+
194+
getBinaryResult(operator: TokenType, value1: any, value2: any) {
195+
return value1 + value2;
196+
}
197+
198+
toString(): string {
199+
return "double";
200+
}
201+
202+
getBaseTypeName(): string {
203+
return "enum";
204+
}
205+
206+
}
207+
208+
209+
class SQLTextEnumType extends SQLBaseType {
210+
211+
constructor(public values: string[]){
212+
super("enum", [],
213+
(ci, pv) => `check(${ci} in (${(<string[]>pv).map(v => '"' + v + '"').join(', ')}))`,
214+
(v: string, pv) => v,
215+
["text", "varchar", "char"]
216+
)
217+
}
218+
219+
getBinaryResultType(operator: TokenType, secondType: SQLType): SQLType {
220+
return operator == TokenType.concatenation ? SQLBaseType.getBaseType('text') : null;
221+
}
222+
223+
getUnaryResultType(operator: TokenType): SQLType {
224+
return null;
225+
}
226+
227+
getBinaryResult(operator: TokenType, value1: any, value2: any) {
228+
return value1 + value2;
229+
}
230+
231+
toString(): string {
232+
return "text";
233+
}
234+
235+
getBaseTypeName(): string {
236+
return "enum";
237+
}
238+
239+
}
240+
176241
let tens: number[] = [1, 10, 100, 1000, 100000, 100000, 1000000, 10000000, 100000000, 1000000000];
177242

178243
export class SQLDerivedType extends SQLType {

0 commit comments

Comments
 (0)