@stxt-lang/core 0.14.0 → 0.14.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -0
- package/out/runtime/Formatter.d.ts +6 -1
- package/out/runtime/Formatter.js +6 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -334,6 +334,10 @@ if (errors.length === 0) {
|
|
|
334
334
|
}
|
|
335
335
|
```
|
|
336
336
|
|
|
337
|
+
`Formatter.format` takes the same limits as the parser as an optional third argument —
|
|
338
|
+
`Formatter.format(source, IndentStyle.TABS, { maxInputSize: -1 })` — since formatting parses
|
|
339
|
+
the document with them (STXT-SPEC §11.2).
|
|
340
|
+
|
|
337
341
|
## API surface
|
|
338
342
|
|
|
339
343
|
Everything importable from the package:
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { ParserOptions } from "../core/Parser";
|
|
1
2
|
import { ParseException } from "../exceptions/ParseException";
|
|
2
3
|
import { IndentStyle } from "./NodeWriter";
|
|
3
4
|
/** The outcome of {@link Formatter.format}. */
|
|
@@ -58,9 +59,13 @@ export declare class Formatter {
|
|
|
58
59
|
*
|
|
59
60
|
* @param text the document.
|
|
60
61
|
* @param style indentation style to format with; tabs by default.
|
|
62
|
+
* @param options limits for the internal parser (STXT-SPEC 11.2); every omitted one keeps
|
|
63
|
+
* its recommended default, and -1 disables one. A limit exceeded shows up in
|
|
64
|
+
* the errors like any other syntax error, and the lines the aborted parse
|
|
65
|
+
* never described are converted as "other lines" (indentation units only).
|
|
61
66
|
* @returns the formatted text and the syntax errors found; see {@link FormatResult}.
|
|
62
67
|
*/
|
|
63
|
-
static format(text: string, style?: IndentStyle): FormatResult;
|
|
68
|
+
static format(text: string, style?: IndentStyle, options?: ParserOptions): FormatResult;
|
|
64
69
|
/**
|
|
65
70
|
* Formats one source line.
|
|
66
71
|
*
|
package/out/runtime/Formatter.js
CHANGED
|
@@ -49,15 +49,19 @@ class Formatter {
|
|
|
49
49
|
*
|
|
50
50
|
* @param text the document.
|
|
51
51
|
* @param style indentation style to format with; tabs by default.
|
|
52
|
+
* @param options limits for the internal parser (STXT-SPEC 11.2); every omitted one keeps
|
|
53
|
+
* its recommended default, and -1 disables one. A limit exceeded shows up in
|
|
54
|
+
* the errors like any other syntax error, and the lines the aborted parse
|
|
55
|
+
* never described are converted as "other lines" (indentation units only).
|
|
52
56
|
* @returns the formatted text and the syntax errors found; see {@link FormatResult}.
|
|
53
57
|
*/
|
|
54
|
-
static format(text, style = NodeWriter_1.IndentStyle.TABS) {
|
|
58
|
+
static format(text, style = NodeWriter_1.IndentStyle.TABS, options) {
|
|
55
59
|
// STXT-TREE-SPEC 12.1: an initial BOM is not kept
|
|
56
60
|
if (text.startsWith("\uFEFF")) {
|
|
57
61
|
text = text.substring(1);
|
|
58
62
|
}
|
|
59
63
|
const sourceLines = new SourceLines();
|
|
60
|
-
const parser = new Parser_1.Parser();
|
|
64
|
+
const parser = new Parser_1.Parser(options);
|
|
61
65
|
parser.registerObserver(sourceLines);
|
|
62
66
|
const result = parser.parseResult(text);
|
|
63
67
|
const eol = text.includes("\r\n") ? "\r\n" : "\n";
|