11# @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 )
26
37> Main compiler module of Syntax Script.
48
@@ -9,15 +13,33 @@ This module is used to either compile a syntax script project, or create diagnos
913Using the compiler.
1014
1115``` typescript
12- // Compiling
1316import { SyntaxScriptCompiler } from ' @syntaxs/compiler' ;
1417
1518const compiler = new SyntaxScriptCompiler (' /path/to/root/dir' ,' /path/to/out/dir' ,' ts' );
1619compiler .compile ();
1720```
1821
19- Creating diagnostic reports.
22+ Creating diagnostic reports for language servers .
2023
2124``` 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+ }
2345```
0 commit comments