Skip to content

Commit 0afe911

Browse files
WIP
1 parent 67542bb commit 0afe911

File tree

2 files changed

+28
-23
lines changed

2 files changed

+28
-23
lines changed

assembly/regexp.ts

Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
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";
28
import { walker as nfaWalker } from "./nfa/walker";
39
import { ConcatenationNode, AssertionNode } from "./parser/node";
410
import { Char } from "./char";
@@ -147,32 +153,31 @@ export class RegExp {
147153
// the ctr via the loader?
148154
export function createRegExp(regex: string, flags: string): RegExp {
149155

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+
*/
150171
const matchers = new Array<Matcher>();
151172
matchers.push(new CharacterMatcher(Char.A));
152173
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+
);
156178
const char = "a".charCodeAt(0);
157179
const doesMatch = state.matches(char) != null;
158-
180+
/* ---------------- */
159181

160182
return new RegExp(regex, flags);
161183
}
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-

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"description": "A regex engine built with AssemblyScript",
55
"main": "index.js",
66
"scripts": {
7-
"test": "npm run asbuild:untouched && jest test/index.test.js",
7+
"test": "npm run asbuild:untouched && npm run prettier:check && jest test/index.test.js",
88
"test:suite": "npm run asbuild:untouched && jest test/data.test.js --reporter=jest-summary-reporter",
99
"prettier:check": "prettier --check .",
1010
"prettier:write": "prettier --write .",

0 commit comments

Comments
 (0)