@@ -28,24 +28,6 @@ import {
28
28
} from "./parsing" ;
29
29
import { ASTParser } from "./ast-parser" ;
30
30
31
- let now : ( ) => number ;
32
- try {
33
- // Web
34
- performance . now ( ) ;
35
- now = ( ) => performance . now ( ) ;
36
- } catch ( e ) {
37
- try {
38
- // Node.js
39
- if ( global ) {
40
- const { performance } = global [ 'require' ] ( 'perf_hooks' ) ;
41
- now = ( ) => performance . now ( ) ;
42
- }
43
- } catch ( e ) {
44
- // Fallback
45
- now = ( ) => new Date ( ) . getTime ( ) ;
46
- }
47
- }
48
-
49
31
export abstract class TokenFactory < T extends TylasuToken > {
50
32
// eslint-disable-next-line @typescript-eslint/no-unused-vars
51
33
categoryOf ( t : Token ) : TokenCategory {
@@ -101,7 +83,7 @@ export abstract class TylasuANTLRLexer<T extends TylasuToken> implements TylasuL
101
83
lex ( inputStream : CharStream , onlyFromDefaultChannel = true ) : LexingResult < T > {
102
84
const issues : Issue [ ] = [ ] ;
103
85
const tokens : T [ ] = [ ] ;
104
- const time = now ( ) ;
86
+ const time = performance . now ( ) ;
105
87
const lexer = this . createANTLRLexer ( inputStream ) ! ;
106
88
this . injectErrorCollectorInLexer ( lexer , issues ) ;
107
89
let t : Token ;
@@ -122,7 +104,7 @@ export abstract class TylasuANTLRLexer<T extends TylasuToken> implements TylasuL
122
104
}
123
105
124
106
const code = inputStream . getText ( Interval . of ( 0 , inputStream . size - 1 ) ) ;
125
- return new LexingResult ( code , tokens , issues , now ( ) - time ) ;
107
+ return new LexingResult ( code , tokens , issues , performance . now ( ) - time ) ;
126
108
}
127
109
128
110
protected injectErrorCollectorInLexer ( lexer : Lexer , issues : Issue [ ] ) : void {
@@ -220,23 +202,23 @@ export abstract class TylasuParser<
220
202
parseFirstStage ( inputStream : CharStream , measureLexingTime = false ) : FirstStageParsingResult < C > {
221
203
const issues : Issue [ ] = [ ] ;
222
204
let lexingTime : number | undefined = undefined ;
223
- const time = now ( ) ;
205
+ const time = performance . now ( ) ;
224
206
const parser = this . createParser ( inputStream , issues ) ;
225
207
if ( measureLexingTime ) {
226
208
const tokenStream = parser . inputStream ;
227
209
if ( tokenStream instanceof CommonTokenStream ) {
228
- lexingTime = now ( ) ;
210
+ lexingTime = performance . now ( ) ;
229
211
tokenStream . fill ( ) ;
230
212
tokenStream . seek ( 0 ) ;
231
- lexingTime = lexingTime - now ( ) ;
213
+ lexingTime = lexingTime - performance . now ( ) ;
232
214
}
233
215
}
234
216
const root = this . invokeRootRule ( parser ) ;
235
217
if ( root != null ) {
236
218
this . verifyParseTree ( parser , issues , root ) ;
237
219
}
238
220
const code = inputStream . getText ( Interval . of ( 0 , inputStream . size - 1 ) ) ;
239
- return new FirstStageParsingResult ( code , root , issues , parser , now ( ) - time , lexingTime ) ;
221
+ return new FirstStageParsingResult ( code , root , issues , parser , performance . now ( ) - time , lexingTime ) ;
240
222
}
241
223
242
224
// eslint-disable-next-line @typescript-eslint/no-unused-vars
@@ -254,7 +236,7 @@ export abstract class TylasuParser<
254
236
}
255
237
code = new CharStream ( code ) ;
256
238
}
257
- const start = now ( )
239
+ const start = performance . now ( ) ;
258
240
const firstStage = this . parseFirstStage ( code , measureLexingTime ) ;
259
241
const issues = firstStage . issues ;
260
242
let ast = this . parseTreeToAst ( firstStage . root ! , considerPosition , issues , source ) ;
@@ -270,7 +252,7 @@ export abstract class TylasuParser<
270
252
}
271
253
}
272
254
const text = code . getText ( Interval . of ( 0 , code . size - 1 ) ) ;
273
- return new ParsingResult ( text , ast , issues , undefined , firstStage , now ( ) - start ) ;
255
+ return new ParsingResult ( text , ast , issues , undefined , firstStage , performance . now ( ) - start ) ;
274
256
}
275
257
276
258
/**
@@ -302,8 +284,8 @@ export abstract class TylasuParser<
302
284
303
285
function processDescendantsAndErrors (
304
286
self : ParserRuleContext ,
305
- operationOnParserRuleContext : ( ParserRuleContext ) => void ,
306
- operationOnError : ( ErrorNode ) => void ,
287
+ operationOnParserRuleContext : ( c : ParserRuleContext ) => void ,
288
+ operationOnError : ( e : ErrorNode ) => void ,
307
289
includingMe = true
308
290
) {
309
291
if ( includingMe ) {
0 commit comments