Skip to content

Commit

Permalink
fix: walker was visiting states multiple times
Browse files Browse the repository at this point in the history
  • Loading branch information
ColinEberhardt committed Feb 7, 2021
1 parent c42d678 commit 4872cf6
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
6 changes: 6 additions & 0 deletions assembly/__tests__/capture-group.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,9 @@ it("should not return captured values for non-matching alternations", () => {
expect(match.matches[1]).toBe("");
expect(match.matches[2]).toBe("b");
});

it("repeated capture groups should return the last match", () => {
const match = exec("([a-c])+", "ac");
expect(match.matches[0]).toBe("ac");
expect(match.matches[1]).toBe("c");
});
2 changes: 1 addition & 1 deletion assembly/nfa/walker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ export function walker(
visitor: (state: State) => void,
visited: State[] = []
): void {
visitor(state);
if (visited.includes(state)) return;
visitor(state);
visited.push(state);
const nextStates = state.transitions;
for (let i = 0, len = nextStates.length; i < len; i++) {
Expand Down

0 comments on commit 4872cf6

Please sign in to comment.