-
-
Notifications
You must be signed in to change notification settings - Fork 41
Expand file tree
/
Copy pathapi.ts
More file actions
48 lines (41 loc) · 1.18 KB
/
api.ts
File metadata and controls
48 lines (41 loc) · 1.18 KB
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
import { source } from 'llparse-frontend';
import { Compiler, ICompilerOptions, ICompilerResult } from './compiler';
export { source, ICompilerOptions, ICompilerResult };
// TODO(indutny): API for disabling/short-circuiting spans
/**
* LLParse graph builder and compiler.
*/
export class LLParse extends source.Builder {
private readonly prefix: string;
/**
* The prefix controls the names of methods and state struct in generated
* public C headers:
*
* ```c
* // state struct
* struct PREFIX_t {
* ...
* }
*
* int PREFIX_init(PREFIX_t* state);
* int PREFIX_execute(PREFIX_t* state, const char* p, const char* endp);
* ```
*
* @param prefix Prefix to be used when generating public API.
*/
constructor(prefix: string = 'llparse') {
super();
this.prefix = prefix;
}
/**
* Compile LLParse graph to the C code and C headers
*
* @param root Root node of the parse graph (see `.node()`)
* @param options Compiler options.
*/
public build(root: source.node.Node, options: ICompilerOptions = {})
: ICompilerResult {
const c = new Compiler(this.prefix, options);
return c.compile(root, this.properties);
}
}