@traqula/parser-sparql-1-2 0.0.21 → 0.0.22

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.
@@ -0,0 +1,58 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var Parser_exports = {};
20
+ __export(Parser_exports, {
21
+ Parser: () => Parser,
22
+ sparql12ParserBuilder: () => sparql12ParserBuilder
23
+ });
24
+ module.exports = __toCommonJS(Parser_exports);
25
+ var import_core = require("@traqula/core");
26
+ var import_parser_sparql_1_1 = require("@traqula/parser-sparql-1-1");
27
+ var import_rules_sparql_1_1 = require("@traqula/rules-sparql-1-1");
28
+ var import_rules_sparql_1_2 = require("@traqula/rules-sparql-1-2");
29
+ const sparql12ParserBuilder = import_core.ParserBuilder.create(import_parser_sparql_1_1.sparql11ParserBuilder).widenContext().typePatch().addMany(import_rules_sparql_1_2.gram.reifiedTripleBlock, import_rules_sparql_1_2.gram.reifiedTripleBlockPath, import_rules_sparql_1_2.gram.reifier, import_rules_sparql_1_2.gram.varOrReifierId, import_rules_sparql_1_2.gram.annotation, import_rules_sparql_1_2.gram.annotationPath, import_rules_sparql_1_2.gram.annotationBlockPath, import_rules_sparql_1_2.gram.annotationBlock, import_rules_sparql_1_2.gram.reifiedTriple, import_rules_sparql_1_2.gram.reifiedTripleSubject, import_rules_sparql_1_2.gram.reifiedTripleObject, import_rules_sparql_1_2.gram.tripleTerm, import_rules_sparql_1_2.gram.tripleTermSubject, import_rules_sparql_1_2.gram.tripleTermObject, import_rules_sparql_1_2.gram.tripleTermData, import_rules_sparql_1_2.gram.tripleTermDataSubject, import_rules_sparql_1_2.gram.tripleTermDataObject, import_rules_sparql_1_2.gram.exprTripleTerm, import_rules_sparql_1_2.gram.exprTripleTermSubject, import_rules_sparql_1_2.gram.exprTripleTermObject).addMany(import_rules_sparql_1_2.gram.versionDecl, import_rules_sparql_1_2.gram.versionSpecifier).addMany(import_rules_sparql_1_2.gram.buildInLangDir, import_rules_sparql_1_2.gram.buildInLangStrDir, import_rules_sparql_1_2.gram.buildInHasLang, import_rules_sparql_1_2.gram.buildInHasLangDir, import_rules_sparql_1_2.gram.buildInIsTriple, import_rules_sparql_1_2.gram.buildInTriple, import_rules_sparql_1_2.gram.buildInSubject, import_rules_sparql_1_2.gram.buildInPredicate, import_rules_sparql_1_2.gram.buildInObject).patchRule(import_rules_sparql_1_2.gram.dataBlockValue).patchRule(import_rules_sparql_1_2.gram.triplesSameSubject).patchRule(import_rules_sparql_1_2.gram.triplesSameSubjectPath).patchRule(import_rules_sparql_1_2.gram.object).patchRule(import_rules_sparql_1_2.gram.objectPath).patchRule(import_rules_sparql_1_2.gram.graphNode).patchRule(import_rules_sparql_1_2.gram.graphNodePath).patchRule(import_rules_sparql_1_2.gram.varOrTerm).deleteRule(import_rules_sparql_1_1.gram.graphTerm.name).patchRule(import_rules_sparql_1_2.gram.primaryExpression).patchRule(import_rules_sparql_1_2.gram.builtInCall).patchRule(import_rules_sparql_1_2.gram.rdfLiteral).patchRule(import_rules_sparql_1_2.gram.unaryExpression).patchRule(import_rules_sparql_1_2.gram.prologue);
30
+ class Parser {
31
+ parser;
32
+ F = new import_rules_sparql_1_2.AstFactory();
33
+ constructor(args = {}) {
34
+ this.parser = sparql12ParserBuilder.build({
35
+ ...args,
36
+ queryPreProcessor: import_rules_sparql_1_1.sparqlCodepointEscape,
37
+ tokenVocabulary: import_rules_sparql_1_2.lex.sparql12LexerBuilder.tokenVocabulary
38
+ });
39
+ }
40
+ parse(query, context = {}) {
41
+ return this.parser.queryOrUpdate(query, (0, import_rules_sparql_1_2.completeParseContext)(context));
42
+ }
43
+ parsePath(query, context = {}) {
44
+ const res = this.parser.path(query, (0, import_rules_sparql_1_2.completeParseContext)(context));
45
+ if (this.F.isPathPure(res)) {
46
+ return {
47
+ ...res,
48
+ prefixes: {}
49
+ };
50
+ }
51
+ return res;
52
+ }
53
+ }
54
+ // Annotate the CommonJS export names for ESM import in node:
55
+ 0 && (module.exports = {
56
+ Parser,
57
+ sparql12ParserBuilder
58
+ });
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __copyProps = (to, from, except, desc) => {
7
+ if (from && typeof from === "object" || typeof from === "function") {
8
+ for (let key of __getOwnPropNames(from))
9
+ if (!__hasOwnProp.call(to, key) && key !== except)
10
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
11
+ }
12
+ return to;
13
+ };
14
+ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
15
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
16
+ var lib_exports = {};
17
+ module.exports = __toCommonJS(lib_exports);
18
+ __reExport(lib_exports, require("./Parser.js"), module.exports);
19
+ // Annotate the CommonJS export names for ESM import in node:
20
+ 0 && (module.exports = {
21
+ ...require("./Parser.js")
22
+ });
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var parser_exports = {};
20
+ __export(parser_exports, {
21
+ parse: () => parse,
22
+ query: () => query,
23
+ update: () => update
24
+ });
25
+ module.exports = __toCommonJS(parser_exports);
26
+ var import_rdf_test_suite = require("rdf-test-suite");
27
+ var import_lib = require("../lib/index.js");
28
+ function parse(query2, context = {}) {
29
+ const parser = new import_lib.Parser();
30
+ parser.parse(query2, context);
31
+ }
32
+ function query() {
33
+ return Promise.reject(new import_rdf_test_suite.ErrorSkipped("Querying is not supported"));
34
+ }
35
+ function update() {
36
+ return Promise.reject(new import_rdf_test_suite.ErrorSkipped("Updating is not supported"));
37
+ }
38
+ // Annotate the CommonJS export names for ESM import in node:
39
+ 0 && (module.exports = {
40
+ parse,
41
+ query,
42
+ update
43
+ });
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ var import_test_utils = require("@traqula/test-utils");
3
+ var import_sparqljs = require("sparqljs");
4
+ var import_vitest = require("vitest");
5
+ var import_lib = require("../lib/index.js");
6
+ (0, import_vitest.describe)("query 1.2, exclude construction", () => {
7
+ const traqulaParser = new import_lib.Parser();
8
+ const sparqlJSparser = new import_sparqljs.Parser();
9
+ (0, import_vitest.describe)("general queries", async () => {
10
+ const allQueries = await Promise.all([...(0, import_test_utils.positiveTest)("sparql-1-1")].map((x) => x.statics().then((x2) => x2.query)));
11
+ (0, import_vitest.bench)("traqula parse 1.2", () => {
12
+ for (const query of allQueries) {
13
+ traqulaParser.parse(query);
14
+ }
15
+ });
16
+ (0, import_vitest.bench)("sparqljs", () => {
17
+ for (const query of allQueries) {
18
+ sparqlJSparser.parse(query);
19
+ }
20
+ });
21
+ });
22
+ });
@@ -0,0 +1,113 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __copyProps = (to, from, except, desc) => {
9
+ if (from && typeof from === "object" || typeof from === "function") {
10
+ for (let key of __getOwnPropNames(from))
11
+ if (!__hasOwnProp.call(to, key) && key !== except)
12
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
13
+ }
14
+ return to;
15
+ };
16
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
17
+ // If the importer is in node compatibility mode or this is not an ESM
18
+ // file that has been converted to a CommonJS file using a Babel-
19
+ // compatible transform (i.e. "__esModule" has not been set), then set
20
+ // "default" to the CommonJS "module.exports" for node compatibility.
21
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
22
+ mod
23
+ ));
24
+ var import_node_fs = __toESM(require("node:fs"), 1);
25
+ var import_node_path = __toESM(require("node:path"), 1);
26
+ var import_rules_sparql_1_2 = require("@traqula/rules-sparql-1-2");
27
+ var import_test_utils = require("@traqula/test-utils");
28
+ var import_rdf_data_factory = require("rdf-data-factory");
29
+ var import_vitest = require("vitest");
30
+ var import_lib = require("../lib/index.js");
31
+ (0, import_vitest.describe)("a SPARQL 1.2 parser", () => {
32
+ const parser = new import_lib.Parser();
33
+ const F = new import_rules_sparql_1_2.AstFactory();
34
+ const context = { prefixes: { ex: "http://example.org/" } };
35
+ function _sinkAst(suite, test, response) {
36
+ const dir = (0, import_test_utils.getStaticFilePath)();
37
+ const fileLoc = import_node_path.default.join(dir, suite, `${test}.json`);
38
+ import_node_fs.default.writeFileSync(fileLoc, JSON.stringify(response, null, 2));
39
+ }
40
+ (0, import_vitest.it)("passes chevrotain validation", () => {
41
+ import_lib.sparql12ParserBuilder.build({
42
+ tokenVocabulary: import_rules_sparql_1_2.lex.sparql12LexerBuilder.tokenVocabulary,
43
+ lexerConfig: {
44
+ skipValidations: false,
45
+ ensureOptimizations: true
46
+ },
47
+ parserConfig: {
48
+ skipValidations: false
49
+ }
50
+ });
51
+ });
52
+ (0, import_vitest.describe)("positive paths", () => {
53
+ for (const { name, statics } of (0, import_test_utils.positiveTest)("paths")) {
54
+ (0, import_vitest.it)(`can parse ${name}`, async ({ expect }) => {
55
+ const { query, ast } = await statics();
56
+ const res = parser.parsePath(query, context);
57
+ expect(res).toEqualParsedQuery(ast);
58
+ });
59
+ }
60
+ });
61
+ (0, import_vitest.describe)("positive sparql 1.1", () => {
62
+ for (const { name, statics } of (0, import_test_utils.positiveTest)("sparql-1-1")) {
63
+ (0, import_vitest.it)(`can parse ${name}`, async ({ expect }) => {
64
+ const { query, ast } = await statics();
65
+ const res = parser.parse(query, context);
66
+ expect(res).toEqualParsedQueryIgnoring((obj) => F.isTriple(obj), ["annotations"], ast);
67
+ });
68
+ }
69
+ });
70
+ (0, import_vitest.describe)("negative SPARQL 1.1", () => {
71
+ for (const { name, statics } of (0, import_test_utils.negativeTest)("sparql-1-1-invalid")) {
72
+ (0, import_vitest.it)(`should NOT parse ${name}`, async ({ expect }) => {
73
+ const { query } = await statics();
74
+ expect(() => parser.parse(query, context)).toThrow();
75
+ });
76
+ }
77
+ });
78
+ (0, import_vitest.describe)("positive sparql 1.2", () => {
79
+ for (const { name, statics } of (0, import_test_utils.positiveTest)("sparql-1-2")) {
80
+ (0, import_vitest.it)(`can parse ${name}`, async ({ expect }) => {
81
+ const { query, ast } = await statics();
82
+ const res = parser.parse(query, context);
83
+ expect(res).toEqualParsedQuery(ast);
84
+ });
85
+ }
86
+ });
87
+ (0, import_vitest.it)(`should NOT parse $only thing}`, async ({ expect }) => {
88
+ const query = `
89
+ PREFIX : <http://example.com/ns#>
90
+
91
+ SELECT * WHERE {
92
+ <<( ?s ?p ?o )>> .
93
+ }
94
+ `;
95
+ expect(() => parser.parse(query)).toThrow();
96
+ });
97
+ (0, import_vitest.describe)("negative sparql 1.2", () => {
98
+ const skip = /* @__PURE__ */ new Set([
99
+ "sparql-1-2-syntax-basic-tripleterm-subject",
100
+ "sparql-1-2-syntax-compound-tripleterm-subject",
101
+ "sparql-1-2-syntax-subject-tripleterm"
102
+ ]);
103
+ for (const { name, statics } of (0, import_test_utils.negativeTest)("sparql-1-2-invalid", (name2) => !skip.has(name2))) {
104
+ (0, import_vitest.it)(`should NOT parse ${name}`, async ({ expect }) => {
105
+ const { query } = await statics();
106
+ expect(() => parser.parse(query, context)).toThrow();
107
+ });
108
+ }
109
+ });
110
+ (0, import_vitest.describe)("specific sparql 1.1 tests", () => {
111
+ (0, import_test_utils.importSparql11NoteTests)(parser, new import_rdf_data_factory.DataFactory());
112
+ });
113
+ });