Renaming and source-region issues

This commit is contained in:
Yura Dupyn 2026-04-06 20:34:20 +02:00
parent 909caaf7ac
commit d64c39db82
19 changed files with 415 additions and 36 deletions

View file

@ -1,5 +1,5 @@
import { char, NEW_LINE, CARRIAGE_RETURN, DOT, DIGIT_0, DIGIT_9, LOWERCASE_a, LOWERCASE_f, UPPERCASE_A, UPPERCASE_F, SPACE, TAB } from 'source-text';
import type { SourceRegion, SourceText, Span, SourceLocation, CodePoint, StringIndex, CodePointIndex } from 'source-text';
import { char, NEW_LINE, CARRIAGE_RETURN, DOT, DIGIT_0, DIGIT_9, LOWERCASE_a, LOWERCASE_f, UPPERCASE_A, UPPERCASE_F, SPACE, TAB } from 'source-region';
import type { SourceRegion, SourceText, Span, SourceLocation, CodePoint, StringIndex, CodePointIndex } from 'source-region';
import { Result } from '../result';
export type CursorState = {
@ -43,15 +43,14 @@ export class Cursor {
peek(n: number = 0): CodePoint | undefined {
if (this.index + n >= this.region.span.end.index) return undefined;
return this.text.chars[this.index + n]?.char;
return this.region.codePointAt(this.index + n);
}
next(): CodePoint | undefined {
if (this.eof()) return undefined;
const ref = this.text.chars[this.index];
if (!ref) return undefined;
const c = this.region.codePointAt(this.index);
if (c === undefined) return undefined;
const c = ref.char;
this.index++;
if (c === NEW_LINE) {
@ -82,7 +81,7 @@ export class Cursor {
// TODO: unicode-index ~> string-offset, make that into a separate function.
currentOffset(): StringIndex {
return this.text.chars[this.index]?.offset ?? this.text.source.length;
return this.text.sliceByCp(0, this.index).length;
}
currentLocation(): SourceLocation {