@speclynx/apidom-parser-adapter-yaml-1-2 1.12.2 → 2.1.0
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/CHANGELOG.md +24 -0
- package/NOTICE +16 -7
- package/README.md +34 -7
- package/dist/167.apidom-parser-adapter-yaml-1-2.browser.min.js +1 -1
- package/dist/451.apidom-parser-adapter-yaml-1-2.browser.min.js +1 -1
- package/dist/apidom-parser-adapter-yaml-1-2.browser.js +19340 -16731
- package/dist/apidom-parser-adapter-yaml-1-2.browser.min.js +1 -1
- package/package.json +10 -9
- package/src/adapter.cjs +28 -16
- package/src/adapter.mjs +25 -15
- package/src/tree-sitter/index.cjs +44 -0
- package/src/tree-sitter/index.mjs +38 -0
- package/src/{lexical-analysis → tree-sitter/lexical-analysis}/index.cjs +1 -1
- package/src/{lexical-analysis → tree-sitter/lexical-analysis}/index.mjs +1 -1
- package/src/tree-sitter/syntactic-analysis/CstTransformer.cjs +625 -0
- package/src/tree-sitter/syntactic-analysis/CstTransformer.mjs +618 -0
- package/src/tree-sitter/syntactic-analysis/YamlAstTransformer.cjs +271 -0
- package/src/tree-sitter/syntactic-analysis/YamlAstTransformer.mjs +263 -0
- package/src/tree-sitter/syntactic-analysis/ast/Error.cjs +30 -0
- package/src/tree-sitter/syntactic-analysis/ast/Error.mjs +24 -0
- package/src/tree-sitter/syntactic-analysis/ast/Literal.cjs +27 -0
- package/src/tree-sitter/syntactic-analysis/ast/Literal.mjs +21 -0
- package/src/tree-sitter/syntactic-analysis/ast/Node.cjs +60 -0
- package/src/tree-sitter/syntactic-analysis/ast/Node.mjs +56 -0
- package/src/tree-sitter/syntactic-analysis/ast/ParseResult.cjs +17 -0
- package/src/tree-sitter/syntactic-analysis/ast/ParseResult.mjs +12 -0
- package/src/tree-sitter/syntactic-analysis/ast/anchors-aliases/ReferenceManager.cjs +23 -0
- package/src/tree-sitter/syntactic-analysis/ast/anchors-aliases/ReferenceManager.mjs +18 -0
- package/src/tree-sitter/syntactic-analysis/ast/errors/YamlError.cjs +10 -0
- package/src/tree-sitter/syntactic-analysis/ast/errors/YamlError.mjs +7 -0
- package/src/tree-sitter/syntactic-analysis/ast/errors/YamlSchemaError.cjs +11 -0
- package/src/tree-sitter/syntactic-analysis/ast/errors/YamlSchemaError.mjs +6 -0
- package/src/tree-sitter/syntactic-analysis/ast/errors/YamlTagError.cjs +43 -0
- package/src/tree-sitter/syntactic-analysis/ast/errors/YamlTagError.mjs +37 -0
- package/src/tree-sitter/syntactic-analysis/ast/nodes/YamlAlias.cjs +27 -0
- package/src/tree-sitter/syntactic-analysis/ast/nodes/YamlAlias.mjs +21 -0
- package/src/tree-sitter/syntactic-analysis/ast/nodes/YamlAnchor.cjs +27 -0
- package/src/tree-sitter/syntactic-analysis/ast/nodes/YamlAnchor.mjs +21 -0
- package/src/tree-sitter/syntactic-analysis/ast/nodes/YamlCollection.cjs +11 -0
- package/src/tree-sitter/syntactic-analysis/ast/nodes/YamlCollection.mjs +6 -0
- package/src/tree-sitter/syntactic-analysis/ast/nodes/YamlComment.cjs +27 -0
- package/src/tree-sitter/syntactic-analysis/ast/nodes/YamlComment.mjs +21 -0
- package/src/tree-sitter/syntactic-analysis/ast/nodes/YamlDirective.cjs +39 -0
- package/src/tree-sitter/syntactic-analysis/ast/nodes/YamlDirective.mjs +32 -0
- package/src/tree-sitter/syntactic-analysis/ast/nodes/YamlDocument.cjs +13 -0
- package/src/tree-sitter/syntactic-analysis/ast/nodes/YamlDocument.mjs +8 -0
- package/src/tree-sitter/syntactic-analysis/ast/nodes/YamlKeyValuePair.cjs +48 -0
- package/src/tree-sitter/syntactic-analysis/ast/nodes/YamlKeyValuePair.mjs +42 -0
- package/src/tree-sitter/syntactic-analysis/ast/nodes/YamlMapping.cjs +20 -0
- package/src/tree-sitter/syntactic-analysis/ast/nodes/YamlMapping.mjs +15 -0
- package/src/tree-sitter/syntactic-analysis/ast/nodes/YamlNode.cjs +35 -0
- package/src/tree-sitter/syntactic-analysis/ast/nodes/YamlNode.mjs +29 -0
- package/src/tree-sitter/syntactic-analysis/ast/nodes/YamlScalar.cjs +27 -0
- package/src/tree-sitter/syntactic-analysis/ast/nodes/YamlScalar.mjs +21 -0
- package/src/tree-sitter/syntactic-analysis/ast/nodes/YamlSequence.cjs +23 -0
- package/src/tree-sitter/syntactic-analysis/ast/nodes/YamlSequence.mjs +18 -0
- package/src/tree-sitter/syntactic-analysis/ast/nodes/YamlStream.cjs +20 -0
- package/src/tree-sitter/syntactic-analysis/ast/nodes/YamlStream.mjs +15 -0
- package/src/tree-sitter/syntactic-analysis/ast/nodes/YamlStyle.cjs +27 -0
- package/src/tree-sitter/syntactic-analysis/ast/nodes/YamlStyle.mjs +24 -0
- package/src/tree-sitter/syntactic-analysis/ast/nodes/YamlTag.cjs +38 -0
- package/src/tree-sitter/syntactic-analysis/ast/nodes/YamlTag.mjs +35 -0
- package/src/tree-sitter/syntactic-analysis/ast/nodes/predicates.cjs +26 -0
- package/src/tree-sitter/syntactic-analysis/ast/nodes/predicates.mjs +14 -0
- package/src/tree-sitter/syntactic-analysis/ast/schemas/ScalarTag.cjs +33 -0
- package/src/tree-sitter/syntactic-analysis/ast/schemas/ScalarTag.mjs +29 -0
- package/src/tree-sitter/syntactic-analysis/ast/schemas/Tag.cjs +20 -0
- package/src/tree-sitter/syntactic-analysis/ast/schemas/Tag.mjs +16 -0
- package/src/tree-sitter/syntactic-analysis/ast/schemas/canonical-format.cjs +127 -0
- package/src/tree-sitter/syntactic-analysis/ast/schemas/canonical-format.mjs +122 -0
- package/src/tree-sitter/syntactic-analysis/ast/schemas/failsafe/GenericMapping.cjs +14 -0
- package/src/tree-sitter/syntactic-analysis/ast/schemas/failsafe/GenericMapping.mjs +9 -0
- package/src/tree-sitter/syntactic-analysis/ast/schemas/failsafe/GenericSequence.cjs +14 -0
- package/src/tree-sitter/syntactic-analysis/ast/schemas/failsafe/GenericSequence.mjs +9 -0
- package/src/tree-sitter/syntactic-analysis/ast/schemas/failsafe/GenericString.cjs +10 -0
- package/src/tree-sitter/syntactic-analysis/ast/schemas/failsafe/GenericString.mjs +5 -0
- package/src/tree-sitter/syntactic-analysis/ast/schemas/failsafe/index.cjs +116 -0
- package/src/tree-sitter/syntactic-analysis/ast/schemas/failsafe/index.mjs +111 -0
- package/src/tree-sitter/syntactic-analysis/ast/schemas/json/Boolean.cjs +19 -0
- package/src/tree-sitter/syntactic-analysis/ast/schemas/json/Boolean.mjs +14 -0
- package/src/tree-sitter/syntactic-analysis/ast/schemas/json/FloatingPoint.cjs +19 -0
- package/src/tree-sitter/syntactic-analysis/ast/schemas/json/FloatingPoint.mjs +14 -0
- package/src/tree-sitter/syntactic-analysis/ast/schemas/json/Integer.cjs +19 -0
- package/src/tree-sitter/syntactic-analysis/ast/schemas/json/Integer.mjs +14 -0
- package/src/tree-sitter/syntactic-analysis/ast/schemas/json/Null.cjs +18 -0
- package/src/tree-sitter/syntactic-analysis/ast/schemas/json/Null.mjs +13 -0
- package/src/tree-sitter/syntactic-analysis/ast/schemas/json/index.cjs +43 -0
- package/src/tree-sitter/syntactic-analysis/ast/schemas/json/index.mjs +38 -0
- package/src/tree-sitter/syntactic-analysis/index.cjs +39 -0
- package/src/tree-sitter/syntactic-analysis/index.mjs +33 -0
- package/src/yaml/index.cjs +31 -0
- package/src/yaml/index.mjs +26 -0
- package/types/apidom-parser-adapter-yaml-1-2.d.ts +11 -3
- package/src/syntactic-analysis/TreeCursorIterator.cjs +0 -93
- package/src/syntactic-analysis/TreeCursorIterator.mjs +0 -88
- package/src/syntactic-analysis/TreeCursorSyntaxNode.cjs +0 -80
- package/src/syntactic-analysis/TreeCursorSyntaxNode.mjs +0 -76
- package/src/syntactic-analysis/indirect/index.cjs +0 -51
- package/src/syntactic-analysis/indirect/index.mjs +0 -44
- package/src/syntactic-analysis/indirect/visitors/CstVisitor.cjs +0 -553
- package/src/syntactic-analysis/indirect/visitors/CstVisitor.mjs +0 -547
- package/src/syntactic-analysis/indirect/visitors/YamlAstVisitor.cjs +0 -164
- package/src/syntactic-analysis/indirect/visitors/YamlAstVisitor.mjs +0 -158
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault").default;
|
|
4
|
+
exports.__esModule = true;
|
|
5
|
+
exports.default = void 0;
|
|
6
|
+
var _index = _interopRequireDefault(require("./ast/schemas/json/index.cjs"));
|
|
7
|
+
var _ReferenceManager = _interopRequireDefault(require("./ast/anchors-aliases/ReferenceManager.cjs"));
|
|
8
|
+
var _CstTransformer = _interopRequireDefault(require("./CstTransformer.cjs"));
|
|
9
|
+
var _YamlAstTransformer = require("./YamlAstTransformer.cjs");
|
|
10
|
+
/**
|
|
11
|
+
* @public
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* This version of syntactic analysis does following transformations:
|
|
16
|
+
* `TreeSitter CST -> YAML AST -> ApiDOM`
|
|
17
|
+
* Two traversals passes are needed to get from CST to ApiDOM.
|
|
18
|
+
* @public
|
|
19
|
+
*/
|
|
20
|
+
const analyze = (cst, {
|
|
21
|
+
sourceMap = false
|
|
22
|
+
} = {}) => {
|
|
23
|
+
const cursor = cst.walk();
|
|
24
|
+
const schema = new _index.default();
|
|
25
|
+
const referenceManager = new _ReferenceManager.default();
|
|
26
|
+
|
|
27
|
+
// Pass 1: CST -> YAML AST (direct cursor-based transformation)
|
|
28
|
+
const yamlAst = (0, _CstTransformer.default)(cursor, {
|
|
29
|
+
schema,
|
|
30
|
+
sourceMap,
|
|
31
|
+
referenceManager
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
// Pass 2: YAML AST -> ApiDOM (direct transformation)
|
|
35
|
+
return (0, _YamlAstTransformer.transformYamlAstToApiDOM)(yamlAst, {
|
|
36
|
+
sourceMap
|
|
37
|
+
});
|
|
38
|
+
};
|
|
39
|
+
var _default = exports.default = analyze;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import JsonSchema from "./ast/schemas/json/index.mjs";
|
|
2
|
+
import YamlReferenceManager from "./ast/anchors-aliases/ReferenceManager.mjs";
|
|
3
|
+
import transformCstToYamlAst from "./CstTransformer.mjs";
|
|
4
|
+
import { transformYamlAstToApiDOM } from "./YamlAstTransformer.mjs";
|
|
5
|
+
/**
|
|
6
|
+
* @public
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* This version of syntactic analysis does following transformations:
|
|
10
|
+
* `TreeSitter CST -> YAML AST -> ApiDOM`
|
|
11
|
+
* Two traversals passes are needed to get from CST to ApiDOM.
|
|
12
|
+
* @public
|
|
13
|
+
*/
|
|
14
|
+
const analyze = (cst, {
|
|
15
|
+
sourceMap = false
|
|
16
|
+
} = {}) => {
|
|
17
|
+
const cursor = cst.walk();
|
|
18
|
+
const schema = new JsonSchema();
|
|
19
|
+
const referenceManager = new YamlReferenceManager();
|
|
20
|
+
|
|
21
|
+
// Pass 1: CST -> YAML AST (direct cursor-based transformation)
|
|
22
|
+
const yamlAst = transformCstToYamlAst(cursor, {
|
|
23
|
+
schema,
|
|
24
|
+
sourceMap,
|
|
25
|
+
referenceManager
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
// Pass 2: YAML AST -> ApiDOM (direct transformation)
|
|
29
|
+
return transformYamlAstToApiDOM(yamlAst, {
|
|
30
|
+
sourceMap
|
|
31
|
+
});
|
|
32
|
+
};
|
|
33
|
+
export default analyze;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
exports.__esModule = true;
|
|
4
|
+
exports.parse = exports.detect = void 0;
|
|
5
|
+
var _yaml = require("yaml");
|
|
6
|
+
var _apidomDatamodel = require("@speclynx/apidom-datamodel");
|
|
7
|
+
/**
|
|
8
|
+
* @public
|
|
9
|
+
*/
|
|
10
|
+
const detect = async source => {
|
|
11
|
+
try {
|
|
12
|
+
(0, _yaml.parse)(source);
|
|
13
|
+
return true;
|
|
14
|
+
} catch {
|
|
15
|
+
return false;
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* @public
|
|
21
|
+
*/
|
|
22
|
+
exports.detect = detect;
|
|
23
|
+
const parse = async source => {
|
|
24
|
+
const pojo = (0, _yaml.parse)(source);
|
|
25
|
+
const element = (0, _apidomDatamodel.refract)(pojo);
|
|
26
|
+
const parseResult = new _apidomDatamodel.ParseResultElement();
|
|
27
|
+
element.classes.push('result');
|
|
28
|
+
parseResult.push(element);
|
|
29
|
+
return parseResult;
|
|
30
|
+
};
|
|
31
|
+
exports.parse = parse;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { parse as parseYaml } from 'yaml';
|
|
2
|
+
import { ParseResultElement, refract } from '@speclynx/apidom-datamodel';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @public
|
|
6
|
+
*/
|
|
7
|
+
export const detect = async source => {
|
|
8
|
+
try {
|
|
9
|
+
parseYaml(source);
|
|
10
|
+
return true;
|
|
11
|
+
} catch {
|
|
12
|
+
return false;
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* @public
|
|
18
|
+
*/
|
|
19
|
+
export const parse = async source => {
|
|
20
|
+
const pojo = parseYaml(source);
|
|
21
|
+
const element = refract(pojo);
|
|
22
|
+
const parseResult = new ParseResultElement();
|
|
23
|
+
element.classes.push('result');
|
|
24
|
+
parseResult.push(element);
|
|
25
|
+
return parseResult;
|
|
26
|
+
};
|
|
@@ -1,12 +1,19 @@
|
|
|
1
1
|
import { MediaTypes } from '@speclynx/apidom-core';
|
|
2
|
-
import { Namespace } from '@speclynx/apidom-
|
|
3
|
-
import { ParseResultElement } from '@speclynx/apidom-
|
|
2
|
+
import { Namespace } from '@speclynx/apidom-datamodel';
|
|
3
|
+
import { ParseResultElement } from '@speclynx/apidom-datamodel';
|
|
4
4
|
import { Tree } from 'web-tree-sitter';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* @public
|
|
8
8
|
*/
|
|
9
|
-
export declare const detect: (source: string) => Promise<boolean>;
|
|
9
|
+
export declare const detect: (source: string, { strict }?: DetectOptions) => Promise<boolean>;
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* @public
|
|
13
|
+
*/
|
|
14
|
+
export declare interface DetectOptions {
|
|
15
|
+
strict?: boolean;
|
|
16
|
+
}
|
|
10
17
|
|
|
11
18
|
/**
|
|
12
19
|
* Lexical Analysis of source string using WebTreeSitter.
|
|
@@ -43,6 +50,7 @@ export declare type ParseFunction = (source: string, options?: ParseFunctionOpti
|
|
|
43
50
|
*/
|
|
44
51
|
export declare interface ParseFunctionOptions {
|
|
45
52
|
sourceMap?: boolean;
|
|
53
|
+
strict?: boolean;
|
|
46
54
|
}
|
|
47
55
|
|
|
48
56
|
/**
|
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault").default;
|
|
4
|
-
exports.__esModule = true;
|
|
5
|
-
exports.default = void 0;
|
|
6
|
-
var _TreeCursorSyntaxNode = _interopRequireDefault(require("./TreeCursorSyntaxNode.cjs"));
|
|
7
|
-
class TreeCursorIterator {
|
|
8
|
-
cursor;
|
|
9
|
-
constructor(cursor) {
|
|
10
|
-
this.cursor = cursor;
|
|
11
|
-
}
|
|
12
|
-
stream() {
|
|
13
|
-
return new _TreeCursorSyntaxNode.default(this.cursor);
|
|
14
|
-
}
|
|
15
|
-
yaml_directive() {
|
|
16
|
-
return new _TreeCursorSyntaxNode.default(this.cursor);
|
|
17
|
-
}
|
|
18
|
-
tag_directive() {
|
|
19
|
-
return new _TreeCursorSyntaxNode.default(this.cursor);
|
|
20
|
-
}
|
|
21
|
-
reserved_directive() {
|
|
22
|
-
return new _TreeCursorSyntaxNode.default(this.cursor);
|
|
23
|
-
}
|
|
24
|
-
document() {
|
|
25
|
-
return new _TreeCursorSyntaxNode.default(this.cursor);
|
|
26
|
-
}
|
|
27
|
-
block_node() {
|
|
28
|
-
return new _TreeCursorSyntaxNode.default(this.cursor).setFieldName(this.cursor);
|
|
29
|
-
}
|
|
30
|
-
flow_node() {
|
|
31
|
-
return new _TreeCursorSyntaxNode.default(this.cursor).setFieldName(this.cursor);
|
|
32
|
-
}
|
|
33
|
-
block_mapping() {
|
|
34
|
-
return new _TreeCursorSyntaxNode.default(this.cursor);
|
|
35
|
-
}
|
|
36
|
-
block_mapping_pair() {
|
|
37
|
-
return new _TreeCursorSyntaxNode.default(this.cursor);
|
|
38
|
-
}
|
|
39
|
-
flow_mapping() {
|
|
40
|
-
return new _TreeCursorSyntaxNode.default(this.cursor);
|
|
41
|
-
}
|
|
42
|
-
flow_pair() {
|
|
43
|
-
return new _TreeCursorSyntaxNode.default(this.cursor);
|
|
44
|
-
}
|
|
45
|
-
block_sequence() {
|
|
46
|
-
return new _TreeCursorSyntaxNode.default(this.cursor);
|
|
47
|
-
}
|
|
48
|
-
block_sequence_item() {
|
|
49
|
-
return new _TreeCursorSyntaxNode.default(this.cursor);
|
|
50
|
-
}
|
|
51
|
-
flow_sequence() {
|
|
52
|
-
return new _TreeCursorSyntaxNode.default(this.cursor);
|
|
53
|
-
}
|
|
54
|
-
plain_scalar() {
|
|
55
|
-
return new _TreeCursorSyntaxNode.default(this.cursor);
|
|
56
|
-
}
|
|
57
|
-
single_quote_scalar() {
|
|
58
|
-
return new _TreeCursorSyntaxNode.default(this.cursor);
|
|
59
|
-
}
|
|
60
|
-
double_quote_scalar() {
|
|
61
|
-
return new _TreeCursorSyntaxNode.default(this.cursor);
|
|
62
|
-
}
|
|
63
|
-
block_scalar() {
|
|
64
|
-
return new _TreeCursorSyntaxNode.default(this.cursor);
|
|
65
|
-
}
|
|
66
|
-
ERROR() {
|
|
67
|
-
return new _TreeCursorSyntaxNode.default(this.cursor).setHasError(this.cursor);
|
|
68
|
-
}
|
|
69
|
-
*[Symbol.iterator]() {
|
|
70
|
-
let node;
|
|
71
|
-
if (this.cursor.nodeType in this) {
|
|
72
|
-
// @ts-ignore
|
|
73
|
-
node = this[this.cursor.nodeType]();
|
|
74
|
-
} else {
|
|
75
|
-
node = new _TreeCursorSyntaxNode.default(this.cursor);
|
|
76
|
-
}
|
|
77
|
-
if (this.cursor.gotoFirstChild()) {
|
|
78
|
-
const [firstChild] = new TreeCursorIterator(this.cursor);
|
|
79
|
-
node.pushChildren(firstChild);
|
|
80
|
-
while (this.cursor.gotoNextSibling()) {
|
|
81
|
-
const firstChildSiblings = Array.from(new TreeCursorIterator(this.cursor));
|
|
82
|
-
node.pushChildren(...firstChildSiblings);
|
|
83
|
-
}
|
|
84
|
-
node.children.reduce((previousNode, currentNode) => {
|
|
85
|
-
currentNode.setPreviousSibling(previousNode);
|
|
86
|
-
return currentNode;
|
|
87
|
-
}, undefined);
|
|
88
|
-
this.cursor.gotoParent();
|
|
89
|
-
}
|
|
90
|
-
yield node;
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
var _default = exports.default = TreeCursorIterator;
|
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
import TreeCursorSyntaxNode from "./TreeCursorSyntaxNode.mjs";
|
|
2
|
-
class TreeCursorIterator {
|
|
3
|
-
cursor;
|
|
4
|
-
constructor(cursor) {
|
|
5
|
-
this.cursor = cursor;
|
|
6
|
-
}
|
|
7
|
-
stream() {
|
|
8
|
-
return new TreeCursorSyntaxNode(this.cursor);
|
|
9
|
-
}
|
|
10
|
-
yaml_directive() {
|
|
11
|
-
return new TreeCursorSyntaxNode(this.cursor);
|
|
12
|
-
}
|
|
13
|
-
tag_directive() {
|
|
14
|
-
return new TreeCursorSyntaxNode(this.cursor);
|
|
15
|
-
}
|
|
16
|
-
reserved_directive() {
|
|
17
|
-
return new TreeCursorSyntaxNode(this.cursor);
|
|
18
|
-
}
|
|
19
|
-
document() {
|
|
20
|
-
return new TreeCursorSyntaxNode(this.cursor);
|
|
21
|
-
}
|
|
22
|
-
block_node() {
|
|
23
|
-
return new TreeCursorSyntaxNode(this.cursor).setFieldName(this.cursor);
|
|
24
|
-
}
|
|
25
|
-
flow_node() {
|
|
26
|
-
return new TreeCursorSyntaxNode(this.cursor).setFieldName(this.cursor);
|
|
27
|
-
}
|
|
28
|
-
block_mapping() {
|
|
29
|
-
return new TreeCursorSyntaxNode(this.cursor);
|
|
30
|
-
}
|
|
31
|
-
block_mapping_pair() {
|
|
32
|
-
return new TreeCursorSyntaxNode(this.cursor);
|
|
33
|
-
}
|
|
34
|
-
flow_mapping() {
|
|
35
|
-
return new TreeCursorSyntaxNode(this.cursor);
|
|
36
|
-
}
|
|
37
|
-
flow_pair() {
|
|
38
|
-
return new TreeCursorSyntaxNode(this.cursor);
|
|
39
|
-
}
|
|
40
|
-
block_sequence() {
|
|
41
|
-
return new TreeCursorSyntaxNode(this.cursor);
|
|
42
|
-
}
|
|
43
|
-
block_sequence_item() {
|
|
44
|
-
return new TreeCursorSyntaxNode(this.cursor);
|
|
45
|
-
}
|
|
46
|
-
flow_sequence() {
|
|
47
|
-
return new TreeCursorSyntaxNode(this.cursor);
|
|
48
|
-
}
|
|
49
|
-
plain_scalar() {
|
|
50
|
-
return new TreeCursorSyntaxNode(this.cursor);
|
|
51
|
-
}
|
|
52
|
-
single_quote_scalar() {
|
|
53
|
-
return new TreeCursorSyntaxNode(this.cursor);
|
|
54
|
-
}
|
|
55
|
-
double_quote_scalar() {
|
|
56
|
-
return new TreeCursorSyntaxNode(this.cursor);
|
|
57
|
-
}
|
|
58
|
-
block_scalar() {
|
|
59
|
-
return new TreeCursorSyntaxNode(this.cursor);
|
|
60
|
-
}
|
|
61
|
-
ERROR() {
|
|
62
|
-
return new TreeCursorSyntaxNode(this.cursor).setHasError(this.cursor);
|
|
63
|
-
}
|
|
64
|
-
*[Symbol.iterator]() {
|
|
65
|
-
let node;
|
|
66
|
-
if (this.cursor.nodeType in this) {
|
|
67
|
-
// @ts-ignore
|
|
68
|
-
node = this[this.cursor.nodeType]();
|
|
69
|
-
} else {
|
|
70
|
-
node = new TreeCursorSyntaxNode(this.cursor);
|
|
71
|
-
}
|
|
72
|
-
if (this.cursor.gotoFirstChild()) {
|
|
73
|
-
const [firstChild] = new TreeCursorIterator(this.cursor);
|
|
74
|
-
node.pushChildren(firstChild);
|
|
75
|
-
while (this.cursor.gotoNextSibling()) {
|
|
76
|
-
const firstChildSiblings = Array.from(new TreeCursorIterator(this.cursor));
|
|
77
|
-
node.pushChildren(...firstChildSiblings);
|
|
78
|
-
}
|
|
79
|
-
node.children.reduce((previousNode, currentNode) => {
|
|
80
|
-
currentNode.setPreviousSibling(previousNode);
|
|
81
|
-
return currentNode;
|
|
82
|
-
}, undefined);
|
|
83
|
-
this.cursor.gotoParent();
|
|
84
|
-
}
|
|
85
|
-
yield node;
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
export default TreeCursorIterator;
|
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
exports.__esModule = true;
|
|
4
|
-
exports.default = void 0;
|
|
5
|
-
class TreeCursorSyntaxNode {
|
|
6
|
-
type;
|
|
7
|
-
startPosition;
|
|
8
|
-
endPosition;
|
|
9
|
-
startIndex;
|
|
10
|
-
endIndex;
|
|
11
|
-
text;
|
|
12
|
-
isNamed;
|
|
13
|
-
isMissing;
|
|
14
|
-
fieldName = null;
|
|
15
|
-
hasError = false;
|
|
16
|
-
children = [];
|
|
17
|
-
previousSibling;
|
|
18
|
-
constructor(cursor) {
|
|
19
|
-
this.type = cursor.nodeType;
|
|
20
|
-
this.startPosition = cursor.startPosition;
|
|
21
|
-
this.endPosition = cursor.endPosition;
|
|
22
|
-
this.startIndex = cursor.startIndex;
|
|
23
|
-
this.endIndex = cursor.endIndex;
|
|
24
|
-
this.text = cursor.nodeText;
|
|
25
|
-
this.isNamed = cursor.nodeIsNamed;
|
|
26
|
-
this.isMissing = cursor.nodeIsMissing;
|
|
27
|
-
}
|
|
28
|
-
get keyNode() {
|
|
29
|
-
if (this.type === 'flow_pair' || this.type === 'block_mapping_pair') {
|
|
30
|
-
return this.children.find(node => node.fieldName === 'key');
|
|
31
|
-
}
|
|
32
|
-
return undefined;
|
|
33
|
-
}
|
|
34
|
-
get valueNode() {
|
|
35
|
-
if (this.type === 'flow_pair' || this.type === 'block_mapping_pair') {
|
|
36
|
-
return this.children.find(node => node.fieldName === 'value');
|
|
37
|
-
}
|
|
38
|
-
return undefined;
|
|
39
|
-
}
|
|
40
|
-
get tag() {
|
|
41
|
-
let {
|
|
42
|
-
previousSibling
|
|
43
|
-
} = this;
|
|
44
|
-
while (typeof previousSibling !== 'undefined' && previousSibling.type !== 'tag') {
|
|
45
|
-
({
|
|
46
|
-
previousSibling
|
|
47
|
-
} = previousSibling);
|
|
48
|
-
}
|
|
49
|
-
return previousSibling;
|
|
50
|
-
}
|
|
51
|
-
get anchor() {
|
|
52
|
-
let {
|
|
53
|
-
previousSibling
|
|
54
|
-
} = this;
|
|
55
|
-
while (typeof previousSibling !== 'undefined' && previousSibling.type !== 'anchor') {
|
|
56
|
-
({
|
|
57
|
-
previousSibling
|
|
58
|
-
} = previousSibling);
|
|
59
|
-
}
|
|
60
|
-
return previousSibling;
|
|
61
|
-
}
|
|
62
|
-
get firstNamedChild() {
|
|
63
|
-
return this.children.find(node => node.isNamed);
|
|
64
|
-
}
|
|
65
|
-
setFieldName(cursor) {
|
|
66
|
-
this.fieldName = cursor.currentFieldName;
|
|
67
|
-
return this;
|
|
68
|
-
}
|
|
69
|
-
setHasError(cursor) {
|
|
70
|
-
this.hasError = cursor.currentNode.hasError;
|
|
71
|
-
return this;
|
|
72
|
-
}
|
|
73
|
-
setPreviousSibling(previousSibling) {
|
|
74
|
-
this.previousSibling = previousSibling;
|
|
75
|
-
}
|
|
76
|
-
pushChildren(...children) {
|
|
77
|
-
this.children.push(...children);
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
var _default = exports.default = TreeCursorSyntaxNode;
|
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
class TreeCursorSyntaxNode {
|
|
2
|
-
type;
|
|
3
|
-
startPosition;
|
|
4
|
-
endPosition;
|
|
5
|
-
startIndex;
|
|
6
|
-
endIndex;
|
|
7
|
-
text;
|
|
8
|
-
isNamed;
|
|
9
|
-
isMissing;
|
|
10
|
-
fieldName = null;
|
|
11
|
-
hasError = false;
|
|
12
|
-
children = [];
|
|
13
|
-
previousSibling;
|
|
14
|
-
constructor(cursor) {
|
|
15
|
-
this.type = cursor.nodeType;
|
|
16
|
-
this.startPosition = cursor.startPosition;
|
|
17
|
-
this.endPosition = cursor.endPosition;
|
|
18
|
-
this.startIndex = cursor.startIndex;
|
|
19
|
-
this.endIndex = cursor.endIndex;
|
|
20
|
-
this.text = cursor.nodeText;
|
|
21
|
-
this.isNamed = cursor.nodeIsNamed;
|
|
22
|
-
this.isMissing = cursor.nodeIsMissing;
|
|
23
|
-
}
|
|
24
|
-
get keyNode() {
|
|
25
|
-
if (this.type === 'flow_pair' || this.type === 'block_mapping_pair') {
|
|
26
|
-
return this.children.find(node => node.fieldName === 'key');
|
|
27
|
-
}
|
|
28
|
-
return undefined;
|
|
29
|
-
}
|
|
30
|
-
get valueNode() {
|
|
31
|
-
if (this.type === 'flow_pair' || this.type === 'block_mapping_pair') {
|
|
32
|
-
return this.children.find(node => node.fieldName === 'value');
|
|
33
|
-
}
|
|
34
|
-
return undefined;
|
|
35
|
-
}
|
|
36
|
-
get tag() {
|
|
37
|
-
let {
|
|
38
|
-
previousSibling
|
|
39
|
-
} = this;
|
|
40
|
-
while (typeof previousSibling !== 'undefined' && previousSibling.type !== 'tag') {
|
|
41
|
-
({
|
|
42
|
-
previousSibling
|
|
43
|
-
} = previousSibling);
|
|
44
|
-
}
|
|
45
|
-
return previousSibling;
|
|
46
|
-
}
|
|
47
|
-
get anchor() {
|
|
48
|
-
let {
|
|
49
|
-
previousSibling
|
|
50
|
-
} = this;
|
|
51
|
-
while (typeof previousSibling !== 'undefined' && previousSibling.type !== 'anchor') {
|
|
52
|
-
({
|
|
53
|
-
previousSibling
|
|
54
|
-
} = previousSibling);
|
|
55
|
-
}
|
|
56
|
-
return previousSibling;
|
|
57
|
-
}
|
|
58
|
-
get firstNamedChild() {
|
|
59
|
-
return this.children.find(node => node.isNamed);
|
|
60
|
-
}
|
|
61
|
-
setFieldName(cursor) {
|
|
62
|
-
this.fieldName = cursor.currentFieldName;
|
|
63
|
-
return this;
|
|
64
|
-
}
|
|
65
|
-
setHasError(cursor) {
|
|
66
|
-
this.hasError = cursor.currentNode.hasError;
|
|
67
|
-
return this;
|
|
68
|
-
}
|
|
69
|
-
setPreviousSibling(previousSibling) {
|
|
70
|
-
this.previousSibling = previousSibling;
|
|
71
|
-
}
|
|
72
|
-
pushChildren(...children) {
|
|
73
|
-
this.children.push(...children);
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
export default TreeCursorSyntaxNode;
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault").default;
|
|
4
|
-
var _interopRequireWildcard = require("@babel/runtime-corejs3/helpers/interopRequireWildcard").default;
|
|
5
|
-
exports.__esModule = true;
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
var _apidomAst = require("@speclynx/apidom-ast");
|
|
8
|
-
var _CstVisitor = _interopRequireWildcard(require("./visitors/CstVisitor.cjs"));
|
|
9
|
-
var _YamlAstVisitor = _interopRequireWildcard(require("./visitors/YamlAstVisitor.cjs"));
|
|
10
|
-
var _TreeCursorIterator = _interopRequireDefault(require("../TreeCursorIterator.cjs"));
|
|
11
|
-
/**
|
|
12
|
-
* @public
|
|
13
|
-
*/
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* This version of syntactic analysis does following transformations:
|
|
17
|
-
* `TreeSitter CST -> YAML AST -> ApiDOM`
|
|
18
|
-
* Two traversals passes are needed to get from CST to ApiDOM.
|
|
19
|
-
* @public
|
|
20
|
-
*/
|
|
21
|
-
const analyze = (cst, {
|
|
22
|
-
sourceMap = false
|
|
23
|
-
} = {}) => {
|
|
24
|
-
const cursor = cst.walk();
|
|
25
|
-
const iterator = new _TreeCursorIterator.default(cursor);
|
|
26
|
-
const [rootNode] = Array.from(iterator);
|
|
27
|
-
const cstVisitor = new _CstVisitor.default();
|
|
28
|
-
const astVisitor = new _YamlAstVisitor.default();
|
|
29
|
-
const schema = new _apidomAst.YamlJsonSchema();
|
|
30
|
-
const referenceManager = new _apidomAst.YamlReferenceManager();
|
|
31
|
-
const yamlAst = (0, _apidomAst.visit)(rootNode, cstVisitor, {
|
|
32
|
-
// @ts-ignore
|
|
33
|
-
keyMap: _CstVisitor.keyMap,
|
|
34
|
-
nodePredicate: _CstVisitor.isNode,
|
|
35
|
-
state: {
|
|
36
|
-
schema,
|
|
37
|
-
sourceMap,
|
|
38
|
-
referenceManager
|
|
39
|
-
}
|
|
40
|
-
});
|
|
41
|
-
return (0, _apidomAst.visit)(yamlAst.rootNode, astVisitor, {
|
|
42
|
-
// @ts-ignore
|
|
43
|
-
keyMap: _YamlAstVisitor.keyMap,
|
|
44
|
-
nodeTypeGetter: _YamlAstVisitor.getNodeType,
|
|
45
|
-
nodePredicate: _YamlAstVisitor.isNode,
|
|
46
|
-
state: {
|
|
47
|
-
sourceMap
|
|
48
|
-
}
|
|
49
|
-
});
|
|
50
|
-
};
|
|
51
|
-
var _default = exports.default = analyze;
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import { visit, YamlJsonSchema as JsonSchema, YamlReferenceManager } from '@speclynx/apidom-ast';
|
|
2
|
-
import CstVisitor, { keyMap as cstKeyMap, isNode as isCstNode } from "./visitors/CstVisitor.mjs";
|
|
3
|
-
import YamlAstVisitor, { keyMap as astKeyMap, isNode as isAstNode, getNodeType as getAstNodeType } from "./visitors/YamlAstVisitor.mjs";
|
|
4
|
-
import TreeCursorIterator from "../TreeCursorIterator.mjs";
|
|
5
|
-
/**
|
|
6
|
-
* @public
|
|
7
|
-
*/
|
|
8
|
-
/**
|
|
9
|
-
* This version of syntactic analysis does following transformations:
|
|
10
|
-
* `TreeSitter CST -> YAML AST -> ApiDOM`
|
|
11
|
-
* Two traversals passes are needed to get from CST to ApiDOM.
|
|
12
|
-
* @public
|
|
13
|
-
*/
|
|
14
|
-
const analyze = (cst, {
|
|
15
|
-
sourceMap = false
|
|
16
|
-
} = {}) => {
|
|
17
|
-
const cursor = cst.walk();
|
|
18
|
-
const iterator = new TreeCursorIterator(cursor);
|
|
19
|
-
const [rootNode] = Array.from(iterator);
|
|
20
|
-
const cstVisitor = new CstVisitor();
|
|
21
|
-
const astVisitor = new YamlAstVisitor();
|
|
22
|
-
const schema = new JsonSchema();
|
|
23
|
-
const referenceManager = new YamlReferenceManager();
|
|
24
|
-
const yamlAst = visit(rootNode, cstVisitor, {
|
|
25
|
-
// @ts-ignore
|
|
26
|
-
keyMap: cstKeyMap,
|
|
27
|
-
nodePredicate: isCstNode,
|
|
28
|
-
state: {
|
|
29
|
-
schema,
|
|
30
|
-
sourceMap,
|
|
31
|
-
referenceManager
|
|
32
|
-
}
|
|
33
|
-
});
|
|
34
|
-
return visit(yamlAst.rootNode, astVisitor, {
|
|
35
|
-
// @ts-ignore
|
|
36
|
-
keyMap: astKeyMap,
|
|
37
|
-
nodeTypeGetter: getAstNodeType,
|
|
38
|
-
nodePredicate: isAstNode,
|
|
39
|
-
state: {
|
|
40
|
-
sourceMap
|
|
41
|
-
}
|
|
42
|
-
});
|
|
43
|
-
};
|
|
44
|
-
export default analyze;
|