-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStreamParser.ts
45 lines (42 loc) · 1.29 KB
/
StreamParser.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import { Table } from "./DataType";
import { Parser } from "./Parser";
export class StreamParser extends Parser {
public constructor() {
super();
}
public static Parse(code: string): Table {
let callarr = code.split("->");
//初始表
let oldtable: Table = null;
let isx = false;
//前一个表会被附加到后一个表的后面
for (let t of callarr) {
//构造层次计算表
//得到当前表
//处理解耦合语法 *()
let now: Table = null;
let nisx = false;
if (t.trim()[0] == "*") {
now = super.Parse(t.slice(1, t.length));
if (now.Type != "normal") {
throw new Error("解析错误!只能对normal型表执行解耦合操作");
}
nisx = true;
}
else {
now = super.Parse(t);
nisx = false;
}
if (oldtable != null) {
if (!isx)
now.childs.push(oldtable);
else {
now.childs = now.childs.concat(oldtable.childs);
}
}
oldtable = now;
isx = nisx;
}
return oldtable;
}
}