@stxt-lang/core 0.6.0 → 0.6.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/out/all.d.ts +2 -0
- package/out/all.js +4 -1
- package/out/runtime/TreeJson.d.ts +40 -0
- package/out/runtime/TreeJson.js +46 -0
- package/out/schema/SchemaProviderMemory.js +7 -2
- package/out/template/TemplateSchemaProviderMemory.d.ts +2 -1
- package/out/template/TemplateSchemaProviderMemory.js +8 -3
- package/package.json +1 -1
package/out/all.d.ts
CHANGED
|
@@ -17,6 +17,8 @@ export { transformNodeToSchema } from "./schema/SchemaParser";
|
|
|
17
17
|
export { UnifiedSchemaProvider } from "./runtime/UnifiedSchemaProvider";
|
|
18
18
|
export { ConditionalValidator } from "./runtime/ConditionalValidator";
|
|
19
19
|
export { NodeWriter, IndentStyle } from "./runtime/NodeWriter";
|
|
20
|
+
export { toCanonicalTree, toCanonicalJson } from "./runtime/TreeJson";
|
|
21
|
+
export type { CanonicalDocument, CanonicalNode, CanonicalInlineNode, CanonicalBlockNode } from "./runtime/TreeJson";
|
|
20
22
|
export { transformTemplateNodeToSchema } from "./template/TemplateParser";
|
|
21
23
|
export { DiscoveryResolver, DiscoveryOptions } from "./discovery/DiscoveryResolver";
|
|
22
24
|
export { DiscoveryResult, DiscoveryDefinition, DiscoveryLevel } from "./discovery/DiscoveryResult";
|
package/out/all.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
// Anything that should be consumable by third parties (e.g. the VSCode extension)
|
|
4
4
|
// has to be re-exported from here.
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.DiscoveryError = exports.DiscoveryResult = exports.DiscoveryResolver = exports.transformTemplateNodeToSchema = exports.IndentStyle = exports.NodeWriter = exports.ConditionalValidator = exports.UnifiedSchemaProvider = exports.transformNodeToSchema = exports.ChildDefinition = exports.NodeDefinition = exports.SchemaValidator = exports.Schema = exports.ValidationException = exports.ParseException = exports.StringUtils = exports.parseLine = exports.Constants = exports.Line = exports.ParseResult = exports.Parser = exports.Node = void 0;
|
|
6
|
+
exports.DiscoveryError = exports.DiscoveryResult = exports.DiscoveryResolver = exports.transformTemplateNodeToSchema = exports.toCanonicalJson = exports.toCanonicalTree = exports.IndentStyle = exports.NodeWriter = exports.ConditionalValidator = exports.UnifiedSchemaProvider = exports.transformNodeToSchema = exports.ChildDefinition = exports.NodeDefinition = exports.SchemaValidator = exports.Schema = exports.ValidationException = exports.ParseException = exports.StringUtils = exports.parseLine = exports.Constants = exports.Line = exports.ParseResult = exports.Parser = exports.Node = void 0;
|
|
7
7
|
var Node_1 = require("./core/Node");
|
|
8
8
|
Object.defineProperty(exports, "Node", { enumerable: true, get: function () { return Node_1.Node; } });
|
|
9
9
|
var Parser_1 = require("./core/Parser");
|
|
@@ -39,6 +39,9 @@ Object.defineProperty(exports, "ConditionalValidator", { enumerable: true, get:
|
|
|
39
39
|
var NodeWriter_1 = require("./runtime/NodeWriter");
|
|
40
40
|
Object.defineProperty(exports, "NodeWriter", { enumerable: true, get: function () { return NodeWriter_1.NodeWriter; } });
|
|
41
41
|
Object.defineProperty(exports, "IndentStyle", { enumerable: true, get: function () { return NodeWriter_1.IndentStyle; } });
|
|
42
|
+
var TreeJson_1 = require("./runtime/TreeJson");
|
|
43
|
+
Object.defineProperty(exports, "toCanonicalTree", { enumerable: true, get: function () { return TreeJson_1.toCanonicalTree; } });
|
|
44
|
+
Object.defineProperty(exports, "toCanonicalJson", { enumerable: true, get: function () { return TreeJson_1.toCanonicalJson; } });
|
|
42
45
|
var TemplateParser_1 = require("./template/TemplateParser");
|
|
43
46
|
Object.defineProperty(exports, "transformTemplateNodeToSchema", { enumerable: true, get: function () { return TemplateParser_1.transformTemplateNodeToSchema; } });
|
|
44
47
|
var DiscoveryResolver_1 = require("./discovery/DiscoveryResolver");
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { Node } from "../core/Node";
|
|
2
|
+
/** Canonical JSON representation of a parsed STXT document (STXT-TREE-SPEC). */
|
|
3
|
+
export type CanonicalDocument = CanonicalNode[];
|
|
4
|
+
/** A node in the canonical JSON representation of an STXT document. */
|
|
5
|
+
export type CanonicalNode = CanonicalInlineNode | CanonicalBlockNode;
|
|
6
|
+
/** Canonical representation of an INLINE (`:`) node. */
|
|
7
|
+
export interface CanonicalInlineNode {
|
|
8
|
+
name: string;
|
|
9
|
+
canonicalName: string;
|
|
10
|
+
namespace: string;
|
|
11
|
+
form: "inline";
|
|
12
|
+
value: string;
|
|
13
|
+
children: CanonicalNode[];
|
|
14
|
+
}
|
|
15
|
+
/** Canonical representation of a BLOCK (`>>`) node. */
|
|
16
|
+
export interface CanonicalBlockNode {
|
|
17
|
+
name: string;
|
|
18
|
+
canonicalName: string;
|
|
19
|
+
namespace: string;
|
|
20
|
+
form: "block";
|
|
21
|
+
lines: string[];
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Converts every root node of a parsed document to the logical tree defined by
|
|
25
|
+
* STXT-TREE-SPEC. The result deliberately excludes source positions, indentation
|
|
26
|
+
* style, comments and derived values such as a qualified name.
|
|
27
|
+
*
|
|
28
|
+
* @param nodes root nodes of an already parsed STXT document.
|
|
29
|
+
* @returns the canonical document tree, ready to be serialized as JSON.
|
|
30
|
+
*/
|
|
31
|
+
export declare function toCanonicalTree(nodes: ReadonlyArray<Node>): CanonicalDocument;
|
|
32
|
+
/**
|
|
33
|
+
* Serializes the canonical tree of a parsed document as human-readable JSON.
|
|
34
|
+
* JSON whitespace is not part of STXT-TREE-SPEC; two-space indentation is this
|
|
35
|
+
* implementation's deterministic presentation for command-line use.
|
|
36
|
+
*
|
|
37
|
+
* @param nodes root nodes of an already parsed STXT document.
|
|
38
|
+
* @returns the canonical document tree encoded as JSON, without a final line break.
|
|
39
|
+
*/
|
|
40
|
+
export declare function toCanonicalJson(nodes: ReadonlyArray<Node>): string;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.toCanonicalTree = toCanonicalTree;
|
|
4
|
+
exports.toCanonicalJson = toCanonicalJson;
|
|
5
|
+
/**
|
|
6
|
+
* Converts every root node of a parsed document to the logical tree defined by
|
|
7
|
+
* STXT-TREE-SPEC. The result deliberately excludes source positions, indentation
|
|
8
|
+
* style, comments and derived values such as a qualified name.
|
|
9
|
+
*
|
|
10
|
+
* @param nodes root nodes of an already parsed STXT document.
|
|
11
|
+
* @returns the canonical document tree, ready to be serialized as JSON.
|
|
12
|
+
*/
|
|
13
|
+
function toCanonicalTree(nodes) {
|
|
14
|
+
return nodes.map(node => toCanonicalNode(node));
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Serializes the canonical tree of a parsed document as human-readable JSON.
|
|
18
|
+
* JSON whitespace is not part of STXT-TREE-SPEC; two-space indentation is this
|
|
19
|
+
* implementation's deterministic presentation for command-line use.
|
|
20
|
+
*
|
|
21
|
+
* @param nodes root nodes of an already parsed STXT document.
|
|
22
|
+
* @returns the canonical document tree encoded as JSON, without a final line break.
|
|
23
|
+
*/
|
|
24
|
+
function toCanonicalJson(nodes) {
|
|
25
|
+
return JSON.stringify(toCanonicalTree(nodes), null, 2);
|
|
26
|
+
}
|
|
27
|
+
function toCanonicalNode(node) {
|
|
28
|
+
if (node.isTextNode()) {
|
|
29
|
+
return {
|
|
30
|
+
name: node.getName(),
|
|
31
|
+
canonicalName: node.getNormalizedName(),
|
|
32
|
+
namespace: node.getNamespace(),
|
|
33
|
+
form: "block",
|
|
34
|
+
lines: [...node.getTextLines()],
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
return {
|
|
38
|
+
name: node.getName(),
|
|
39
|
+
canonicalName: node.getNormalizedName(),
|
|
40
|
+
namespace: node.getNamespace(),
|
|
41
|
+
form: "inline",
|
|
42
|
+
value: node.getValue(),
|
|
43
|
+
children: node.getChildren().map(child => toCanonicalNode(child)),
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=TreeJson.js.map
|
|
@@ -52,9 +52,14 @@ class SchemaProviderMemory {
|
|
|
52
52
|
addSchema(txt) {
|
|
53
53
|
const parser = new Parser_1.Parser();
|
|
54
54
|
const node = parser.parse(txt)[0];
|
|
55
|
-
|
|
55
|
+
// A schema that does not validate against its meta-schema must not be
|
|
56
|
+
// registered (same policy as UnifiedSchemaProvider/DiscoveryResolver)
|
|
56
57
|
const schemaValidator = new SchemaValidator_1.SchemaValidator(new SchemaProviderMeta_1.SchemaProviderMeta(), true);
|
|
57
|
-
schemaValidator.validate(node);
|
|
58
|
+
const errors = schemaValidator.validate(node);
|
|
59
|
+
if (errors.length > 0) {
|
|
60
|
+
throw errors[0];
|
|
61
|
+
}
|
|
62
|
+
const schema = (0, SchemaParser_1.transformNodeToSchema)(node);
|
|
58
63
|
const key = schema.getNamespace();
|
|
59
64
|
this.schemas.set(key, schema);
|
|
60
65
|
}
|
|
@@ -18,7 +18,8 @@ export declare class TemplateSchemaProviderMemory extends SchemaProviderMemory {
|
|
|
18
18
|
*
|
|
19
19
|
* @param template text of the `@stxt.template` document.
|
|
20
20
|
* @throws ValidationException with code `INVALID_SCHEMA` if the document does not hold exactly
|
|
21
|
-
* one template
|
|
21
|
+
* one template or the resulting schema has no namespace, or the first validation error
|
|
22
|
+
* if the template does not validate against the template meta-schema.
|
|
22
23
|
*/
|
|
23
24
|
addTemplate(template: string): void;
|
|
24
25
|
}
|
|
@@ -31,7 +31,8 @@ class TemplateSchemaProviderMemory extends SchemaProviderMemory_1.SchemaProvider
|
|
|
31
31
|
*
|
|
32
32
|
* @param template text of the `@stxt.template` document.
|
|
33
33
|
* @throws ValidationException with code `INVALID_SCHEMA` if the document does not hold exactly
|
|
34
|
-
* one template
|
|
34
|
+
* one template or the resulting schema has no namespace, or the first validation error
|
|
35
|
+
* if the template does not validate against the template meta-schema.
|
|
35
36
|
*/
|
|
36
37
|
addTemplate(template) {
|
|
37
38
|
const parser = new Parser_1.Parser();
|
|
@@ -39,9 +40,13 @@ class TemplateSchemaProviderMemory extends SchemaProviderMemory_1.SchemaProvider
|
|
|
39
40
|
if (nodes.length !== 1) {
|
|
40
41
|
throw new ValidationException_1.ValidationException(0, "INVALID_SCHEMA", `There are ${nodes.length}, and expected is 1`);
|
|
41
42
|
}
|
|
42
|
-
//
|
|
43
|
+
// A template that does not validate against the template meta-schema must not
|
|
44
|
+
// be registered (same policy as UnifiedSchemaProvider/DiscoveryResolver)
|
|
43
45
|
const schemaValidator = new SchemaValidator_1.SchemaValidator(new MetaTemplateSchemaProvider_1.MetaTemplateSchemaProvider(), true);
|
|
44
|
-
schemaValidator.validate(nodes[0]);
|
|
46
|
+
const errors = schemaValidator.validate(nodes[0]);
|
|
47
|
+
if (errors.length > 0) {
|
|
48
|
+
throw errors[0];
|
|
49
|
+
}
|
|
45
50
|
// Build the schema out of the template
|
|
46
51
|
const sch = (0, TemplateParser_1.transformTemplateNodeToSchema)(nodes[0]);
|
|
47
52
|
// Minimum safety check (Java checked the expected namespace here too)
|