Skip to content

Commit cdd7501

Browse files
committed
refactor(pattern): drop unused functions
These functions were previously used in the now-removed NFA matcher. There is no breaking change as these functions were internal and are not exported from the library entrypoint.
1 parent 9430168 commit cdd7501

File tree

4 files changed

+2
-243
lines changed

4 files changed

+2
-243
lines changed

src/pattern/Simplifier.ts

Lines changed: 0 additions & 60 deletions
This file was deleted.

src/pattern/Util.ts

Lines changed: 1 addition & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
import type { LiteralNode, Node, ParsedPattern } from './Nodes';
1+
import type { Node, ParsedPattern } from './Nodes';
22
import { SyntaxKind } from './Nodes';
3-
import type { SimpleNode } from './Simplifier';
43

54
export function potentiallyMatchesEmptyString(pattern: ParsedPattern) {
65
return pattern.nodes.every((node) => node.kind === SyntaxKind.Optional);
@@ -36,38 +35,3 @@ export function getRegExpStringForNode(node: Node): string {
3635
return `.`;
3736
}
3837
}
39-
40-
export function computePatternMatchLength(nodes: SimpleNode[]) {
41-
return nodes.reduce((total, node) => total + (node.kind === SyntaxKind.Wildcard ? 1 : node.chars.length), 0);
42-
}
43-
44-
export function groupByNodeType(nodes: SimpleNode[]) {
45-
let i = 0;
46-
const groups: NodeGroup[] = [];
47-
while (i < nodes.length) {
48-
const node = nodes[i];
49-
if (node.kind === SyntaxKind.Literal) {
50-
const literals: LiteralNode[] = [];
51-
while (i < nodes.length && nodes[i].kind === SyntaxKind.Literal) literals.push(nodes[i++] as LiteralNode);
52-
groups.push({ literals, isLiteralGroup: true });
53-
} else {
54-
const mark = i;
55-
while (i < nodes.length && nodes[i].kind === SyntaxKind.Wildcard) i++;
56-
groups.push({ wildcardCount: i - mark, isLiteralGroup: false });
57-
}
58-
}
59-
60-
return groups;
61-
}
62-
63-
export type NodeGroup = LiteralGroup | WildcardGroup;
64-
65-
export interface LiteralGroup {
66-
isLiteralGroup: true;
67-
literals: LiteralNode[];
68-
}
69-
70-
export interface WildcardGroup {
71-
isLiteralGroup: false;
72-
wildcardCount: number;
73-
}

test/pattern/Simplifier.test.ts

Lines changed: 0 additions & 78 deletions
This file was deleted.

test/pattern/Util.test.ts

Lines changed: 1 addition & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,6 @@
11
import type { LiteralNode, OptionalNode } from '../../src/pattern/Nodes';
22
import { SyntaxKind } from '../../src/pattern/Nodes';
3-
import type { SimpleNode } from '../../src/pattern/Simplifier';
4-
import {
5-
compilePatternToRegExp,
6-
computePatternMatchLength,
7-
getRegExpStringForNode,
8-
groupByNodeType,
9-
potentiallyMatchesEmptyString,
10-
} from '../../src/pattern/Util';
3+
import { compilePatternToRegExp, getRegExpStringForNode, potentiallyMatchesEmptyString } from '../../src/pattern/Util';
114
import { CharacterIterator } from '../../src/util/CharacterIterator';
125

136
function toLiteralNode(str: string): LiteralNode {
@@ -123,63 +116,3 @@ describe('getRegExpStringForNode()', () => {
123116
});
124117
});
125118
});
126-
127-
describe('computePatternMatchLength()', () => {
128-
it('should return 0 if given an empty array', () => {
129-
expect(computePatternMatchLength([])).toBe(0);
130-
});
131-
132-
it('should return the total number of chars in literal nodes plus 1 for each wildcard node', () => {
133-
const nodes: SimpleNode[] = [
134-
{ kind: SyntaxKind.Literal, chars: [0, 0] },
135-
{ kind: SyntaxKind.Wildcard },
136-
{ kind: SyntaxKind.Literal, chars: [0, 0, 0] },
137-
];
138-
expect(computePatternMatchLength(nodes)).toBe(6);
139-
});
140-
});
141-
142-
describe('groupByNodeType()', () => {
143-
it('should return an empty array if nodes=[]', () => {
144-
expect(groupByNodeType([])).toStrictEqual([]);
145-
});
146-
147-
it('should return one literal group if there are only literal nodes in the input', () => {
148-
const nodes: SimpleNode[] = [
149-
{ kind: SyntaxKind.Literal, chars: [1, 2, 3] },
150-
{ kind: SyntaxKind.Literal, chars: [2, 3, 4] },
151-
];
152-
expect(groupByNodeType(nodes)).toStrictEqual([{ isLiteralGroup: true, literals: nodes }]);
153-
});
154-
155-
it('should return one wildcard group if there are only wildcards in the input', () => {
156-
const nodes: SimpleNode[] = [
157-
{ kind: SyntaxKind.Wildcard },
158-
{ kind: SyntaxKind.Wildcard },
159-
{ kind: SyntaxKind.Wildcard },
160-
];
161-
expect(groupByNodeType(nodes)).toStrictEqual([{ isLiteralGroup: false, wildcardCount: 3 }]);
162-
});
163-
164-
it('should group literals and wildcards together', () => {
165-
const literal0: LiteralNode = { kind: SyntaxKind.Literal, chars: [1, 2, 3] };
166-
const literal1: LiteralNode = { kind: SyntaxKind.Literal, chars: [2, 3, 4] };
167-
const literal2: LiteralNode = { kind: SyntaxKind.Literal, chars: [3, 4, 5] };
168-
const nodes: SimpleNode[] = [
169-
{ kind: SyntaxKind.Wildcard },
170-
literal0,
171-
literal1,
172-
{ kind: SyntaxKind.Wildcard },
173-
literal2,
174-
{ kind: SyntaxKind.Wildcard },
175-
{ kind: SyntaxKind.Wildcard },
176-
];
177-
expect(groupByNodeType(nodes)).toStrictEqual([
178-
{ isLiteralGroup: false, wildcardCount: 1 },
179-
{ isLiteralGroup: true, literals: [literal0, literal1] },
180-
{ isLiteralGroup: false, wildcardCount: 1 },
181-
{ isLiteralGroup: true, literals: [literal2] },
182-
{ isLiteralGroup: false, wildcardCount: 2 },
183-
]);
184-
});
185-
});

0 commit comments

Comments
 (0)