@traqula/rules-sparql-1-1 0.0.23 → 0.0.25

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.
Files changed (116) hide show
  1. package/README.md +2 -0
  2. package/dist/cjs/lib/MinimalSparqlParser.js +66 -58
  3. package/dist/cjs/lib/MinimalSparqlParser.js.map +1 -0
  4. package/dist/cjs/lib/Sparql11types.js +2 -15
  5. package/dist/cjs/lib/Sparql11types.js.map +1 -0
  6. package/dist/cjs/lib/astFactory.js +110 -119
  7. package/dist/cjs/lib/astFactory.js.map +1 -0
  8. package/dist/cjs/lib/expressionHelpers.js +181 -191
  9. package/dist/cjs/lib/expressionHelpers.js.map +1 -0
  10. package/dist/cjs/lib/factoryMixins/ContextFactory.js +30 -52
  11. package/dist/cjs/lib/factoryMixins/ContextFactory.js.map +1 -0
  12. package/dist/cjs/lib/factoryMixins/ExpressionFactory.js +83 -102
  13. package/dist/cjs/lib/factoryMixins/ExpressionFactory.js.map +1 -0
  14. package/dist/cjs/lib/factoryMixins/GraphRefFactory.js +51 -73
  15. package/dist/cjs/lib/factoryMixins/GraphRefFactory.js.map +1 -0
  16. package/dist/cjs/lib/factoryMixins/PathFactory.js +68 -87
  17. package/dist/cjs/lib/factoryMixins/PathFactory.js.map +1 -0
  18. package/dist/cjs/lib/factoryMixins/Patternfactory.js +98 -120
  19. package/dist/cjs/lib/factoryMixins/Patternfactory.js.map +1 -0
  20. package/dist/cjs/lib/factoryMixins/QueryFactory.js +43 -65
  21. package/dist/cjs/lib/factoryMixins/QueryFactory.js.map +1 -0
  22. package/dist/cjs/lib/factoryMixins/SolutionModifiersFactory.js +55 -77
  23. package/dist/cjs/lib/factoryMixins/SolutionModifiersFactory.js.map +1 -0
  24. package/dist/cjs/lib/factoryMixins/TermFactory.js +81 -102
  25. package/dist/cjs/lib/factoryMixins/TermFactory.js.map +1 -0
  26. package/dist/cjs/lib/factoryMixins/UpdateOperationFactory.js +126 -147
  27. package/dist/cjs/lib/factoryMixins/UpdateOperationFactory.js.map +1 -0
  28. package/dist/cjs/lib/factoryMixins/mixins.js +21 -38
  29. package/dist/cjs/lib/factoryMixins/mixins.js.map +1 -0
  30. package/dist/cjs/lib/grammar/builtIn.js +277 -377
  31. package/dist/cjs/lib/grammar/builtIn.js.map +1 -0
  32. package/dist/cjs/lib/grammar/dataSetClause.js +110 -109
  33. package/dist/cjs/lib/grammar/dataSetClause.js.map +1 -0
  34. package/dist/cjs/lib/grammar/expression.js +387 -358
  35. package/dist/cjs/lib/grammar/expression.js.map +1 -0
  36. package/dist/cjs/lib/grammar/general.js +173 -158
  37. package/dist/cjs/lib/grammar/general.js.map +1 -0
  38. package/dist/cjs/lib/grammar/index.js +94 -111
  39. package/dist/cjs/lib/grammar/index.js.map +1 -0
  40. package/dist/cjs/lib/grammar/literals.js +292 -266
  41. package/dist/cjs/lib/grammar/literals.js.map +1 -0
  42. package/dist/cjs/lib/grammar/propertyPaths.js +206 -193
  43. package/dist/cjs/lib/grammar/propertyPaths.js.map +1 -0
  44. package/dist/cjs/lib/grammar/queryUnit.js +395 -372
  45. package/dist/cjs/lib/grammar/queryUnit.js.map +1 -0
  46. package/dist/cjs/lib/grammar/solutionModifier.js +281 -265
  47. package/dist/cjs/lib/grammar/solutionModifier.js.map +1 -0
  48. package/dist/cjs/lib/grammar/tripleBlock.js +396 -355
  49. package/dist/cjs/lib/grammar/tripleBlock.js.map +1 -0
  50. package/dist/cjs/lib/grammar/updateUnit.js +551 -519
  51. package/dist/cjs/lib/grammar/updateUnit.js.map +1 -0
  52. package/dist/cjs/lib/grammar/whereClause.js +486 -459
  53. package/dist/cjs/lib/grammar/whereClause.js.map +1 -0
  54. package/dist/cjs/lib/index.js +47 -54
  55. package/dist/cjs/lib/index.js.map +1 -0
  56. package/dist/cjs/lib/lexer/BuiltInCalls.js +188 -333
  57. package/dist/cjs/lib/lexer/BuiltInCalls.js.map +1 -0
  58. package/dist/cjs/lib/lexer/graph.js +10 -40
  59. package/dist/cjs/lib/lexer/graph.js.map +1 -0
  60. package/dist/cjs/lib/lexer/index.js +43 -48
  61. package/dist/cjs/lib/lexer/index.js.map +1 -0
  62. package/dist/cjs/lib/lexer/lexer.js +84 -195
  63. package/dist/cjs/lib/lexer/lexer.js.map +1 -0
  64. package/dist/cjs/lib/lexer/lexerPatterns.js +40 -132
  65. package/dist/cjs/lib/lexer/lexerPatterns.js.map +1 -0
  66. package/dist/cjs/lib/lexer/symbols.js +31 -106
  67. package/dist/cjs/lib/lexer/symbols.js.map +1 -0
  68. package/dist/cjs/lib/lexer/terminals.js +100 -102
  69. package/dist/cjs/lib/lexer/terminals.js.map +1 -0
  70. package/dist/cjs/lib/sparql11HelperTypes.js +2 -15
  71. package/dist/cjs/lib/sparql11HelperTypes.js.map +1 -0
  72. package/dist/cjs/lib/utils.js +40 -58
  73. package/dist/cjs/lib/utils.js.map +1 -0
  74. package/dist/cjs/lib/validation/validators.js +217 -196
  75. package/dist/cjs/lib/validation/validators.js.map +1 -0
  76. package/dist/esm/lib/MinimalSparqlParser.d.ts +26 -8
  77. package/dist/esm/lib/MinimalSparqlParser.js +40 -11
  78. package/dist/esm/lib/MinimalSparqlParser.js.map +1 -1
  79. package/dist/esm/lib/astFactory.d.ts +66 -45
  80. package/dist/esm/lib/astFactory.js +3 -0
  81. package/dist/esm/lib/astFactory.js.map +1 -1
  82. package/dist/esm/lib/factoryMixins/ContextFactory.d.ts +7 -5
  83. package/dist/esm/lib/factoryMixins/ExpressionFactory.d.ts +7 -5
  84. package/dist/esm/lib/factoryMixins/GraphRefFactory.d.ts +7 -5
  85. package/dist/esm/lib/factoryMixins/PathFactory.d.ts +7 -5
  86. package/dist/esm/lib/factoryMixins/Patternfactory.d.ts +7 -5
  87. package/dist/esm/lib/factoryMixins/QueryFactory.d.ts +7 -5
  88. package/dist/esm/lib/factoryMixins/SolutionModifiersFactory.d.ts +7 -5
  89. package/dist/esm/lib/factoryMixins/TermFactory.d.ts +7 -5
  90. package/dist/esm/lib/factoryMixins/UpdateOperationFactory.d.ts +7 -5
  91. package/dist/esm/lib/grammar/index.js +1 -1
  92. package/dist/esm/lib/grammar/index.js.map +1 -1
  93. package/dist/esm/lib/grammar/literals.js +23 -13
  94. package/dist/esm/lib/grammar/literals.js.map +1 -1
  95. package/dist/esm/lib/grammar/propertyPaths.d.ts +2 -2
  96. package/dist/esm/lib/grammar/tripleBlock.d.ts +4 -4
  97. package/dist/esm/lib/grammar/tripleBlock.js +18 -12
  98. package/dist/esm/lib/grammar/tripleBlock.js.map +1 -1
  99. package/dist/esm/lib/grammar/updateUnit.js +2 -2
  100. package/dist/esm/lib/grammar/updateUnit.js.map +1 -1
  101. package/dist/esm/lib/lexer/BuiltInCalls.d.ts +1 -1
  102. package/dist/esm/lib/lexer/graph.d.ts +1 -1
  103. package/dist/esm/lib/lexer/lexer.d.ts +2 -2
  104. package/dist/esm/lib/lexer/lexerPatterns.d.ts +1 -1
  105. package/dist/esm/lib/lexer/lexerPatterns.js +1 -1
  106. package/dist/esm/lib/lexer/lexerPatterns.js.map +1 -1
  107. package/dist/esm/lib/lexer/symbols.d.ts +1 -1
  108. package/dist/esm/lib/lexer/terminals.d.ts +2 -2
  109. package/dist/esm/lib/lexer/terminals.js +3 -3
  110. package/dist/esm/lib/lexer/terminals.js.map +1 -1
  111. package/dist/esm/lib/sparql11HelperTypes.d.ts +1 -1
  112. package/dist/esm/lib/sparql11HelperTypes.js.map +1 -1
  113. package/dist/esm/lib/validation/validators.d.ts +2 -2
  114. package/dist/esm/lib/validation/validators.js +61 -51
  115. package/dist/esm/lib/validation/validators.js.map +1 -1
  116. package/package.json +10 -10
