|
1 | | -import { mergeSetInto, eqSet } from '../utils'; |
| 1 | +import { mergeSetInto } from '../utils'; |
| 2 | +import epsilon, { Epsilon } from './epsilon'; |
2 | 3 |
|
3 | | -export class Epsilon {} |
4 | | -export const epsilon = new Epsilon(); |
5 | | - |
6 | | -type InputType = string | Epsilon; |
| 4 | +export type InputType = string | Epsilon; |
7 | 5 |
|
8 | 6 | export class State { |
9 | 7 | public nextStatesMap: Map<InputType, Set<State>>; |
@@ -44,104 +42,3 @@ export class State { |
44 | 42 | return epsilonSet; |
45 | 43 | } |
46 | 44 | } |
47 | | - |
48 | | - |
49 | | -export class StateOp { |
50 | | - protected start: State | null; |
51 | | - protected end: State | null; |
52 | | - constructor() { |
53 | | - this.start = null; |
54 | | - this.end = null; |
55 | | - } |
56 | | - |
57 | | - public getStartState() { |
58 | | - return this.start; |
59 | | - } |
60 | | - |
61 | | - public getEndState() { |
62 | | - return this.end; |
63 | | - } |
64 | | - |
65 | | - public setNext(input: InputType, state: StateOp) { |
66 | | - const start = state.getStartState(); |
67 | | - if (start && this.end) { |
68 | | - this.end.setNext(input, start); |
69 | | - } else if (!start) { |
70 | | - throw new Error('Start state of param state is null'); |
71 | | - } else if (!this.end) { |
72 | | - throw new Error('this.end is null') |
73 | | - } |
74 | | - } |
75 | | - |
76 | | -} |
77 | | - |
78 | | -export class SingleInputState extends StateOp { |
79 | | - constructor(input: InputType, accepted: boolean = false) { |
80 | | - super(); |
81 | | - this.start = new State(); |
82 | | - this.end = new State(accepted); |
83 | | - this.start.setNext(input, this.end); |
84 | | - } |
85 | | -} |
86 | | - |
87 | | - |
88 | | -export class ConcatState extends StateOp { |
89 | | - private a: StateOp; |
90 | | - private b: StateOp; |
91 | | - constructor(a: StateOp, b: StateOp) { |
92 | | - super(); |
93 | | - this.a = a; |
94 | | - this.b = b; |
95 | | - this.start = this.a.getStartState(); |
96 | | - this.a.setNext(epsilon, this.b); |
97 | | - this.end = this.b.getEndState(); |
98 | | - } |
99 | | -} |
100 | | - |
101 | | -export class UnionState extends StateOp { |
102 | | - private a: StateOp; |
103 | | - private b: StateOp; |
104 | | - constructor(a: StateOp, b: StateOp, accepted: boolean = false) { |
105 | | - super(); |
106 | | - this.a = a; |
107 | | - this.b = b; |
108 | | - this.start = new State(); |
109 | | - this.end = new State(accepted); |
110 | | - for (const arg of [this.a, this.b]) { |
111 | | - const argOpStart = arg.getStartState(); |
112 | | - const argOpEnd = arg.getEndState(); |
113 | | - if (argOpStart) { |
114 | | - this.start.setNext(epsilon, argOpStart) |
115 | | - } else { |
116 | | - throw new Error('start of argOp is null'); |
117 | | - } |
118 | | - if (argOpEnd) { |
119 | | - argOpEnd.setNext(epsilon, this.end); |
120 | | - } else { |
121 | | - throw new Error('end of argOp is null') |
122 | | - } |
123 | | - } |
124 | | - } |
125 | | -} |
126 | | - |
127 | | -export class ClosureState extends StateOp { |
128 | | - private a: StateOp; |
129 | | - constructor(a: StateOp, accepted: boolean = false) { |
130 | | - super(); |
131 | | - this.a = a; |
132 | | - this.start = new State(); |
133 | | - this.end = new State(accepted); |
134 | | - const aStart = this.a.getStartState(); |
135 | | - const aEnd = this.a.getEndState(); |
136 | | - if (aStart) { |
137 | | - this.start.setNext(epsilon, aStart); |
138 | | - } else { |
139 | | - throw new Error('start of a is null'); |
140 | | - } |
141 | | - this.start.setNext(epsilon, this.end); |
142 | | - if (aEnd) { |
143 | | - aEnd.setNext(epsilon, this.end); |
144 | | - aEnd.setNext(epsilon, this.start); |
145 | | - } |
146 | | - } |
147 | | -} |
0 commit comments