@eagleoutice/flowr
Version:
Static Dataflow Analyzer and Program Slicer for the R Programming Language
67 lines (66 loc) • 2.86 kB
TypeScript
/**
* A source position in a file.
*
* Please note that some packages like `xmlparsedata` use their own start and end only to break ties
* (e.g., `xmlparsedata` calculates them on a max col width approximation)
*/
export type SourcePosition = [
/** starts with 1 */
line: number,
/** starts with 1 */
column: number
];
/**
* Describe the start and end {@link SourcePosition|source position} of an element.
*
* @see {@link rangeFrom} - to create a range
* @see {@link mergeRanges} - to merge multiple ranges
* @see {@link getRangeStart} - to get the start of a range
* @see {@link getRangeEnd} - to get the end of a range
* @see {@link rangeStartsCompletelyBefore} - to check if one range starts before another
* @see {@link rangesOverlap} - to check if two ranges overlap
* @see {@link addRanges} - to add two ranges
* @see {@link rangeCompare} - to compare two ranges
*/
export type SourceRange = [
/** inclusive start position */
startLine: number,
startColumn: number,
/** inclusive end position */
endLine: number,
endColumn: number
];
export declare function getRangeStart(p: undefined): undefined;
export declare function getRangeStart(p: SourceRange): SourcePosition;
export declare function getRangeStart(p: SourceRange | undefined): SourcePosition | undefined;
export declare function getRangeEnd(p: undefined): undefined;
export declare function getRangeEnd(p: SourceRange): SourcePosition;
export declare function getRangeEnd(p: SourceRange | undefined): SourcePosition | undefined;
/**
* This does not ensure ordering of start and end!
*
* @param sl - start line
* @param sc - start column
* @param el - end line
* @param ec - end column
*/
export declare function rangeFrom(sl: number | string, sc: number | string, el: number | string, ec: number | string): SourceRange;
export declare function mergeRanges(...rs: SourceRange[]): SourceRange;
/**
* @returns true iff `r1` starts and ends before `r2` starts (i.e., if `r1` and `r2` do not overlap and `r1` comes before `r2`
*/
export declare function rangeStartsCompletelyBefore([, , r1el, r1ec]: SourceRange, [r2sl, r2sc, ,]: SourceRange): boolean;
/**
* Checks if the two ranges overlap.
*/
export declare function rangesOverlap([r1sl, r1sc, r1el, r1ec]: SourceRange, [r2sl, r2sc, r2el, r2ec]: SourceRange): boolean;
/**
* Calculate the component-wise sum of two ranges
*/
export declare function addRanges([r1sl, r1sc, r1el, r1ec]: SourceRange, [r2sl, r2sc, r2el, r2ec]: SourceRange): SourceRange;
/**
* Provides a comparator for {@link SourceRange}s that sorts them in ascending order.
*
* @returns a positive number if `r1` comes after `r2`, a negative number if `r1` comes before `r2`, and `0` if they are equal
*/
export declare function rangeCompare([r1sl, r1sc, ,]: SourceRange, [r2sl, r2sc, ,]: SourceRange): number;