@@ -1,384 +1,413 @@
1
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 __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
- var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
19
- };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
- var expression_exports = {};
30
- __export(expression_exports, {
31
- additiveExpression: () => additiveExpression,
32
- argList: () => argList,
33
- brackettedExpression: () => brackettedExpression,
34
- conditionalAndExpression: () => conditionalAndExpression,
35
- conditionalOrExpression: () => conditionalOrExpression,
36
- expression: () => expression,
37
- expressionList: () => expressionList,
38
- iriOrFunction: () => iriOrFunction,
39
- multiplicativeExpression: () => multiplicativeExpression,
40
- numericExpression: () => numericExpression,
41
- primaryExpression: () => primaryExpression,
42
- relationalExpression: () => relationalExpression,
43
- unaryExpression: () => unaryExpression,
44
- valueLogical: () => valueLogical
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
45
17
  });
46
- module.exports = __toCommonJS(expression_exports);
47
- var l = __toESM(require("../lexer/index.js"), 1);
48
- var import_builtIn = require("./builtIn.js");
49
- var import_general = require("./general.js");
50
- var import_literals = require("./literals.js");
51
- var import_whereClause = require("./whereClause.js");
52
- const argList = {
53
- name: "argList",
54
- impl: ({ ACTION, CONSUME, SUBRULE1, OPTION, OR, AT_LEAST_ONE_SEP }) => (C) => OR([
55
- { ALT: () => {
56
- const nil = CONSUME(l.terminals.nil);
57
- return ACTION(() => C.astFactory.wrap({ args: [], distinct: false }, C.astFactory.sourceLocation(nil)));
58
- } },
59
- { ALT: () => {
60
- const args = [];
61
- const open = CONSUME(l.symbols.LParen);
62
- const distinct = OPTION(() => {
63
- CONSUME(l.distinct);
64
- return true;
65
- }) ?? false;
66
- AT_LEAST_ONE_SEP({
67
- SEP: l.symbols.comma,
68
- DEF: () => {
69
- const arg = SUBRULE1(expression);
70
- args.push(arg);
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.iriOrFunction = exports.brackettedExpression = exports.primaryExpression = exports.unaryExpression = exports.multiplicativeExpression = exports.additiveExpression = exports.numericExpression = exports.relationalExpression = exports.valueLogical = exports.conditionalAndExpression = exports.conditionalOrExpression = exports.expression = exports.expressionList = exports.argList = void 0;
37
+ const l = __importStar(require("../lexer/index.js"));
38
+ const builtIn_js_1 = require("./builtIn.js");
39
+ const general_js_1 = require("./general.js");
40
+ const literals_js_1 = require("./literals.js");
41
+ const whereClause_js_1 = require("./whereClause.js");
42
+ exports.argList = {
43
+ name: 'argList',
44
+ impl: ({ ACTION, CONSUME, SUBRULE1, OPTION, OR, AT_LEAST_ONE_SEP }) => C => OR([
45
+ { ALT: () => {
46
+ const nil = CONSUME(l.terminals.nil);
47
+ return ACTION(() => C.astFactory.wrap({ args: [], distinct: false }, C.astFactory.sourceLocation(nil)));
48
+ } },
49
+ { ALT: () => {
50
+ const args = [];
51
+ const open = CONSUME(l.symbols.LParen);
52
+ const distinct = OPTION(() => {
53
+ CONSUME(l.distinct);
54
+ return true;
55
+ }) ?? false;
56
+ AT_LEAST_ONE_SEP({
57
+ SEP: l.symbols.comma,
58
+ DEF: () => {
59
+ const arg = SUBRULE1(exports.expression);
60
+ args.push(arg);
61
+ },
62
+ });
63
+ const close = CONSUME(l.symbols.RParen);
64
+ return ACTION(() => C.astFactory.wrap({ args, distinct }, C.astFactory.sourceLocation(open, close)));
65
+ } },
66
+ ]),
67
+ gImpl: ({ SUBRULE, PRINT_WORD }) => (ast, { astFactory: F }) => {
68
+ F.printFilter(ast, () => {
69
+ PRINT_WORD('(');
70
+ if (ast.val.distinct) {
71
+ PRINT_WORD('DISTINCT');
72
+ }
73
+ });
74
+ const [head, ...tail] = ast.val.args;
75
+ if (head) {
76
+ SUBRULE(exports.expression, head);
71
77
  }
72
- });
73
- const close = CONSUME(l.symbols.RParen);
74
- return ACTION(() => C.astFactory.wrap({ args, distinct }, C.astFactory.sourceLocation(open, close)));
75
- } }
76
- ]),
77
- gImpl: ({ SUBRULE, PRINT_WORD }) => (ast, { astFactory: F }) => {
78
- F.printFilter(ast, () => {
79
- PRINT_WORD("(");
80
- if (ast.val.distinct) {
81
- PRINT_WORD("DISTINCT");
82
- }
83
- });
84
- const [head, ...tail] = ast.val.args;
85
- if (head) {
86
- SUBRULE(expression, head);
87
- }
88
- for (const expr of tail) {
89
- F.printFilter(ast, () => PRINT_WORD(","));
90
- SUBRULE(expression, expr);
91
- }
92
- F.printFilter(ast, () => PRINT_WORD(")"));
93
- }
78
+ for (const expr of tail) {
79
+ F.printFilter(ast, () => PRINT_WORD(','));
80
+ SUBRULE(exports.expression, expr);
81
+ }
82
+ F.printFilter(ast, () => PRINT_WORD(')'));
83
+ },
94
84
  };
95
- const expressionList = {
96
- name: "expressionList",
97
- impl: ({ ACTION, CONSUME, MANY, OR, SUBRULE1, SUBRULE2 }) => (C) => OR([
98
- { ALT: () => {
99
- const nil = CONSUME(l.terminals.nil);
100
- return ACTION(() => C.astFactory.wrap([], C.astFactory.sourceLocation(nil)));
101
- } },
102
- { ALT: () => {
103
- const open = CONSUME(l.symbols.LParen);
104
- const expr1 = SUBRULE1(expression);
105
- const args = [expr1];
106
- MANY(() => {
107
- CONSUME(l.symbols.comma);
108
- const expr = SUBRULE2(expression);
109
- args.push(expr);
110
- });
111
- const close = CONSUME(l.symbols.RParen);
112
- return ACTION(() => C.astFactory.wrap(args, C.astFactory.sourceLocation(open, close)));
113
- } }
114
- ])
85
+ /**
86
+ * [[72]](https://www.w3.org/TR/sparql11-query/#rConstructTemplate)
87
+ */
88
+ exports.expressionList = {
89
+ name: 'expressionList',
90
+ impl: ({ ACTION, CONSUME, MANY, OR, SUBRULE1, SUBRULE2 }) => C => OR([
91
+ { ALT: () => {
92
+ const nil = CONSUME(l.terminals.nil);
93
+ return ACTION(() => C.astFactory.wrap([], C.astFactory.sourceLocation(nil)));
94
+ } },
95
+ { ALT: () => {
96
+ const open = CONSUME(l.symbols.LParen);
97
+ const expr1 = SUBRULE1(exports.expression);
98
+ const args = [expr1];
99
+ MANY(() => {
100
+ CONSUME(l.symbols.comma);
101
+ const expr = SUBRULE2(exports.expression);
102
+ args.push(expr);
103
+ });
104
+ const close = CONSUME(l.symbols.RParen);
105
+ return ACTION(() => C.astFactory.wrap(args, C.astFactory.sourceLocation(open, close)));
106
+ } },
107
+ ]),
115
108
  };
116
- const infixOperators = /* @__PURE__ */ new Set(["in", "notin", "||", "&&", "=", "!=", "<", ">", "<=", ">=", "+", "-", "*", "/"]);
117
- const prefixOperator = /* @__PURE__ */ new Set(["!", "UPLUS", "UMINUS"]);
118
- const expression = {
119
- name: "expression",
120
- impl: ({ SUBRULE }) => () => SUBRULE(conditionalOrExpression),
121
- gImpl: ({ SUBRULE, PRINT_WORD }) => (ast, { astFactory: F }) => {
122
- if (F.isTerm(ast)) {
123
- SUBRULE(import_general.varOrTerm, ast);
124
- } else if (F.isExpressionOperator(ast)) {
125
- if (infixOperators.has(ast.operator)) {
126
- const [left, ...right] = ast.args;
127
- F.printFilter(ast, () => PRINT_WORD("("));
128
- SUBRULE(expression, left);
129
- F.printFilter(ast, () => {
130
- if (ast.operator === "notin") {
131
- PRINT_WORD("NOT IN");
132
- } else if (ast.operator === "in") {
133
- PRINT_WORD("IN");
134
- } else {
135
- PRINT_WORD(ast.operator.toUpperCase());
136
- }
137
- });
138
- if (right.length === 1) {
139
- SUBRULE(expression, right[0]);
140
- } else {
141
- SUBRULE(argList, F.wrap({ args: right, distinct: false }, ast.loc));
109
+ const infixOperators = new Set(['in', 'notin', '||', '&&', '=', '!=', '<', '>', '<=', '>=', '+', '-', '*', '/']);
110
+ const prefixOperator = new Set(['!', 'UPLUS', 'UMINUS']);
111
+ /**
112
+ * [[110]](https://www.w3.org/TR/sparql11-query/#rExpression)
113
+ */
114
+ exports.expression = {
115
+ name: 'expression',
116
+ impl: ({ SUBRULE }) => () => SUBRULE(exports.conditionalOrExpression),
117
+ gImpl: ({ SUBRULE, PRINT_WORD }) => (ast, { astFactory: F }) => {
118
+ if (F.isTerm(ast)) {
119
+ SUBRULE(general_js_1.varOrTerm, ast);
142
120
  }
143
- F.printFilter(ast, () => PRINT_WORD(")"));
144
- } else if (prefixOperator.has(ast.operator)) {
145
- const [expr] = ast.args;
146
- F.printFilter(ast, () => PRINT_WORD(ast.operator.toUpperCase()));
147
- SUBRULE(expression, expr);
148
- } else {
149
- F.printFilter(ast, () => PRINT_WORD(ast.operator.toUpperCase(), "("));
150
- const [head, ...tail] = ast.args;
151
- if (head) {
152
- SUBRULE(expression, head);
121
+ else if (F.isExpressionOperator(ast)) {
122
+ if (infixOperators.has(ast.operator)) {
123
+ const [left, ...right] = ast.args;
124
+ F.printFilter(ast, () => PRINT_WORD('('));
125
+ SUBRULE(exports.expression, left);
126
+ F.printFilter(ast, () => {
127
+ if (ast.operator === 'notin') {
128
+ PRINT_WORD('NOT IN');
129
+ }
130
+ else if (ast.operator === 'in') {
131
+ PRINT_WORD('IN');
132
+ }
133
+ else {
134
+ PRINT_WORD(ast.operator.toUpperCase());
135
+ }
136
+ });
137
+ if (right.length === 1) {
138
+ SUBRULE(exports.expression, right[0]);
139
+ }
140
+ else {
141
+ SUBRULE(exports.argList, F.wrap({ args: right, distinct: false }, ast.loc));
142
+ }
143
+ F.printFilter(ast, () => PRINT_WORD(')'));
144
+ }
145
+ else if (prefixOperator.has(ast.operator)) {
146
+ const [expr] = ast.args;
147
+ F.printFilter(ast, () => PRINT_WORD(ast.operator.toUpperCase()));
148
+ SUBRULE(exports.expression, expr);
149
+ }
150
+ else {
151
+ F.printFilter(ast, () => PRINT_WORD(ast.operator.toUpperCase(), '('));
152
+ const [head, ...tail] = ast.args;
153
+ if (head) {
154
+ SUBRULE(exports.expression, head);
155
+ }
156
+ for (const arg of tail) {
157
+ F.printFilter(ast, () => PRINT_WORD(','));
158
+ SUBRULE(exports.expression, arg);
159
+ }
160
+ F.printFilter(ast, () => PRINT_WORD(')'));
161
+ }
153
162
  }
154
- for (const arg of tail) {
155
- F.printFilter(ast, () => PRINT_WORD(","));
156
- SUBRULE(expression, arg);
163
+ else if (F.isExpressionPatternOperation(ast)) {
164
+ const patterns = ast.args;
165
+ F.printFilter(ast, () => PRINT_WORD(ast.operator === 'exists' ? 'EXISTS' : 'NOT EXISTS'));
166
+ SUBRULE(whereClause_js_1.groupGraphPattern, patterns);
157
167
  }
158
- F.printFilter(ast, () => PRINT_WORD(")"));
159
- }
160
- } else if (F.isExpressionPatternOperation(ast)) {
161
- const patterns = ast.args;
162
- F.printFilter(ast, () => PRINT_WORD(ast.operator === "exists" ? "EXISTS" : "NOT EXISTS"));
163
- SUBRULE(import_whereClause.groupGraphPattern, patterns);
164
- } else if (F.isExpressionFunctionCall(ast)) {
165
- SUBRULE(iriOrFunction, ast);
166
- } else if (F.isExpressionAggregate(ast)) {
167
- SUBRULE(import_builtIn.aggregate, ast);
168
- }
169
- }
168
+ else if (F.isExpressionFunctionCall(ast)) {
169
+ SUBRULE(exports.iriOrFunction, ast);
170
+ }
171
+ else if (F.isExpressionAggregate(ast)) {
172
+ SUBRULE(builtIn_js_1.aggregate, ast);
173
+ }
174
+ },
170
175
  };
171
176
  function constructLeftDeep(startGenerator, restGenerator, ACTION, MANY) {
172
- let iterExpr = startGenerator();
173
- MANY(() => {
174
- const res = restGenerator();
175
- ACTION(() => {
176
- iterExpr = res(iterExpr);
177
+ // By using iterExpression, we avoid creating unnecessary arrays
178
+ let iterExpr = startGenerator();
179
+ MANY(() => {
180
+ const res = restGenerator();
181
+ ACTION(() => {
182
+ iterExpr = res(iterExpr);
183
+ });
177
184
  });
178
- });
179
- return iterExpr;
185
+ return iterExpr;
180
186
  }
181
- const conditionalOrExpression = {
182
- name: "conditionalOrExpression",
183
- impl: ({ ACTION, MANY, CONSUME, SUBRULE1, SUBRULE2 }) => (C) => constructLeftDeep(() => SUBRULE1(conditionalAndExpression), () => {
184
- CONSUME(l.symbols.logicOr);
185
- const args = SUBRULE2(conditionalAndExpression);
186
- return (left) => ACTION(() => C.astFactory.expressionOperation("||", [left, args], C.astFactory.sourceLocation(left, args)));
187
- }, ACTION, MANY)
187
+ /**
188
+ * [[111]](https://www.w3.org/TR/sparql11-query/#rConditionalOrExpression)
189
+ */
190
+ exports.conditionalOrExpression = {
191
+ name: 'conditionalOrExpression',
192
+ impl: ({ ACTION, MANY, CONSUME, SUBRULE1, SUBRULE2 }) => C => constructLeftDeep(() => SUBRULE1(exports.conditionalAndExpression), () => {
193
+ CONSUME(l.symbols.logicOr);
194
+ const args = SUBRULE2(exports.conditionalAndExpression);
195
+ return left => ACTION(() => C.astFactory.expressionOperation('||', [left, args], C.astFactory.sourceLocation(left, args)));
196
+ }, ACTION, MANY),
188
197
  };
189
- const conditionalAndExpression = {
190
- name: "conditionalAndExpression",
191
- impl: ({ ACTION, MANY, SUBRULE1, SUBRULE2, CONSUME }) => (C) => constructLeftDeep(() => SUBRULE1(valueLogical), () => {
192
- CONSUME(l.symbols.logicAnd);
193
- const arg = SUBRULE2(valueLogical);
194
- return (left) => ACTION(() => C.astFactory.expressionOperation("&&", [left, arg], C.astFactory.sourceLocation(left, arg)));
195
- }, ACTION, MANY)
198
+ /**
199
+ * [[112]](https://www.w3.org/TR/sparql11-query/#rConditionalAndExpression)
200
+ */
201
+ exports.conditionalAndExpression = {
202
+ name: 'conditionalAndExpression',
203
+ impl: ({ ACTION, MANY, SUBRULE1, SUBRULE2, CONSUME }) => C => constructLeftDeep(() => SUBRULE1(exports.valueLogical), () => {
204
+ CONSUME(l.symbols.logicAnd);
205
+ const arg = SUBRULE2(exports.valueLogical);
206
+ return left => ACTION(() => C.astFactory.expressionOperation('&&', [left, arg], C.astFactory.sourceLocation(left, arg)));
207
+ }, ACTION, MANY),
196
208
  };
197
- const valueLogical = {
198
- name: "valueLogical",
199
- impl: ({ SUBRULE }) => () => SUBRULE(relationalExpression)
209
+ /**
210
+ * [[113]](https://www.w3.org/TR/sparql11-query/#rValueLogical)
211
+ */
212
+ exports.valueLogical = {
213
+ name: 'valueLogical',
214
+ impl: ({ SUBRULE }) => () => SUBRULE(exports.relationalExpression),
200
215
  };
201
- const relationalExpression = {
202
- name: "relationalExpression",
203
- impl: ({ ACTION, CONSUME, SUBRULE1, SUBRULE2, OPTION, OR1, OR2, OR3 }) => (C) => {
204
- const args1 = SUBRULE1(numericExpression);
205
- const expression2 = OPTION(() => OR1([
206
- { ALT: () => {
207
- const operator = OR2([
208
- { ALT: () => CONSUME(l.symbols.equal) },
209
- { ALT: () => CONSUME(l.symbols.notEqual) },
210
- { ALT: () => CONSUME(l.symbols.lessThan) },
211
- { ALT: () => CONSUME(l.symbols.greaterThan) },
212
- { ALT: () => CONSUME(l.symbols.lessThanEqual) },
213
- { ALT: () => CONSUME(l.symbols.greaterThanEqual) }
214
- ]);
215
- const expr = SUBRULE2(numericExpression);
216
- return ACTION(() => C.astFactory.expressionOperation(operator.image, [args1, expr], C.astFactory.sourceLocation(args1, expr)));
217
- } },
218
- { ALT: () => {
219
- const operator = OR3([
220
- { ALT: () => CONSUME(l.in_) },
221
- { ALT: () => CONSUME(l.notIn) }
222
- ]);
223
- const args = SUBRULE1(expressionList);
224
- return ACTION(() => C.astFactory.expressionOperation(operator.image, [args1, ...args.val], C.astFactory.sourceLocation(args1, args)));
225
- } }
226
- ]));
227
- return expression2 ?? args1;
228
- }
216
+ /**
217
+ * [[114]](https://www.w3.org/TR/sparql11-query/#rRelationalExpression)
218
+ */
219
+ exports.relationalExpression = {
220
+ name: 'relationalExpression',
221
+ impl: ({ ACTION, CONSUME, SUBRULE1, SUBRULE2, OPTION, OR1, OR2, OR3 }) => (C) => {
222
+ const args1 = SUBRULE1(exports.numericExpression);
223
+ const expression = OPTION(() => OR1([
224
+ { ALT: () => {
225
+ // Stay in numeric;
226
+ const operator = OR2([
227
+ { ALT: () => CONSUME(l.symbols.equal) },
228
+ { ALT: () => CONSUME(l.symbols.notEqual) },
229
+ { ALT: () => CONSUME(l.symbols.lessThan) },
230
+ { ALT: () => CONSUME(l.symbols.greaterThan) },
231
+ { ALT: () => CONSUME(l.symbols.lessThanEqual) },
232
+ { ALT: () => CONSUME(l.symbols.greaterThanEqual) },
233
+ ]);
234
+ const expr = SUBRULE2(exports.numericExpression);
235
+ return ACTION(() => C.astFactory.expressionOperation(operator.image, [args1, expr], C.astFactory.sourceLocation(args1, expr)));
236
+ } },
237
+ { ALT: () => {
238
+ const operator = OR3([
239
+ { ALT: () => CONSUME(l.in_) },
240
+ { ALT: () => CONSUME(l.notIn) },
241
+ ]);
242
+ const args = SUBRULE1(exports.expressionList);
243
+ return ACTION(() => C.astFactory.expressionOperation(operator.image, [args1, ...args.val], C.astFactory.sourceLocation(args1, args)));
244
+ } },
245
+ ]));
246
+ return expression ?? args1;
247
+ },
229
248
  };
230
- const numericExpression = {
231
- name: "numericExpression",
232
- impl: ({ SUBRULE }) => () => SUBRULE(additiveExpression)
249
+ /**
250
+ * [[115]](https://www.w3.org/TR/sparql11-query/#rNumericExpression)
251
+ */
252
+ exports.numericExpression = {
253
+ name: 'numericExpression',
254
+ impl: ({ SUBRULE }) => () => SUBRULE(exports.additiveExpression),
233
255
  };
234
- const additiveExpression = {
235
- name: "additiveExpression",
236
- impl: ({ ACTION, SUBRULE, CONSUME, SUBRULE1, SUBRULE2, MANY1, MANY2, OR1, OR2, OR3, OR4 }) => (C) => constructLeftDeep(() => SUBRULE1(multiplicativeExpression), () => OR1([
237
- { ALT: () => {
238
- const operator = OR2([
239
- { ALT: () => CONSUME(l.symbols.opPlus) },
240
- { ALT: () => CONSUME(l.symbols.opMinus) }
241
- ]);
242
- const arg = SUBRULE2(multiplicativeExpression);
243
- return ACTION(() => (left) => C.astFactory.expressionOperation(operator.image, [left, arg], C.astFactory.sourceLocation(left, arg)));
244
- } },
245
- { ALT: () => {
246
- const { operator, startInt } = OR3([
256
+ /**
257
+ * [[116]](https://www.w3.org/TR/sparql11-query/#rAdditiveExpression)
258
+ */
259
+ exports.additiveExpression = {
260
+ name: 'additiveExpression',
261
+ impl: ({ ACTION, SUBRULE, CONSUME, SUBRULE1, SUBRULE2, MANY1, MANY2, OR1, OR2, OR3, OR4 }) => C => constructLeftDeep(() => SUBRULE1(exports.multiplicativeExpression), () => OR1([
247
262
  { ALT: () => {
248
- const integer = SUBRULE(import_literals.numericLiteralPositive);
249
- return ACTION(() => {
250
- integer.value = integer.value.replace(/^\+/u, "");
251
- return {
252
- operator: "+",
253
- startInt: integer
254
- };
255
- });
256
- } },
263
+ // Multiplicative expression as 2nd argument
264
+ const operator = OR2([
265
+ { ALT: () => CONSUME(l.symbols.opPlus) },
266
+ { ALT: () => CONSUME(l.symbols.opMinus) },
267
+ ]);
268
+ const arg = SUBRULE2(exports.multiplicativeExpression);
269
+ return ACTION(() => left => C.astFactory.expressionOperation(operator.image, [left, arg], C.astFactory.sourceLocation(left, arg)));
270
+ } },
257
271
  { ALT: () => {
258
- const integer = SUBRULE(import_literals.numericLiteralNegative);
259
- return ACTION(() => {
260
- integer.value = integer.value.replace(/^-/u, "");
261
- return {
262
- operator: "-",
263
- startInt: integer
264
- };
265
- });
266
- } }
267
- ]);
268
- const multiplicativeExpr = constructLeftDeep(() => ACTION(() => startInt), () => {
269
- const innerOperator = OR4([
270
- { ALT: () => CONSUME(l.symbols.star) },
271
- { ALT: () => CONSUME(l.symbols.slash) }
272
- ]);
273
- const innerExpr = SUBRULE1(unaryExpression);
274
- return ACTION(() => (leftInner) => C.astFactory.expressionOperation(innerOperator.image, [leftInner, innerExpr], C.astFactory.sourceLocation(leftInner, innerExpr)));
275
- }, ACTION, MANY2);
276
- return (left) => C.astFactory.expressionOperation(operator, [left, multiplicativeExpr], C.astFactory.sourceLocation(left, multiplicativeExpr));
277
- } }
278
- ]), ACTION, MANY1)
272
+ // The operator of this alternative is actually parsed as part of the signed numeric literal. (note #6)
273
+ const { operator, startInt } = OR3([
274
+ { ALT: () => {
275
+ // Note #6. No spaces are allowed between the sign and a number.
276
+ // In this rule however, we do not want to care about this.
277
+ const integer = SUBRULE(literals_js_1.numericLiteralPositive);
278
+ return ACTION(() => {
279
+ integer.value = integer.value.replace(/^\+/u, '');
280
+ return {
281
+ operator: '+',
282
+ startInt: integer,
283
+ };
284
+ });
285
+ } },
286
+ { ALT: () => {
287
+ const integer = SUBRULE(literals_js_1.numericLiteralNegative);
288
+ return ACTION(() => {
289
+ integer.value = integer.value.replace(/^-/u, '');
290
+ return {
291
+ operator: '-',
292
+ startInt: integer,
293
+ };
294
+ });
295
+ } },
296
+ ]);
297
+ const multiplicativeExpr = constructLeftDeep(() => ACTION(() => startInt), () => {
298
+ const innerOperator = OR4([
299
+ { ALT: () => CONSUME(l.symbols.star) },
300
+ { ALT: () => CONSUME(l.symbols.slash) },
301
+ ]);
302
+ const innerExpr = SUBRULE1(exports.unaryExpression);
303
+ return ACTION(() => leftInner => C.astFactory.expressionOperation(innerOperator.image, [leftInner, innerExpr], C.astFactory.sourceLocation(leftInner, innerExpr)));
304
+ }, ACTION, MANY2);
305
+ return left => C.astFactory.expressionOperation(operator, [left, multiplicativeExpr], C.astFactory.sourceLocation(left, multiplicativeExpr));
306
+ } },
307
+ ]), ACTION, MANY1),
279
308
  };
280
- const multiplicativeExpression = {
281
- name: "multiplicativeExpression",
282
- impl: ({ ACTION, CONSUME, MANY, SUBRULE1, SUBRULE2, OR }) => (C) => constructLeftDeep(() => SUBRULE1(unaryExpression), () => {
283
- const operator = OR([
284
- { ALT: () => CONSUME(l.symbols.star) },
285
- { ALT: () => CONSUME(l.symbols.slash) }
286
- ]);
287
- const expr = SUBRULE2(unaryExpression);
288
- return (left) => ({
289
- type: "expression",
290
- subType: "operation",
291
- operator: operator.image,
292
- args: [left, expr],
293
- loc: C.astFactory.sourceLocation(left, expr)
294
- });
295
- }, ACTION, MANY)
309
+ /**
310
+ * [[117]](https://www.w3.org/TR/sparql11-query/#rMultiplicativeExpression)
311
+ */
312
+ exports.multiplicativeExpression = {
313
+ name: 'multiplicativeExpression',
314
+ impl: ({ ACTION, CONSUME, MANY, SUBRULE1, SUBRULE2, OR }) => C => constructLeftDeep(() => SUBRULE1(exports.unaryExpression), () => {
315
+ const operator = OR([
316
+ { ALT: () => CONSUME(l.symbols.star) },
317
+ { ALT: () => CONSUME(l.symbols.slash) },
318
+ ]);
319
+ const expr = SUBRULE2(exports.unaryExpression);
320
+ return (left) => ({
321
+ type: 'expression',
322
+ subType: 'operation',
323
+ operator: operator.image,
324
+ args: [left, expr],
325
+ loc: C.astFactory.sourceLocation(left, expr),
326
+ });
327
+ }, ACTION, MANY),
296
328
  };
297
- const unaryExpression = {
298
- name: "unaryExpression",
299
- impl: ({ ACTION, CONSUME, SUBRULE1, SUBRULE2, OR1, OR2 }) => (C) => OR1([
300
- { ALT: () => SUBRULE1(primaryExpression) },
301
- { ALT: () => {
302
- const operator = OR2([
303
- { ALT: () => CONSUME(l.symbols.exclamation) },
304
- { ALT: () => CONSUME(l.symbols.opPlus) },
305
- { ALT: () => CONSUME(l.symbols.opMinus) }
306
- ]);
307
- const expr = SUBRULE2(primaryExpression);
308
- return ACTION(() => C.astFactory.expressionOperation(operator.image === "!" ? "!" : operator.image === "+" ? "UPLUS" : "UMINUS", [expr], C.astFactory.sourceLocation(operator, expr)));
309
- } }
310
- ])
329
+ /**
330
+ * [[118]](https://www.w3.org/TR/sparql11-query/#rUnaryExpression)
331
+ */
332
+ exports.unaryExpression = {
333
+ name: 'unaryExpression',
334
+ impl: ({ ACTION, CONSUME, SUBRULE1, SUBRULE2, OR1, OR2 }) => C => OR1([
335
+ { ALT: () => SUBRULE1(exports.primaryExpression) },
336
+ { ALT: () => {
337
+ const operator = OR2([
338
+ { ALT: () => CONSUME(l.symbols.exclamation) },
339
+ { ALT: () => CONSUME(l.symbols.opPlus) },
340
+ { ALT: () => CONSUME(l.symbols.opMinus) },
341
+ ]);
342
+ const expr = SUBRULE2(exports.primaryExpression);
343
+ return ACTION(() => C.astFactory.expressionOperation(operator.image === '!' ? '!' : (operator.image === '+' ? 'UPLUS' : 'UMINUS'), [expr], C.astFactory.sourceLocation(operator, expr)));
344
+ } },
345
+ ]),
311
346
  };
312
- const primaryExpression = {
313
- name: "primaryExpression",
314
- impl: ({ SUBRULE, OR }) => () => OR([
315
- { ALT: () => SUBRULE(brackettedExpression) },
316
- { ALT: () => SUBRULE(import_builtIn.builtInCall) },
317
- { ALT: () => SUBRULE(iriOrFunction) },
318
- { ALT: () => SUBRULE(import_literals.rdfLiteral) },
319
- { ALT: () => SUBRULE(import_literals.numericLiteral) },
320
- { ALT: () => SUBRULE(import_literals.booleanLiteral) },
321
- { ALT: () => SUBRULE(import_general.var_) }
322
- ])
347
+ /**
348
+ * [[119]](https://www.w3.org/TR/sparql11-query/#rPrimaryExpression)
349
+ */
350
+ exports.primaryExpression = {
351
+ name: 'primaryExpression',
352
+ impl: ({ SUBRULE, OR }) => () => OR([
353
+ { ALT: () => SUBRULE(exports.brackettedExpression) },
354
+ { ALT: () => SUBRULE(builtIn_js_1.builtInCall) },
355
+ { ALT: () => SUBRULE(exports.iriOrFunction) },
356
+ { ALT: () => SUBRULE(literals_js_1.rdfLiteral) },
357
+ { ALT: () => SUBRULE(literals_js_1.numericLiteral) },
358
+ { ALT: () => SUBRULE(literals_js_1.booleanLiteral) },
359
+ { ALT: () => SUBRULE(general_js_1.var_) },
360
+ ]),
323
361
  };
324
- const brackettedExpression = {
325
- name: "brackettedExpression",
326
- impl: ({ ACTION, SUBRULE, CONSUME }) => (C) => {
327
- const open = CONSUME(l.symbols.LParen);
328
- const expr = SUBRULE(expression);
329
- const close = CONSUME(l.symbols.RParen);
330
- return ACTION(() => {
331
- expr.loc = C.astFactory.sourceLocation(open, close);
332
- return expr;
333
- });
334
- }
362
+ /**
363
+ * [[120]](https://www.w3.org/TR/sparql11-query/#rBrackettedExpression)
364
+ */
365
+ exports.brackettedExpression = {
366
+ name: 'brackettedExpression',
367
+ impl: ({ ACTION, SUBRULE, CONSUME }) => (C) => {
368
+ const open = CONSUME(l.symbols.LParen);
369
+ const expr = SUBRULE(exports.expression);
370
+ const close = CONSUME(l.symbols.RParen);
371
+ return ACTION(() => {
372
+ expr.loc = C.astFactory.sourceLocation(open, close);
373
+ return expr;
374
+ });
375
+ },
335
376
  };
336
- const iriOrFunction = {
337
- name: "iriOrFunction",
338
- impl: ({ ACTION, SUBRULE, OPTION }) => (C) => {
339
- const iriVal = SUBRULE(import_literals.iri);
340
- const functionCall = OPTION(() => {
341
- const args = SUBRULE(argList);
342
- return ACTION(() => {
343
- const distinct = args.val.distinct;
344
- if (!C.parseMode.has("canParseAggregate") && distinct) {
345
- throw new Error(`DISTINCT implies that this function is an aggregated function, which is not allowed in this context.`);
377
+ /**
378
+ * [[128]](https://www.w3.org/TR/sparql11-query/#ririOrFunction)
379
+ */
380
+ exports.iriOrFunction = {
381
+ name: 'iriOrFunction',
382
+ impl: ({ ACTION, SUBRULE, OPTION }) => (C) => {
383
+ const iriVal = SUBRULE(literals_js_1.iri);
384
+ const functionCall = OPTION(() => {
385
+ const args = SUBRULE(exports.argList);
386
+ return ACTION(() => {
387
+ const distinct = args.val.distinct;
388
+ if (!C.parseMode.has('canParseAggregate') && distinct) {
389
+ throw new Error(`DISTINCT implies that this function is an aggregated function, which is not allowed in this context.`);
390
+ }
391
+ return {
392
+ type: 'expression',
393
+ subType: 'functionCall',
394
+ function: iriVal,
395
+ args: args.val.args,
396
+ distinct,
397
+ loc: C.astFactory.sourceLocation(iriVal, args),
398
+ };
399
+ });
400
+ });
401
+ return functionCall ?? iriVal;
402
+ },
403
+ gImpl: ({ SUBRULE }) => (ast, { astFactory: F }) => {
404
+ if (F.isTermNamed(ast)) {
405
+ SUBRULE(literals_js_1.iri, ast);
346
406
  }
347
- return {
348
- type: "expression",
349
- subType: "functionCall",
350
- function: iriVal,
351
- args: args.val.args,
352
- distinct,
353
- loc: C.astFactory.sourceLocation(iriVal, args)
354
- };
355
- });
356
- });
357
- return functionCall ?? iriVal;
358
- },
359
- gImpl: ({ SUBRULE }) => (ast, { astFactory: F }) => {
360
- if (F.isTermNamed(ast)) {
361
- SUBRULE(import_literals.iri, ast);
362
- } else {
363
- SUBRULE(import_literals.iri, ast.function);
364
- SUBRULE(argList, F.wrap({ args: ast.args, distinct: ast.distinct }, ast.loc));
365
- }
366
- }
407
+ else {
408
+ SUBRULE(literals_js_1.iri, ast.function);
409
+ SUBRULE(exports.argList, F.wrap({ args: ast.args, distinct: ast.distinct }, ast.loc));
410
+ }
411
+ },
367
412
  };
368
- // Annotate the CommonJS export names for ESM import in node:
369
- 0 && (module.exports = {
370
- additiveExpression,
371
- argList,
372
- brackettedExpression,
373
- conditionalAndExpression,
374
- conditionalOrExpression,
375
- expression,
376
- expressionList,
377
- iriOrFunction,
378
- multiplicativeExpression,
379
- numericExpression,
380
- primaryExpression,
381
- relationalExpression,
382
- unaryExpression,
383
- valueLogical
384
- });
413
+ //# sourceMappingURL=expression.js.map