1
1
# @syntaxs/compiler ` v0.0.1-alpha `
2
+ ![ Stars] ( https://badgen.net/github/stars/syntax-script/compiler )
3
+ ![ Releases] ( https://badgen.net/github/release/syntax-script/compiler )
4
+ ![ Version] ( https://badgen.net/npm/v/@syntaxs/compiler )
5
+ ![ License] ( https://badgen.net/github/license/syntax-script/compiler )
2
6
3
7
> Main compiler module of Syntax Script.
4
8
@@ -9,15 +13,33 @@ This module is used to either compile a syntax script project, or create diagnos
9
13
Using the compiler.
10
14
11
15
``` typescript
12
- // Compiling
13
16
import { SyntaxScriptCompiler } from ' @syntaxs/compiler' ;
14
17
15
18
const compiler = new SyntaxScriptCompiler (' /path/to/root/dir' ,' /path/to/out/dir' ,' ts' );
16
19
compiler .compile ();
17
20
```
18
21
19
- Creating diagnostic reports.
22
+ Creating diagnostic reports for language servers .
20
23
21
24
``` typescript
22
- // TODO
25
+ import {createSyntaxScriptDiagnosticReport } from ' @syntaxs/compiler' ;
26
+
27
+ const report = createSyntaxScriptDiagnosticReport (' /path/to/file.syx' );
28
+ console .log (` ${report .items .length } Problems found in the file. ` );
29
+ ```
30
+
31
+ Handling compiler errors
32
+ ``` typescript
33
+ import { SyntaxScriptCompiler ,isCompilerError } from ' @syntaxs/compiler' ;
34
+
35
+ const compiler = new SyntaxScriptCompiler (' /path/to/root/dir' ,' /path/to/out/dir' ,' ts' );
36
+ try {
37
+ compiler .compile ();
38
+ } catch (e ) {
39
+ if (isCompilerError (e )) {
40
+ console .log (` There is a syntax error in the file: ${e .message } ` );
41
+ console .log (` This problem is at line ${e .range .start .line } ` );
42
+ console .log (` There are ${e .actions .length } recommended solutions to this problem. ` )
43
+ }
44
+ }
23
45
```
0 commit comments