Skip to content

Commit 059683a

Browse files
committed
work on enums continued...
1 parent 235eee4 commit 059683a

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

@@ -167,6 +167,71 @@ export class SQLBaseType extends SQLType {
167167

168168
}
169169

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

172237
export class SQLDerivedType extends SQLType {

0 commit comments

Comments
 (0)