File tree Expand file tree Collapse file tree 2 files changed +13
-9
lines changed Expand file tree Collapse file tree 2 files changed +13
-9
lines changed Original file line number Diff line number Diff line change @@ -24,9 +24,11 @@ export enum MatchResult {
24
24
Ignore ,
25
25
}
26
26
27
+ let _stateId : u32 = 0 ;
28
+
27
29
/* eslint @typescript-eslint/no-empty-function: ["error", { "allow": ["constructors", "methods"] }] */
28
30
export class State {
29
- constructor ( public transitions : State [ ] = [ ] ) { }
31
+ constructor ( public transitions : State [ ] = [ ] , public id : u32 = _stateId ++ ) { }
30
32
31
33
matches ( input : string , position : u32 ) : MatchResult {
32
34
return MatchResult . Ignore ;
@@ -40,7 +42,7 @@ export class GroupStartMarkerState extends State {
40
42
// captures from the path through the NFA that reaches the end are flagged
41
43
flagged : bool = false ;
42
44
43
- constructor ( next : State , public id : i32 ) {
45
+ constructor ( next : State , public groupId : i32 ) {
44
46
super ( ) ;
45
47
this . transitions . push ( next ) ;
46
48
}
Original file line number Diff line number Diff line change @@ -9,14 +9,16 @@ import { walker as astWalker, expandRepetitions } from "./parser/walker";
9
9
function recursiveBacktrackingSearch (
10
10
state : State ,
11
11
input : string ,
12
- visited : State [ ] = [ ] ,
12
+ visited : u32 [ ] = [ ] ,
13
13
position : i32 = 0
14
14
) : string | null {
15
15
// prevent endless loops when following epsilon transitions
16
- if ( visited . includes ( state ) ) {
17
- return null ;
16
+ for ( let i = 0 , len = visited . length ; i < len ; i ++ ) {
17
+ if ( visited [ i ] == state . id ) {
18
+ return null ;
19
+ }
18
20
}
19
- visited . push ( state ) ;
21
+ visited . push ( state . id ) ;
20
22
21
23
const matches = state . matches ( input , position ) ;
22
24
if ( matches == MatchResult . Match ) {
@@ -92,11 +94,11 @@ function filterCaptures(groupMarkers: GroupStartMarkerState[]): string[] {
92
94
return [ ] ;
93
95
}
94
96
const values = [ first ( groupMarkers ) . capture ] ;
95
- let currrentId = first ( groupMarkers ) . id ;
97
+ let currrentId = first ( groupMarkers ) . groupId ;
96
98
for ( let i = 0 ; i < groupMarkers . length ; i ++ ) {
97
99
const gm = groupMarkers [ i ] ;
98
- if ( gm . id != currrentId ) {
99
- currrentId = gm . id ;
100
+ if ( gm . groupId != currrentId ) {
101
+ currrentId = gm . groupId ;
100
102
values . push ( gm . capture ) ;
101
103
} else {
102
104
if ( gm . flagged ) {
You can’t perform that action at this time.
0 commit comments