Skip to content

Commit 8a63197

Browse files
committed
fix: export RegExpVistor at runtime.
Also changed the built in visitor methods signature to `protected` to enable customizing sub-visitor flows by overriding. fixes mysticatea#12
1 parent 20e0388 commit 8a63197

File tree

2 files changed

+14
-14
lines changed

2 files changed

+14
-14
lines changed

src/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { RegExpParser } from "./parser"
33
import { RegExpValidator } from "./validator"
44
import { RegExpVisitor } from "./visitor"
55

6-
export { AST, RegExpParser, RegExpValidator }
6+
export { AST, RegExpParser, RegExpValidator, RegExpVisitor }
77

88
/**
99
* Parse a given regular expression literal then make AST object.

src/visitor.ts

+13-13
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ export class RegExpVisitor {
7979
}
8080
}
8181

82-
private visitAlternative(node: Alternative): void {
82+
protected visitAlternative(node: Alternative): void {
8383
if (this._handlers.onAlternativeEnter) {
8484
this._handlers.onAlternativeEnter(node)
8585
}
@@ -88,7 +88,7 @@ export class RegExpVisitor {
8888
this._handlers.onAlternativeLeave(node)
8989
}
9090
}
91-
private visitAssertion(node: Assertion): void {
91+
protected visitAssertion(node: Assertion): void {
9292
if (this._handlers.onAssertionEnter) {
9393
this._handlers.onAssertionEnter(node)
9494
}
@@ -99,15 +99,15 @@ export class RegExpVisitor {
9999
this._handlers.onAssertionLeave(node)
100100
}
101101
}
102-
private visitBackreference(node: Backreference): void {
102+
protected visitBackreference(node: Backreference): void {
103103
if (this._handlers.onBackreferenceEnter) {
104104
this._handlers.onBackreferenceEnter(node)
105105
}
106106
if (this._handlers.onBackreferenceLeave) {
107107
this._handlers.onBackreferenceLeave(node)
108108
}
109109
}
110-
private visitCapturingGroup(node: CapturingGroup): void {
110+
protected visitCapturingGroup(node: CapturingGroup): void {
111111
if (this._handlers.onCapturingGroupEnter) {
112112
this._handlers.onCapturingGroupEnter(node)
113113
}
@@ -116,15 +116,15 @@ export class RegExpVisitor {
116116
this._handlers.onCapturingGroupLeave(node)
117117
}
118118
}
119-
private visitCharacter(node: Character): void {
119+
protected visitCharacter(node: Character): void {
120120
if (this._handlers.onCharacterEnter) {
121121
this._handlers.onCharacterEnter(node)
122122
}
123123
if (this._handlers.onCharacterLeave) {
124124
this._handlers.onCharacterLeave(node)
125125
}
126126
}
127-
private visitCharacterClass(node: CharacterClass): void {
127+
protected visitCharacterClass(node: CharacterClass): void {
128128
if (this._handlers.onCharacterClassEnter) {
129129
this._handlers.onCharacterClassEnter(node)
130130
}
@@ -133,7 +133,7 @@ export class RegExpVisitor {
133133
this._handlers.onCharacterClassLeave(node)
134134
}
135135
}
136-
private visitCharacterClassRange(node: CharacterClassRange): void {
136+
protected visitCharacterClassRange(node: CharacterClassRange): void {
137137
if (this._handlers.onCharacterClassRangeEnter) {
138138
this._handlers.onCharacterClassRangeEnter(node)
139139
}
@@ -143,23 +143,23 @@ export class RegExpVisitor {
143143
this._handlers.onCharacterClassRangeLeave(node)
144144
}
145145
}
146-
private visitCharacterSet(node: CharacterSet): void {
146+
protected visitCharacterSet(node: CharacterSet): void {
147147
if (this._handlers.onCharacterSetEnter) {
148148
this._handlers.onCharacterSetEnter(node)
149149
}
150150
if (this._handlers.onCharacterSetLeave) {
151151
this._handlers.onCharacterSetLeave(node)
152152
}
153153
}
154-
private visitFlags(node: Flags): void {
154+
protected visitFlags(node: Flags): void {
155155
if (this._handlers.onFlagsEnter) {
156156
this._handlers.onFlagsEnter(node)
157157
}
158158
if (this._handlers.onFlagsLeave) {
159159
this._handlers.onFlagsLeave(node)
160160
}
161161
}
162-
private visitGroup(node: Group): void {
162+
protected visitGroup(node: Group): void {
163163
if (this._handlers.onGroupEnter) {
164164
this._handlers.onGroupEnter(node)
165165
}
@@ -168,7 +168,7 @@ export class RegExpVisitor {
168168
this._handlers.onGroupLeave(node)
169169
}
170170
}
171-
private visitPattern(node: Pattern): void {
171+
protected visitPattern(node: Pattern): void {
172172
if (this._handlers.onPatternEnter) {
173173
this._handlers.onPatternEnter(node)
174174
}
@@ -177,7 +177,7 @@ export class RegExpVisitor {
177177
this._handlers.onPatternLeave(node)
178178
}
179179
}
180-
private visitQuantifier(node: Quantifier): void {
180+
protected visitQuantifier(node: Quantifier): void {
181181
if (this._handlers.onQuantifierEnter) {
182182
this._handlers.onQuantifierEnter(node)
183183
}
@@ -186,7 +186,7 @@ export class RegExpVisitor {
186186
this._handlers.onQuantifierLeave(node)
187187
}
188188
}
189-
private visitRegExpLiteral(node: RegExpLiteral): void {
189+
protected visitRegExpLiteral(node: RegExpLiteral): void {
190190
if (this._handlers.onRegExpLiteralEnter) {
191191
this._handlers.onRegExpLiteralEnter(node)
192192
}

0 commit comments

Comments
 (0)