2025-01-19 15:15:01 -05:00
|
|
|
import { type MainModule } from '../lib/tree-sitter';
|
2025-01-13 01:48:42 -05:00
|
|
|
|
|
|
|
|
export interface Point {
|
|
|
|
|
row: number;
|
|
|
|
|
column: number;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface Range {
|
|
|
|
|
startPosition: Point;
|
|
|
|
|
endPosition: Point;
|
|
|
|
|
startIndex: number;
|
|
|
|
|
endIndex: number;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface Edit {
|
|
|
|
|
startPosition: Point;
|
|
|
|
|
oldEndPosition: Point;
|
|
|
|
|
newEndPosition: Point;
|
|
|
|
|
startIndex: number;
|
|
|
|
|
oldEndIndex: number;
|
|
|
|
|
newEndIndex: number;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface ParserOptions {
|
|
|
|
|
includedRanges?: Range[];
|
|
|
|
|
progressCallback?: (progress: { currentOffset: number }) => boolean;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export const SIZE_OF_SHORT = 2;
|
|
|
|
|
export const SIZE_OF_INT = 4;
|
|
|
|
|
export const SIZE_OF_CURSOR = 4 * SIZE_OF_INT;
|
|
|
|
|
export const SIZE_OF_NODE = 5 * SIZE_OF_INT;
|
|
|
|
|
export const SIZE_OF_POINT = 2 * SIZE_OF_INT;
|
|
|
|
|
export const SIZE_OF_RANGE = 2 * SIZE_OF_INT + 2 * SIZE_OF_POINT;
|
|
|
|
|
export const ZERO_POINT: Point = { row: 0, column: 0 };
|
|
|
|
|
|
|
|
|
|
// Types for callbacks
|
|
|
|
|
export type ParseCallback = (index: number, position: Point) => string | null;
|
|
|
|
|
export type ProgressCallback = (progress: { currentOffset: number }) => boolean;
|
|
|
|
|
export type LogCallback = (message: string, isLex: boolean) => void;
|
|
|
|
|
|
|
|
|
|
// Helper type for internal use
|
|
|
|
|
export const INTERNAL = Symbol('INTERNAL');
|
|
|
|
|
export type Internal = typeof INTERNAL;
|
|
|
|
|
|
|
|
|
|
// Helper functions for type checking
|
|
|
|
|
export function assertInternal(x: unknown): asserts x is Internal {
|
|
|
|
|
if (x !== INTERNAL) throw new Error('Illegal constructor');
|
|
|
|
|
}
|
|
|
|
|
|
2025-01-16 01:10:54 -05:00
|
|
|
export function isPoint(point?: Point): point is Point {
|
2025-01-13 01:48:42 -05:00
|
|
|
return (
|
|
|
|
|
!!point &&
|
2025-01-16 01:10:54 -05:00
|
|
|
typeof (point).row === 'number' &&
|
|
|
|
|
typeof (point).column === 'number'
|
2025-01-13 01:48:42 -05:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2025-01-19 15:15:01 -05:00
|
|
|
export function setModule(module: MainModule) {
|
|
|
|
|
C = module;
|
|
|
|
|
}
|
2025-01-13 01:48:42 -05:00
|
|
|
|
2025-01-19 15:15:01 -05:00
|
|
|
export let C: MainModule;
|