-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate-tokenizer.mts
More file actions
1136 lines (1013 loc) · 27.7 KB
/
Copy pathcreate-tokenizer.mts
File metadata and controls
1136 lines (1013 loc) · 27.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**
* @file createTokenizer
* @module mark-parser/createTokenizer
*/
import type Info from '#types/info'
import type ReturnHandle from '#types/return-handle'
import type { Initialize, Options } from '@flex-development/mark-parser'
import { chars, codes, constants, ev } from '@flex-development/mark-util-symbol'
import type { IfNever, List } from '@flex-development/mark/core'
import type {
Attempt,
Chunk,
Code,
Column,
Construct,
ConstructRecord,
Constructs,
ContentType,
Context,
Create,
CreateToken,
Effects,
Event,
Extension,
FileLike,
InitialConstruct,
InitialConstructs,
Line,
NormalizedExtension,
ParseContext,
Place,
Point,
Range,
SerializeOptions,
State,
Token,
TokenFields,
TokenInfo,
TokenizeContext,
TokenType,
Value
} from '@flex-development/mark/parse'
import { Location } from '@flex-development/vfile-location'
import type { Debugger } from 'debug'
import { ok as assert } from 'devlop'
import createDebugger from './internal/create-debugger.mts'
import createDefineSkip from './internal/create-define-skip.mts'
import createTokenFactory from './internal/create-token-factory.mts'
import isList from './internal/is-list.mts'
import noop from './internal/noop.mts'
import skip from './internal/skip.mts'
import toList from './internal/to-list.mts'
import preprocess from './preprocess.mts'
import {
combineExtensions,
decode,
eol,
eos,
isCode,
push,
resolveAll,
serializeChunks,
sliceChunks,
splice,
tab
} from './utils/index.mts'
export default createTokenizer
/**
* Create a tokenizer.
*
* @see {@linkcode Context}
* @see {@linkcode IfNever}
* @see {@linkcode Initialize}
* @see {@linkcode Options}
* @see {@linkcode Point}
* @see {@linkcode TokenizeContext}
*
* @this {void}
*
* @param {Initialize} initialize
* The initial construct, a record of initial constructs,
* or a function that returns the initial construct or record
* @param {Partial<Options> | Point | null | undefined} [options]
* The tokenizer options or the point before the first character in the content
* @return {IfNever<Context, TokenizeContext, Context>}
* The tokenization context
*/
function createTokenizer(
this: void,
initialize: Initialize,
options?: Partial<Options> | Point | null | undefined
): IfNever<Context, TokenizeContext, Context>
/**
* Create a tokenizer.
*
* @see {@linkcode Context}
* @see {@linkcode IfNever}
* @see {@linkcode Initialize}
* @see {@linkcode Options}
* @see {@linkcode TokenizeContext}
*
* @this {void}
*
* @param {Initialize | Options} options
* The initial construct, a record of initial constructs, a function that
* returns the initial construct or record, or the tokenizer options
* @return {IfNever<Context, TokenizeContext, Context>}
* The tokenization context
*/
function createTokenizer(
this: void,
options: Initialize | Options
): IfNever<Context, TokenizeContext, Context>
/**
* Create a tokenizer.
*
* @see {@linkcode Initialize}
* @see {@linkcode Options}
* @see {@linkcode TokenizeContext}
*
* @this {void}
*
* @param {Initialize | Options} initialize
* The initial construct, a record of initial constructs, a function that
* returns the initial construct or record, or the tokenizer options
* @param {Partial<Options> | Point | null | undefined} [options]
* The tokenizer options or the point before the first character in the content
* @return {TokenizeContext}
* The tokenization context
*/
function createTokenizer(
this: void,
initialize: Initialize | Options,
options?: Partial<Options> | Point | null | undefined
): TokenizeContext {
if ('initialize' in initialize) {
options = initialize
initialize = initialize.initialize
} else if (options && 'line' in options) {
options = { from: options, initialize: initialize }
} else {
options = { ...options, initialize: initialize }
}
assert('initialize' in options, 'expected options object')
if (typeof initialize === 'function') initialize = initialize()
/**
* The debug logger.
*
* @const {Debugger} debug
*/
const debug: Debugger = createDebugger(options)
/**
* The context object to transition the state machine.
*
* @const {Effects} effects
*/
const effects: Effects = {
attempt: constructFactory(onsuccessfulconstruct),
check: constructFactory(onsuccessfulcheck),
consume,
enter,
exit,
interrupt: constructFactory(onsuccessfulcheck, { interrupt: true })
}
/**
* The list of constructs with `resolveAll` handlers.
*
* @const {Construct[]} resolveAlls
*/
const resolveAlls: Construct[] = []
/**
* Map, where each key is a line number and each value a column to be skipped
* to when the tokenizer has reached that line.
*
* @const {Record<Line, Column>} skips
*/
const skips: Record<Line, Column> = {}
/**
* The token factory.
*
* @const {CreateToken} token
*/
const token: CreateToken = createTokenFactory(options)
/**
* The list of chunks.
*
* @var {Chunk[]} chunks
*/
let chunks: Chunk[] = []
/**
* The character code consumption state, used for tracking bugs.
*
* @var {boolean | null} consumed
*/
let consumed: boolean | null = true
/**
* The expected character code, used for tracking bugs.
*
* @var {Code} expected
*/
let expected: Code
/**
* The last buffer chunk index.
*
* @var {number} lastBufferIndex
*/
let lastBufferIndex: number = -1
/**
* The current point in the content.
*
* @var {Place} place
*/
let place: Place = new Location(null, options.from).place as Place
/**
* The token stack.
*
* @var {Token[]} stack
*/
let stack: Token[] = []
/**
* The current state.
*
* @var {State | undefined} state
*/
let state: State | undefined
/**
* The tokenization context.
*
* Contains state and tools for resolving and serializing.
*
* @const {TokenizeContext} context
*/
const context: TokenizeContext = Object.defineProperties({
code: codes.bos,
currentConstruct: undefined,
debug,
defineSkip: createDefineSkip(place, skips, debug),
effects,
encoding: options.encoding,
events: [],
now,
parser: options.parser ?? {} as ParseContext,
peek,
preprocess: options.preprocess ?? preprocess(options),
previous: codes.bos,
serializeChunks,
sliceSerialize,
sliceStream,
token,
write
}, {
debug: {
configurable: false,
enumerable: false,
writable: false
},
effects: {
configurable: false,
enumerable: false,
writable: false
}
})
place._bufferIndex = lastBufferIndex
place._index = 0
finalizeContext(context, initialize, options)
if ('tokenize' in initialize) {
onsuccessfulconstruct(initialize)
state = initialize.tokenize.call(context, effects)
}
return context
/**
* Factory to attempt/check/interrupt.
*
* @this {void}
*
* @param {ReturnHandle} onreturn
* The success callback
* @param {Partial<TokenizeContext> | null | undefined} [fields]
* The fields to attach to the tokenization context
* @return {Attempt}
* attempt/check/interrupt
*/
function constructFactory(
this: void,
onreturn: ReturnHandle,
fields?: Partial<TokenizeContext> | null | undefined
): Attempt {
return hook
/**
* Handle an object mapping codes to constructs, a list of constructs,
* or a single construct.
*
* @this {void}
*
* @param {Constructs} construct
* The constructs to try
* @param {State | undefined} [succ]
* The successful tokenization state
* @param {State | undefined} [fail]
* The failed tokenization state
* @return {State}
* The next state
*/
function hook(
this: void,
construct: Constructs,
succ: State | undefined = noop,
fail?: State | undefined
): State {
/**
* The current construct.
*
* @var {Construct} currentConstruct
*/
let currentConstruct: Construct
/**
* The internal state.
*
* @var {Info} info
*/
let info: Info
/**
* The index of the current construct.
*
* @var {number} j
*/
let j: number
/**
* The construct list.
*
* @var {Construct[]} list
*/
let list: Construct[]
// handle list of constructs, single construct, or map of constructs
return 'tokenize' in construct || isList(construct)
? handleConstructList(toList(construct))
: handleConstructRecord(construct)
/**
* Handle a list of constructs.
*
* @this {void}
*
* @param {Construct[]} constructs
* The list of constructs
* @return {State}
* The next state
*/
function handleConstructList(this: void, constructs: Construct[]): State {
list = constructs
j = 0
if (!constructs.length) {
assert(fail, 'expected `fail` to be given')
return fail
}
assert(constructs[j], 'expected `constructs[j]`')
return handleConstruct(constructs[j]!)
}
/**
* Handle an object mapping codes to constructs.
*
* @this {void}
*
* @param {ConstructRecord} map
* The construct record
* @return {State}
* The next state
*/
function handleConstructRecord(this: void, map: ConstructRecord): State {
return record
/**
* @this {void}
*
* @param {Code} code
* The current character code
* @return {State | undefined}
* The next state
*/
function record(this: void, code: Code): State | undefined {
/**
* The list of constructs to try.
*
* @const {Construct[]} list
*/
const list: Construct[] = []
code !== codes.eos && map[code] && list.push(...toList(map[code]))
map.null && list.push(...toList(map.null))
return handleConstructList(list)(code)
}
}
/**
* Handle a single construct.
*
* @this {void}
*
* @param {Construct} construct
* The construct
* @return {State}
* The next state
*/
function handleConstruct(this: void, construct: Construct): State {
return start
/**
* @this {void}
*
* @param {Code} code
* The current character code
* @return {State | undefined}
* The next state
*/
function start(code: Code): State | undefined {
debug('start: %o', code)
info = store()
currentConstruct = construct
// set current construct.
if (!construct.partial) context.currentConstruct = construct
// always populated by defaults.
assert(
context.parser.constructs.disable.null,
'expected `disable.null` to be populated'
)
// construct is disabled by name.
if (
construct.name &&
context.parser.constructs.disable.null.includes(construct.name)
) {
return nok(code)
}
// construct is disabled by guard.
if (
construct.previous &&
!construct.previous.call(context, context.previous)
) {
return nok(code)
}
/**
* The tokenization context to use.
*
* @var {TokenizeContext} self
*/
let self: TokenizeContext = context
// create an object w/ `context` as its prototype.
// this allows a "live binding", which is needed for `interrupt`.
if (fields) {
self = Object.create(
context,
Object.getOwnPropertyDescriptors(context)
)
}
return construct.tokenize.call(
Object.assign(self, fields),
effects,
ok,
nok
)(code)
}
}
/**
* The state to go on successful tokenization.
*
* @this {void}
*
* @param {Code} code
* The current character code
* @return {State}
* The next state
*/
function ok(this: void, code: Code): State {
assert(code === expected, 'expected `code` to equal expected code')
debug('ok: `%o`', code)
consumed = true
onreturn(currentConstruct, info)
return succ
}
/**
* The state to go on failed tokenization.
*
* @this {void}
*
* @param {Code} code
* The current character code
* @return {State | undefined}
* The next state
*/
function nok(this: void, code: Code): State | undefined {
assert(list, 'expected construct `list`')
assert(code === expected, 'expected `code` to equal `expected`')
debug('nok: `%o`', code)
consumed = true
info.restore()
if (++j < list.length) {
assert(list[j], 'expected construct')
return handleConstruct(list[j]!)
}
return fail
}
}
}
/**
* Consume a character code and move onto the next.
*
* @this {void}
*
* @param {Code} code
* The current character code
* @return {undefined}
*/
function consume(this: void, code: Code): undefined {
assert(options && 'initialize' in options, 'expected options object')
assert(code === expected, 'expected `code` to equal expected code')
debug('consume: `%o`; previous: `%o`', code, context.previous)
assert(consumed === null, 'expected unconsumed code')
if ((options.eol ?? eol)(code)) {
place.column = 1
place.line++
place.offset += code === codes.crlf ? 2 : 1
skip(place, skips)
debug('position after eol: %o', place)
} else if (tab(code)) {
place.column += options.tabSize ?? constants.tabSize
if (code < 0) place.offset++
} else if (
code !== codes.empty &&
code !== codes.eos &&
code !== codes.vs
) {
if (code !== codes.break || options.moveOnBreak) {
place.column++
place.offset++
}
}
if (place._bufferIndex < 0) { // not in a string chunk.
place._index++
} else { // inside string chunk.
lastBufferIndex = ++place._bufferIndex
/**
* The current chunk.
*
* @const {Chunk | undefined} chunk
*/
const chunk: Chunk | undefined = chunks[place._index]
assert(typeof chunk === 'string', 'expected string chunk')
// at end of string chunk.
// points with non-negative `_bufferIndex` values reference strings.
if (lastBufferIndex === chunk.length) {
place._index++
place._bufferIndex = -1
}
}
context.previous = code
context.code = peek()
debug('context.code: `%o`', context.code)
return consumed = true, void code
}
/**
* Create a tokenizer factory.
*
* @this {void}
*
* @param {ContentType} contentType
* The content type
* @return {Create}
* The tokenizer factory
*/
function creator(this: void, contentType: ContentType): Create {
return create
/**
* @this {void}
*
* @param {Point | null | undefined} [from]
* Where to start the tokenizer
* @return {TokenizeContext}
* The new tokenization context
*/
function create(
this: void,
from?: Point | null | undefined
): TokenizeContext {
assert(options && 'initialize' in options, 'expected options object')
assert(contentType in initialize, 'expected initial construct record')
return createTokenizer(initialize[contentType], {
...options,
debug: debug.namespace + chars.colon + contentType,
from: from ?? options.from,
parser: context.parser
})
}
}
/**
* Start a new token.
*
* @this {void}
*
* @param {TokenType} type
* The token type
* @param {TokenFields | null | undefined} [fields]
* Token fields
* @return {Token}
* The open token
*/
function enter(
this: void,
type: TokenType,
fields?: TokenFields | null | undefined
): Token {
skip(place, skips)
fields ??= {}
/**
* Where the token starts.
*
* @const {Point} start
*/
const start: Point = context.now()
/**
* The token info.
*
* @const {TokenInfo} info
*/
const info: TokenInfo = Object.assign(fields as TokenInfo, { start })
/**
* The new token.
*
* @const {Token} token
*/
const token: Token = context.token(type, info)
assert(typeof type === 'string', 'expected `type` to be a string')
assert(type.length > 0, 'expected `type` to be a non-empty string')
debug('enter: `%s`; %o', type, token.start)
// add enter event and push `token` onto the `stack`.
context.events.push([ev.enter, token, context])
stack.push(token)
return token
}
/**
* Close an open token.
*
* @this {void}
*
* @param {TokenType} type
* The token type
* @return {Token}
* The closed token
*/
function exit(this: void, type: TokenType): Token {
assert(typeof type === 'string', 'expected `type` to be a string')
assert(type.length > 0, 'expected `type` to be a non-empty string')
/**
* The token to close.
*
* @const {Token | undefined} token
*/
const token: Token | undefined = stack.pop()
assert(token, 'cannot exit without open token')
// close token.
token.end = context.now()
// empty token closed at end of string chunk.
if (
token.start._index === token.end._index &&
token.start._bufferIndex === token.end._bufferIndex &&
token.start._bufferIndex < 0 &&
typeof chunks[token.start._index - 1] === 'string'
) {
token.start._index = token.end._index - 1
token.start._bufferIndex = lastBufferIndex
}
debug('exit: `%s`; %o', token.type, token.end)
// add exit event.
assert(type === token.type, 'expected exit token to match current token')
context.events.push([ev.exit, token, context])
return token
}
/**
* Finalize the tokenization context.
*
* @see {@linkcode TokenizeContext}
*
* @this {void}
*
* @param {TokenizeContext} context
* The base tokenization context
* @param {InitialConstruct | InitialConstructs} initialize
* The initial construct, or the record of initial constructs
* @param {Partial<Options>} options
* The tokenizer options
* @return {null | undefined}
* Nothing
*/
function finalizeContext(
this: void,
context: TokenizeContext,
initialize: InitialConstruct | InitialConstructs,
options: Partial<Options>
): null | undefined {
/**
* The base syntax extension.
*
* @const {NormalizedExtension} extension
*/
const extension: NormalizedExtension = {
disable: { null: options.disable ? [...options.disable] : [] }
}
/**
* The extension, or extensions, to combine.
*
* @const {Extension | List<Extension> | null | undefined} extensions
*/
const extensions: Extension | List<Extension> | null | undefined =
typeof options.extensions === 'function'
? options.extensions()
: options.extensions
// combine extensions.
context.parser.constructs = combineExtensions(extension, extensions)
// add content-level tokenizers.
if (!Object.prototype.hasOwnProperty.call(initialize, 'tokenize')) {
for (const ct in initialize) {
Object.assign(context.parser, { [ct]: creator(ct as ContentType) })
if (ct in context.parser.constructs) continue
Object.assign(context.parser.constructs, { [ct]: {} })
}
}
return options.finalizeContext?.(context, initialize, options)
}
/**
* Deal with one character code.
*
* @this {void}
*
* @param {Code} code
* The character code to handle
* @return {undefined}
*/
function go(this: void, code: Code): undefined {
assert(consumed, `expected code \`${code}\` to be consumed`)
consumed = null
debug('go: `%o`, %j', code, /* v8 ignore next */ state?.name)
expected = code
assert(typeof state === 'function', 'expected state function')
return state = state(code), void code
}
/**
* Get the current point in the file.
*
* @this {void}
*
* @return {Place}
* The current point
*/
function now(this: void): Place {
const { _bufferIndex, _index, column, line, offset } = place
// eslint-disable-next-line sort-keys
return { line, column, offset, _index, _bufferIndex }
}
/**
* Restore state after a check.
*
* @this {void}
*
* @param {Construct} construct
* The successful construct
* @param {Pick<Info, 'restore'>} info
* Info passed around
* @return {undefined}
*/
function onsuccessfulcheck(
this: void,
construct: Construct,
info: Pick<Info, 'restore'>
): undefined {
return void info.restore()
}
/**
* Resolve events.
*
* @this {void}
*
* @param {Construct} construct
* The successful construct
* @param {Pick<Info, 'from'> | null | undefined} [info]
* Info passed around
* @return {undefined}
*/
function onsuccessfulconstruct(
this: void,
construct: Construct,
info?: Pick<Info, 'from'> | null | undefined
): undefined {
if (construct.resolveAll && !resolveAlls.includes(construct)) {
resolveAlls.push(construct)
}
if (info) {
// resolve the events parsed by `construct.tokenize`.
if (construct.resolve) {
splice(
context.events,
info.from,
context.events.length - info.from,
construct.resolve(context.events.slice(info.from), context)
)
}
// resolve events parsed from the start of content (which may include
// other constructs) to the last one parsed by `construct.tokenize`.
if (construct.resolveTo) {
context.events = construct.resolveTo(context.events, context)
}
assert(
/* v8 ignore next 3 */ construct.partial ||
!context.events.length ||
context.events[context.events.length - 1]![0] === ev.exit,
'expected last token to end'
)
}
return void construct
}
/**
* Get the next character code without changing position without changing the
* position of the tokenizer.
*
* @this {void}
*
* @return {Code}
* The peeked character code
*/
function peek(this: void): Code {
/**
* The peeked character code.
*
* @var {Code} code
*/
let code: Code | undefined
if (place._index < chunks.length) {
/**
* The current chunk.
*
* @const {Chunk | undefined} chunk
*/
const chunk: Chunk | undefined = chunks[place._index]
assert(chunk !== undefined, 'expected `chunk`')
if (typeof chunk !== 'string') { // not in string chunk.
assert(place._bufferIndex < 0, 'expected negative `_bufferIndex`')
code = chunk
} else { // in or at end of string chunk.
code = chunk.codePointAt(place._bufferIndex)
}
}
return isCode(code) ? code : eos(chunks.at(-1)) ? codes.eos : codes.break
}
/**
* Get the text spanning `range`.
*
* @this {void}
*
* @param {Range} range
* The position in stream
* @param {SerializeOptions | boolean | null | undefined} [options]
* Options for serializing or whether to expand tabs
* @return {string}
* The serialized slice
*/
function sliceSerialize(
this: void,
range: Range,
options?: SerializeOptions | boolean | null | undefined
): string {
return context.serializeChunks(context.sliceStream(range), options)
}
/**
* Get the chunks spanning `range`.
*
* @this {void}
*
* @param {Range} range
* The position in stream
* @return {Chunk[]}
* The chunks in stream spanning `range`
*/
function sliceStream(this: void, range: Range): Chunk[] {
return sliceChunks(chunks, range)
}
/**
* Store state.
*
* @this {void}
*
* @return {Info}
* Info passed around
*/
function store(this: void): Info {
/**
* The current character code.
*
* @const {Code} code
*/
const code: Code = context.code
/**
* The current construct.
*
* @const {Construct | null | undefined} construct
*/
const construct: Construct | null | undefined = context.currentConstruct