22 * Copyright (C) Microsoft Corporation. All rights reserved.
33 *-------------------------------------------------------- */
44
5- import { ShikiError } from '../error'
6- import type { IOnigBinding , IOnigCaptureIndex , IOnigMatch , OnigScanner as IOnigScanner , OnigString as IOnigString , Pointer } from './types'
5+ import { ShikiError } from '../../error'
6+ import type { LoadWasmOptions , WebAssemblyInstance , WebAssemblyInstantiator } from '../../types'
7+ import type { IOnigCaptureIndex , IOnigMatch , OnigScanner as IOnigScanner , OnigString as IOnigString } from '../../../vendor/vscode-textmate/src/main'
78import createOnigasm from './onig'
89
10+ export type Instantiator = ( importObject : Record < string , Record < string , WebAssembly . ImportValue > > ) => Promise < WebAssembly . Exports >
11+
12+ export type Pointer = number
13+
914export const enum FindOption {
1015 None = 0 ,
1116 /**
@@ -20,14 +25,25 @@ export const enum FindOption {
2025 * equivalent of ONIG_OPTION_NOT_BEGIN_POSITION: (start) isn't considered as start position of search (* fail \G)
2126 */
2227 NotBeginPosition = 4 ,
23- /**
24- * used for debugging purposes.
25- */
26- DebugCall = 8 ,
28+ }
29+
30+ export interface IOnigBinding {
31+ HEAPU8 : Uint8Array
32+ HEAPU32 : Uint32Array
33+
34+ UTF8ToString : ( ptr : Pointer ) => string
35+
36+ omalloc : ( count : number ) => Pointer
37+ ofree : ( ptr : Pointer ) => void
38+ getLastOnigError : ( ) => Pointer
39+ createOnigScanner : ( strPtrsPtr : Pointer , strLenPtr : Pointer , count : number ) => Pointer
40+ freeOnigScanner : ( ptr : Pointer ) => void
41+ findNextOnigScannerMatch : ( scanner : Pointer , strCacheId : number , strData : Pointer , strLength : number , position : number , options : number ) => number
42+ // findNextOnigScannerMatchDbg: (scanner: Pointer, strCacheId: number, strData: Pointer, strLength: number, position: number, options: number) => number
2743}
2844
2945let onigBinding : IOnigBinding | null = null
30- let defaultDebugCall = false
46+ // let defaultDebugCall = false
3147
3248function throwLastOnigError ( onigBinding : IOnigBinding ) : void {
3349 throw new ShikiError ( onigBinding . UTF8ToString ( onigBinding . getLastOnigError ( ) ) )
@@ -294,34 +310,33 @@ export class OnigScanner implements IOnigScanner {
294310 public findNextMatchSync ( string : string | OnigString , startPosition : number , debugCall : boolean ) : IOnigMatch | null
295311 public findNextMatchSync ( string : string | OnigString , startPosition : number ) : IOnigMatch | null
296312 public findNextMatchSync ( string : string | OnigString , startPosition : number , arg ?: number | boolean ) : IOnigMatch | null {
297- let debugCall = defaultDebugCall
313+ // let debugCall = defaultDebugCall
298314 let options = FindOption . None
299315 if ( typeof arg === 'number' ) {
300- if ( arg & FindOption . DebugCall )
301- debugCall = true
302-
316+ // if (arg & FindOption.DebugCall)
317+ // debugCall = true
303318 options = arg
304319 }
305320 else if ( typeof arg === 'boolean' ) {
306- debugCall = arg
321+ // debugCall = arg
307322 }
308323 if ( typeof string === 'string' ) {
309324 string = new OnigString ( string )
310- const result = this . _findNextMatchSync ( string , startPosition , debugCall , options )
325+ const result = this . _findNextMatchSync ( string , startPosition , false , options )
311326 string . dispose ( )
312327 return result
313328 }
314- return this . _findNextMatchSync ( string , startPosition , debugCall , options )
329+ return this . _findNextMatchSync ( string , startPosition , false , options )
315330 }
316331
317332 private _findNextMatchSync ( string : OnigString , startPosition : number , debugCall : boolean , options : number ) : IOnigMatch | null {
318333 const onigBinding = this . _onigBinding
319- let resultPtr : Pointer
320- if ( debugCall )
321- resultPtr = onigBinding . findNextOnigScannerMatchDbg ( this . _ptr , string . id , string . ptr , string . utf8Length , string . convertUtf16OffsetToUtf8 ( startPosition ) , options )
334+ // let resultPtr: Pointer
335+ // if (debugCall)
336+ // resultPtr = onigBinding.findNextOnigScannerMatchDbg(this._ptr, string.id, string.ptr, string.utf8Length, string.convertUtf16OffsetToUtf8(startPosition), options)
322337
323- else
324- resultPtr = onigBinding . findNextOnigScannerMatch ( this . _ptr , string . id , string . ptr , string . utf8Length , string . convertUtf16OffsetToUtf8 ( startPosition ) , options )
338+ // else
339+ const resultPtr = onigBinding . findNextOnigScannerMatch ( this . _ptr , string . id , string . ptr , string . utf8Length , string . convertUtf16OffsetToUtf8 ( startPosition ) , options )
325340
326341 if ( resultPtr === 0 ) {
327342 // no match
@@ -348,17 +363,6 @@ export class OnigScanner implements IOnigScanner {
348363 }
349364}
350365
351- export interface WebAssemblyInstantiator {
352- ( importObject : Record < string , Record < string , WebAssembly . ImportValue > > | undefined ) : Promise < WebAssemblyInstance >
353- }
354-
355- export type WebAssemblyInstance = WebAssembly . WebAssemblyInstantiatedSource | WebAssembly . Instance | WebAssembly . Instance [ 'exports' ]
356-
357- export type OnigurumaLoadOptions =
358- | { instantiator : WebAssemblyInstantiator }
359- | { default : WebAssemblyInstantiator }
360- | { data : ArrayBufferView | ArrayBuffer | Response }
361-
362366function isInstantiatorOptionsObject ( dataOrOptions : any ) : dataOrOptions is { instantiator : WebAssemblyInstantiator } {
363367 return ( typeof dataOrOptions . instantiator === 'function' )
364368}
@@ -385,15 +389,6 @@ function isArrayBuffer(data: any): data is ArrayBuffer | ArrayBufferView {
385389
386390let initPromise : Promise < void >
387391
388- type Awaitable < T > = T | Promise < T >
389-
390- export type LoadWasmOptionsPlain =
391- | OnigurumaLoadOptions
392- | WebAssemblyInstantiator
393- | ArrayBufferView | ArrayBuffer | Response
394-
395- export type LoadWasmOptions = Awaitable < LoadWasmOptionsPlain > | ( ( ) => Awaitable < LoadWasmOptionsPlain > )
396-
397392export function loadWasm ( options : LoadWasmOptions ) : Promise < void > {
398393 if ( initPromise )
399394 return initPromise
@@ -461,14 +456,14 @@ function _makeResponseNonStreamingLoader(data: Response): WebAssemblyInstantiato
461456 }
462457}
463458
464- export function createOnigString ( str : string ) {
465- return new OnigString ( str )
466- }
459+ // export function createOnigString(str: string) {
460+ // return new OnigString(str)
461+ // }
467462
468- export function createOnigScanner ( patterns : string [ ] ) {
469- return new OnigScanner ( patterns )
470- }
463+ // export function createOnigScanner(patterns: string[]) {
464+ // return new OnigScanner(patterns)
465+ // }
471466
472- export function setDefaultDebugCall ( _defaultDebugCall : boolean ) : void {
473- defaultDebugCall = _defaultDebugCall
474- }
467+ // export function setDefaultDebugCall(_defaultDebugCall: boolean): void {
468+ // defaultDebugCall = _defaultDebugCall
469+ // }
0 commit comments