/
index.d.ts
46 lines (40 loc) · 1.3 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
import {MatchResult, Grammar, Semantics} from 'ohm-js';
interface LineAndColumnInfo {
offset: number;
lineNumber: number;
colNum: number;
line: string;
prevLine: string;
nextLine: string;
toString(...ranges: number[][]): string;
}
export function toAST(matchResult: MatchResult, mapping?: {}): {};
export function semanticsForToAST(g: Grammar): Semantics;
/**
* Returns contextual information (line and column number, etc.) about a
* specific character in a string.
*/
export function getLineAndColumn(str: string, offset: number): LineAndColumnInfo;
/**
* Returns a nicely-formatted message (appropriate for syntax errors, etc.)
* pointing to a specific character within a string. Optionally, one or more
* ranges within the string can also be highlighted.
*/
export function getLineAndColumnMessage(
str: string,
offset: number,
...ranges: number[][]
): string;
interface Example {
grammar: string;
rule: string;
example: string;
shouldMatch: boolean;
}
/**
* Given a string containing one or more grammar definitions, returns an array
* of examples extracted from the comments.
* Positive examples look like `//+ "one", "two"` and negative examples like
* `//- "shouldn't match"`. The examples text is a JSON string.
*/
export function extractExamples(grammarsDef: string): [Example];