forked from rksm/paredit.js
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.d.ts
116 lines (99 loc) · 4.82 KB
/
index.d.ts
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
export as namespace paredit
type ParseOptions = { addSourceForLeafs?: boolean }
export function parse(src: string, options?: ParseOptions): TopLevelNode
interface Range {
start: number,
end: number
}
type AST = TopLevelNode | ErrorNode | ListNode | StringNode | SimpleNode
type InnerNode = ErrorNode | ListNode | StringNode | SimpleNode
export interface TopLevelNode extends Range {
type: 'toplevel',
errors: ErrorNode[],
children: InnerNode[]
}
export interface ErrorNode extends Range {
type: 'error',
error: string
open: string,
close: string,
children: InnerNode[]
}
export interface ListNode extends Range {
type: 'list',
open: string,
close: string,
children: InnerNode[]
}
export interface SimpleNode extends Range {
type: 'number' | 'symbol' | 'char' | 'special' | 'comment',
source?: string
}
export interface StringNode extends Range {
type: 'string',
open: string,
close: string,
source?: string
}
export namespace reader {
export interface Position {
idx: number,
column: number,
row: number
}
export interface ReaderError<T> {
error: string,
start: Position,
end: Position,
children?: (T | number | string | ReaderError<T>)[]
}
type Xform<T> = (type: string, read: T[] | number | string | ReaderError<T>,
start: Position, end: Position, args: { open: string, close: string }) => T
export function setParentheses(parentheses: { [open: string]: string }): void
export function readSeq<T>(src: string, xform: Xform<T>): T[]
export function readSexp<T>(src: string, xform: Xform<T>): T
}
export namespace navigator {
export function forwardSexp(ast: AST, idx: number): number
export function forwardDownSexp(ast: AST, idx: number): number
export function backwardSexp(ast: AST, idx: number): number
export function backwardUpSexp(ast: AST, idx: number): number
export function closeList(ast: AST, idx: number): number
export function sexpRange(ast: AST, idx: number): [number, number]
export function sexpRangeExpansion(ast: AST, startIdx: number, endIdx: number): [number, number]
export function rangeForDefun(ast: AST, idx: number): [number, number]
}
export namespace walk {
type MatchFunc = (ast: AST) => boolean
export function hasChildren(ast: AST): boolean
export function containingSexpsAt(ast: AST, idx: number, matchFunc?: MatchFunc): AST[]
export function sexpsAt(ast: AST, idx: number, matchFunc?: MatchFunc): AST[]
export function nextSexp(ast: AST, idx: number, matchFunc?: MatchFunc): AST
export function prevSexp(ast: AST, idx: number, matchFunc?: MatchFunc): AST
export function stringify(ast: AST): string
export function source(src: string, ast: AST): string
}
export namespace editor {
interface EditorChanges { changes: [string, number, string | number][], newIndex: number }
interface Indent extends EditorChanges { ast: AST, src: string, idx: number }
type OpenListArgs = { count?: number, open?: string, close?: string, endIdx?: number, freeEdits?: boolean }
type CountAndBackwardArgs = { count?: number, backward?: boolean }
type WrapArgs = { count?: number }
type SexpBarfArgs = { backward?: boolean }
type DeleteArgs = { count?: number, backward?: boolean, endIdx?: number, freeEdits?: boolean }
export function rewrite(ast: AST, nodeToReplace: InnerNode, newNodes: InnerNode[]): AST
export function openList(ast: AST, src: string, idx: number, args?: OpenListArgs): EditorChanges
export function spliceSexp(ast: AST, src: string, idx: number): EditorChanges | null
export function spliceSexpKill(ast: AST, src: string, idx: number, args?: CountAndBackwardArgs): EditorChanges | null
export function splitSexp(ast: AST, src: string, idx: number): EditorChanges | null
export function killSexp(ast: AST, src: string, idx: number, args?: CountAndBackwardArgs): EditorChanges | null
export function wrapAround(ast: AST, src: string, idx: number, wrapWithStart: string, wrapWithEnd: string, args?: WrapArgs): EditorChanges | null
export function closeAndNewLine(ast: AST, src: string, idx: number, close?: string): EditorChanges | null
export function barfSexp(ast: AST, src: string, idx: number, args?: SexpBarfArgs): EditorChanges | null
export function slurpSexp(ast: AST, src: string, idx: number, args?: CountAndBackwardArgs): EditorChanges | null
export function transpose(ast: AST, src: string, idx: number, args?: {}): EditorChanges | null // args?
function deleteX(ast: AST, src: string, idx: number, args?: DeleteArgs): EditorChanges | null
export { deleteX as delete } // hackish way to export 'delete', which is a reserved word
export function indentRange(ast: AST, src: string, start: number, end: number): Indent
}
export const specialForms: string[]