|
1 |
| -import { State, Automata, toNFAFromAST, GroupEndMarkerState, MatcherState } from "./nfa/nfa"; |
| 1 | +import { |
| 2 | + State, |
| 3 | + Automata, |
| 4 | + toNFAFromAST, |
| 5 | + GroupEndMarkerState, |
| 6 | + MatcherState, |
| 7 | +} from "./nfa/nfa"; |
2 | 8 | import { walker as nfaWalker } from "./nfa/walker";
|
3 | 9 | import { ConcatenationNode, AssertionNode } from "./parser/node";
|
4 | 10 | import { Char } from "./char";
|
@@ -147,32 +153,31 @@ export class RegExp {
|
147 | 153 | // the ctr via the loader?
|
148 | 154 | export function createRegExp(regex: string, flags: string): RegExp {
|
149 | 155 |
|
| 156 | + /* ---------------- */ |
| 157 | + /* |
| 158 | + This block of code is needed to avoid the following runtime error ... |
| 159 | +
|
| 160 | + RuntimeError: unreachable |
| 161 | + at assembly/nfa/matcher/Matcher#matches@virtual (wasm-function[240]:1) |
| 162 | + at assembly/nfa/matcher/CharacterSetMatcher#matches~anonymous|0 (wasm-function[241]:19) |
| 163 | + at ~lib/array/Array<assembly/nfa/matcher/Matcher>#some (wasm-function[242]:85) |
| 164 | + at assembly/nfa/matcher/CharacterSetMatcher#matches (wasm-function[244]:21) |
| 165 | + at assembly/nfa/nfa/MatcherState<assembly/nfa/matcher/CharacterSetMatcher>#matches (wasm-function[245]:8) |
| 166 | + at assembly/nfa/nfa/State#matches@virtual (wasm-function[250]:58) |
| 167 | + at assembly/regexp/recursiveBacktrackingSearch (wasm-function[184]:121) |
| 168 | + at assembly/regexp/recursiveBacktrackingSearch@varargs (wasm-function[185]:56) |
| 169 | + at assembly/regexp/RegExp#exec (wasm-function[192]:307) |
| 170 | + */ |
150 | 171 | const matchers = new Array<Matcher>();
|
151 | 172 | matchers.push(new CharacterMatcher(Char.A));
|
152 | 173 | const charMatcher = new CharacterSetMatcher(matchers, false);
|
153 |
| - |
154 |
| - const state = new MatcherState<CharacterSetMatcher>(charMatcher, new State(true)); |
155 |
| - |
| 174 | + const state = new MatcherState<CharacterSetMatcher>( |
| 175 | + charMatcher, |
| 176 | + new State(true) |
| 177 | + ); |
156 | 178 | const char = "a".charCodeAt(0);
|
157 | 179 | const doesMatch = state.matches(char) != null;
|
158 |
| - |
| 180 | + /* ---------------- */ |
159 | 181 |
|
160 | 182 | return new RegExp(regex, flags);
|
161 | 183 | }
|
162 |
| - |
163 |
| - |
164 |
| -export function tryMatch(value: string): bool { |
165 |
| - const matchers = new Array<Matcher>(); |
166 |
| - matchers.push(new CharacterMatcher(Char.A)); |
167 |
| - const charMatcher = new CharacterSetMatcher(matchers, false); |
168 |
| - |
169 |
| - const state = new MatcherState<CharacterSetMatcher>(charMatcher, new State(true)); |
170 |
| - |
171 |
| - const char = value.charCodeAt(0); |
172 |
| - const doesMatch = state.matches(char) != null; |
173 |
| - |
174 |
| - |
175 |
| - const regex = new RegExp("[A-Z]"); |
176 |
| - return regex.exec(value) != null; |
177 |
| -} |
178 |
| - |
|
0 commit comments