-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparser.mjs
More file actions
21 lines (20 loc) · 719 Bytes
/
parser.mjs
File metadata and controls
21 lines (20 loc) · 719 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
export class Parser {
constructor() {
this.commands = new Map();
this.commands.set("createTable", /create table ([a-z]+) \((.+)\)/);
this.commands.set("insert", /insert into ([a-z]+) \((.+)\) values \((.+)\)/);
this.commands.set("select", /select (.+) from ([a-z]+)(?: where (.+))?/);
this.commands.set("delete", /delete from ([a-z]+)(?: where (.+))?/);
}
parse(statement) {
for (let [command, regexp] of this.commands) {
const parsedStatement = statement.match(regexp);
if (parsedStatement) {
return {
command,
parsedStatement
}
}
}
}
};