@traqula/rules-sparql-1-1 0.0.1-alpha.10
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/LICENSE.txt +22 -0
- package/README.md +17 -0
- package/lib/RoundTripTypes.d.ts +379 -0
- package/lib/RoundTripTypes.js +2 -0
- package/lib/RoundTripTypes.js.map +1 -0
- package/lib/Sparql11types.d.ts +68 -0
- package/lib/Sparql11types.js +2 -0
- package/lib/Sparql11types.js.map +1 -0
- package/lib/SparqlParser.d.ts +23 -0
- package/lib/SparqlParser.js +32 -0
- package/lib/SparqlParser.js.map +1 -0
- package/lib/expressionHelpers.d.ts +45 -0
- package/lib/expressionHelpers.js +161 -0
- package/lib/expressionHelpers.js.map +1 -0
- package/lib/factory.d.ts +447 -0
- package/lib/factory.js +105 -0
- package/lib/factory.js.map +1 -0
- package/lib/factoryMixins/ContextFactory.d.ts +38 -0
- package/lib/factoryMixins/ContextFactory.js +30 -0
- package/lib/factoryMixins/ContextFactory.js.map +1 -0
- package/lib/factoryMixins/ExpressionFactory.d.ts +60 -0
- package/lib/factoryMixins/ExpressionFactory.js +83 -0
- package/lib/factoryMixins/ExpressionFactory.js.map +1 -0
- package/lib/factoryMixins/GraphRefFactory.d.ts +43 -0
- package/lib/factoryMixins/GraphRefFactory.js +51 -0
- package/lib/factoryMixins/GraphRefFactory.js.map +1 -0
- package/lib/factoryMixins/PathFactory.d.ts +51 -0
- package/lib/factoryMixins/PathFactory.js +68 -0
- package/lib/factoryMixins/PathFactory.js.map +1 -0
- package/lib/factoryMixins/Patternfactory.d.ts +55 -0
- package/lib/factoryMixins/Patternfactory.js +98 -0
- package/lib/factoryMixins/Patternfactory.js.map +1 -0
- package/lib/factoryMixins/QueryFactory.d.ts +41 -0
- package/lib/factoryMixins/QueryFactory.js +43 -0
- package/lib/factoryMixins/QueryFactory.js.map +1 -0
- package/lib/factoryMixins/SolutionModifiersFactory.d.ts +43 -0
- package/lib/factoryMixins/SolutionModifiersFactory.js +55 -0
- package/lib/factoryMixins/SolutionModifiersFactory.js.map +1 -0
- package/lib/factoryMixins/TermFactory.d.ts +76 -0
- package/lib/factoryMixins/TermFactory.js +84 -0
- package/lib/factoryMixins/TermFactory.js.map +1 -0
- package/lib/factoryMixins/UpdateOperationFactory.d.ts +68 -0
- package/lib/factoryMixins/UpdateOperationFactory.js +126 -0
- package/lib/factoryMixins/UpdateOperationFactory.js.map +1 -0
- package/lib/factoryMixins/mixins.d.ts +14 -0
- package/lib/factoryMixins/mixins.js +20 -0
- package/lib/factoryMixins/mixins.js.map +1 -0
- package/lib/grammar/builtIn.d.ts +89 -0
- package/lib/grammar/builtIn.js +247 -0
- package/lib/grammar/builtIn.js.map +1 -0
- package/lib/grammar/dataSetClause.d.ts +34 -0
- package/lib/grammar/dataSetClause.js +81 -0
- package/lib/grammar/dataSetClause.js.map +1 -0
- package/lib/grammar/expression.d.ts +63 -0
- package/lib/grammar/expression.js +383 -0
- package/lib/grammar/expression.js.map +1 -0
- package/lib/grammar/general.d.ts +36 -0
- package/lib/grammar/general.js +145 -0
- package/lib/grammar/general.js.map +1 -0
- package/lib/grammar/index.d.ts +12 -0
- package/lib/grammar/index.js +13 -0
- package/lib/grammar/index.js.map +1 -0
- package/lib/grammar/literals.d.ts +55 -0
- package/lib/grammar/literals.js +258 -0
- package/lib/grammar/literals.js.map +1 -0
- package/lib/grammar/propertyPaths.d.ts +43 -0
- package/lib/grammar/propertyPaths.js +182 -0
- package/lib/grammar/propertyPaths.js.map +1 -0
- package/lib/grammar/queryUnit/queryUnit.d.ts +48 -0
- package/lib/grammar/queryUnit/queryUnit.js +366 -0
- package/lib/grammar/queryUnit/queryUnit.js.map +1 -0
- package/lib/grammar/solutionModifier.d.ts +44 -0
- package/lib/grammar/solutionModifier.js +253 -0
- package/lib/grammar/solutionModifier.js.map +1 -0
- package/lib/grammar/tripleBlock.d.ts +36 -0
- package/lib/grammar/tripleBlock.js +357 -0
- package/lib/grammar/tripleBlock.js.map +1 -0
- package/lib/grammar/updateUnit/updateUnit.d.ts +95 -0
- package/lib/grammar/updateUnit/updateUnit.js +493 -0
- package/lib/grammar/updateUnit/updateUnit.js.map +1 -0
- package/lib/grammar/whereClause.d.ts +76 -0
- package/lib/grammar/whereClause.js +441 -0
- package/lib/grammar/whereClause.js.map +1 -0
- package/lib/grammar-helpers/utils.d.ts +12 -0
- package/lib/grammar-helpers/utils.js +16 -0
- package/lib/grammar-helpers/utils.js.map +1 -0
- package/lib/index.cjs +14565 -0
- package/lib/index.d.ts +10 -0
- package/lib/index.js +11 -0
- package/lib/index.js.map +1 -0
- package/lib/lexer/BuildinCalls.d.ts +126 -0
- package/lib/lexer/BuildinCalls.js +188 -0
- package/lib/lexer/BuildinCalls.js.map +1 -0
- package/lib/lexer/graph.d.ts +6 -0
- package/lib/lexer/graph.js +8 -0
- package/lib/lexer/graph.js.map +1 -0
- package/lib/lexer/index.d.ts +5 -0
- package/lib/lexer/index.js +6 -0
- package/lib/lexer/index.js.map +1 -0
- package/lib/lexer/lexer.d.ts +54 -0
- package/lib/lexer/lexer.js +70 -0
- package/lib/lexer/lexer.js.map +1 -0
- package/lib/lexer/symbols.d.ts +28 -0
- package/lib/lexer/symbols.js +29 -0
- package/lib/lexer/symbols.js.map +1 -0
- package/lib/lexer/terminals.d.ts +26 -0
- package/lib/lexer/terminals.js +63 -0
- package/lib/lexer/terminals.js.map +1 -0
- package/lib/utils.d.ts +5 -0
- package/lib/utils.js +24 -0
- package/lib/utils.js.map +1 -0
- package/lib/validation/validators.d.ts +14 -0
- package/lib/validation/validators.js +235 -0
- package/lib/validation/validators.js.map +1 -0
- package/package.json +48 -0
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
import * as l from '../lexer';
|
|
2
|
+
import { iri, verbA } from './literals';
|
|
3
|
+
/**
|
|
4
|
+
* [[88]](https://www.w3.org/TR/sparql11-query/#rPath)
|
|
5
|
+
*/
|
|
6
|
+
export const path = {
|
|
7
|
+
name: 'path',
|
|
8
|
+
impl: ({ SUBRULE }) => () => SUBRULE(pathAlternative, undefined),
|
|
9
|
+
};
|
|
10
|
+
export const pathGenerator = {
|
|
11
|
+
name: 'path',
|
|
12
|
+
gImpl: ({ PRINT, SUBRULE }) => (ast, { factory: F }, braces = true) => {
|
|
13
|
+
if (F.isTerm(ast) && F.isTermNamed(ast)) {
|
|
14
|
+
SUBRULE(iri, ast, undefined);
|
|
15
|
+
}
|
|
16
|
+
else {
|
|
17
|
+
F.printFilter(ast, () => braces && PRINT('('));
|
|
18
|
+
switch (ast.subType) {
|
|
19
|
+
case '|':
|
|
20
|
+
case '/': {
|
|
21
|
+
const [head, ...tail] = ast.items;
|
|
22
|
+
SUBRULE(pathGenerator, head, braces);
|
|
23
|
+
for (const val of tail) {
|
|
24
|
+
F.printFilter(ast, () => PRINT(ast.subType));
|
|
25
|
+
SUBRULE(pathGenerator, val, braces);
|
|
26
|
+
}
|
|
27
|
+
break;
|
|
28
|
+
}
|
|
29
|
+
case '^':
|
|
30
|
+
F.printFilter(ast, () => PRINT('^'));
|
|
31
|
+
SUBRULE(pathGenerator, ast.items[0], braces);
|
|
32
|
+
break;
|
|
33
|
+
case '?':
|
|
34
|
+
case '*':
|
|
35
|
+
case '+':
|
|
36
|
+
SUBRULE(pathGenerator, ast.items[0], braces);
|
|
37
|
+
F.printFilter(ast, () => PRINT(ast.subType));
|
|
38
|
+
break;
|
|
39
|
+
case '!':
|
|
40
|
+
F.printFilter(ast, () => PRINT('!'));
|
|
41
|
+
F.printFilter(ast, () => PRINT('('));
|
|
42
|
+
SUBRULE(pathGenerator, ast.items[0], false);
|
|
43
|
+
F.printFilter(ast, () => PRINT(')'));
|
|
44
|
+
break;
|
|
45
|
+
}
|
|
46
|
+
F.printFilter(ast, () => braces && PRINT(')'));
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
};
|
|
50
|
+
export function pathChainHelper(name, SEP, subType, subRule) {
|
|
51
|
+
return {
|
|
52
|
+
name,
|
|
53
|
+
impl: ({ ACTION, CONSUME, SUBRULE1, SUBRULE2, MANY }) => (C) => {
|
|
54
|
+
const head = SUBRULE1(subRule, undefined);
|
|
55
|
+
let tailEnd = head;
|
|
56
|
+
const tail = [];
|
|
57
|
+
MANY(() => {
|
|
58
|
+
CONSUME(SEP);
|
|
59
|
+
tailEnd = SUBRULE2(subRule, undefined);
|
|
60
|
+
tail.push(tailEnd);
|
|
61
|
+
});
|
|
62
|
+
return ACTION(() => tail.length === 0 ?
|
|
63
|
+
head :
|
|
64
|
+
C.factory.path(subType, [head, ...tail], C.factory.sourceLocation(head, tailEnd)));
|
|
65
|
+
},
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* [[92]](https://www.w3.org/TR/sparql11-query/#rPathEltOrInverse)
|
|
70
|
+
*/
|
|
71
|
+
export const pathEltOrInverse = {
|
|
72
|
+
name: 'pathEltOrInverse',
|
|
73
|
+
impl: ({ ACTION, CONSUME, SUBRULE1, SUBRULE2, OR }) => C => OR([
|
|
74
|
+
{ ALT: () => SUBRULE1(pathElt, undefined) },
|
|
75
|
+
{ ALT: () => {
|
|
76
|
+
const hat = CONSUME(l.symbols.hat);
|
|
77
|
+
const item = SUBRULE2(pathElt, undefined);
|
|
78
|
+
return ACTION(() => C.factory.path('^', [item], C.factory.sourceLocation(hat, item)));
|
|
79
|
+
} },
|
|
80
|
+
]),
|
|
81
|
+
};
|
|
82
|
+
/**
|
|
83
|
+
* [[90]](https://www.w3.org/TR/sparql11-query/#rPathSequence)
|
|
84
|
+
*/
|
|
85
|
+
export const pathSequence = pathChainHelper('pathSequence', l.symbols.slash, '/', pathEltOrInverse);
|
|
86
|
+
/**
|
|
87
|
+
* [[89]](https://www.w3.org/TR/sparql11-query/#rPathAlternative)
|
|
88
|
+
*/
|
|
89
|
+
export const pathAlternative = pathChainHelper('pathAlternative', l.symbols.pipe, '|', pathSequence);
|
|
90
|
+
/**
|
|
91
|
+
* [[91]](https://www.w3.org/TR/sparql11-query/#rPathElt)
|
|
92
|
+
*/
|
|
93
|
+
export const pathElt = {
|
|
94
|
+
name: 'pathElt',
|
|
95
|
+
impl: ({ ACTION, SUBRULE, OPTION }) => (C) => {
|
|
96
|
+
const item = SUBRULE(pathPrimary, undefined);
|
|
97
|
+
const modification = OPTION(() => SUBRULE(pathMod, undefined));
|
|
98
|
+
return ACTION(() => modification === undefined ?
|
|
99
|
+
item :
|
|
100
|
+
C.factory.path(modification.image, [item], C.factory.sourceLocation(item, modification)));
|
|
101
|
+
},
|
|
102
|
+
};
|
|
103
|
+
/**
|
|
104
|
+
* [[93]](https://www.w3.org/TR/sparql11-query/#rPathMod)
|
|
105
|
+
*/
|
|
106
|
+
export const pathMod = {
|
|
107
|
+
name: 'pathMod',
|
|
108
|
+
impl: ({ CONSUME, OR }) => () => OR([
|
|
109
|
+
{ ALT: () => CONSUME(l.symbols.question) },
|
|
110
|
+
{ ALT: () => CONSUME(l.symbols.star) },
|
|
111
|
+
{ ALT: () => CONSUME(l.symbols.opPlus) },
|
|
112
|
+
]),
|
|
113
|
+
};
|
|
114
|
+
/**
|
|
115
|
+
* [[94]](https://www.w3.org/TR/sparql11-query/#rPathPrimary)
|
|
116
|
+
*/
|
|
117
|
+
export const pathPrimary = {
|
|
118
|
+
name: 'pathPrimary',
|
|
119
|
+
impl: ({ SUBRULE, CONSUME, OR }) => () => OR([
|
|
120
|
+
{ ALT: () => SUBRULE(iri, undefined) },
|
|
121
|
+
{ ALT: () => SUBRULE(verbA, undefined) },
|
|
122
|
+
{ ALT: () => SUBRULE(pathNegatedPropertySet, undefined) },
|
|
123
|
+
{ ALT: () => {
|
|
124
|
+
CONSUME(l.symbols.LParen);
|
|
125
|
+
const resRecursive = SUBRULE(path, undefined);
|
|
126
|
+
CONSUME(l.symbols.RParen);
|
|
127
|
+
return resRecursive;
|
|
128
|
+
} },
|
|
129
|
+
]),
|
|
130
|
+
};
|
|
131
|
+
/**
|
|
132
|
+
* [[95]](https://www.w3.org/TR/sparql11-query/#rPathNegatedPropertySet)
|
|
133
|
+
*/
|
|
134
|
+
export const pathNegatedPropertySet = {
|
|
135
|
+
name: 'pathNegatedPropertySet',
|
|
136
|
+
impl: ({ ACTION, CONSUME, SUBRULE1, SUBRULE2, SUBRULE3, OR, MANY }) => (C) => {
|
|
137
|
+
const exclamation = CONSUME(l.symbols.exclamation);
|
|
138
|
+
return OR([
|
|
139
|
+
{ ALT: () => {
|
|
140
|
+
const noAlternative = SUBRULE1(pathOneInPropertySet, undefined);
|
|
141
|
+
return ACTION(() => C.factory.path('!', [noAlternative], C.factory.sourceLocation(exclamation, noAlternative)));
|
|
142
|
+
} },
|
|
143
|
+
{ ALT: () => {
|
|
144
|
+
const open = CONSUME(l.symbols.LParen);
|
|
145
|
+
const head = SUBRULE2(pathOneInPropertySet, undefined);
|
|
146
|
+
const tail = [];
|
|
147
|
+
MANY(() => {
|
|
148
|
+
CONSUME(l.symbols.pipe);
|
|
149
|
+
const item = SUBRULE3(pathOneInPropertySet, undefined);
|
|
150
|
+
tail.push(item);
|
|
151
|
+
});
|
|
152
|
+
const close = CONSUME(l.symbols.RParen);
|
|
153
|
+
return ACTION(() => {
|
|
154
|
+
const F = C.factory;
|
|
155
|
+
if (tail.length === 0) {
|
|
156
|
+
return F.path('!', [head], F.sourceLocation(exclamation, close));
|
|
157
|
+
}
|
|
158
|
+
return F.path('!', [F.path('|', [head, ...tail], F.sourceLocation(open, close))], F.sourceLocation(exclamation, close));
|
|
159
|
+
});
|
|
160
|
+
} },
|
|
161
|
+
]);
|
|
162
|
+
},
|
|
163
|
+
};
|
|
164
|
+
/**
|
|
165
|
+
* [[96]](https://www.w3.org/TR/sparql11-query/#rPathOneInPropertySet)
|
|
166
|
+
*/
|
|
167
|
+
export const pathOneInPropertySet = {
|
|
168
|
+
name: 'pathOneInPropertySet',
|
|
169
|
+
impl: ({ ACTION, CONSUME, SUBRULE1, SUBRULE2, OR1, OR2 }) => C => OR1([
|
|
170
|
+
{ ALT: () => SUBRULE1(iri, undefined) },
|
|
171
|
+
{ ALT: () => SUBRULE1(verbA, undefined) },
|
|
172
|
+
{ ALT: () => {
|
|
173
|
+
const hat = CONSUME(l.symbols.hat);
|
|
174
|
+
const item = OR2([
|
|
175
|
+
{ ALT: () => SUBRULE2(iri, undefined) },
|
|
176
|
+
{ ALT: () => SUBRULE2(verbA, undefined) },
|
|
177
|
+
]);
|
|
178
|
+
return ACTION(() => C.factory.path('^', [item], C.factory.sourceLocation(hat, item)));
|
|
179
|
+
} },
|
|
180
|
+
]),
|
|
181
|
+
};
|
|
182
|
+
//# sourceMappingURL=propertyPaths.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"propertyPaths.js","sourceRoot":"","sources":["propertyPaths.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,CAAC,MAAM,UAAU,CAAC;AAM9B,OAAO,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAExC;;GAEG;AACH,MAAM,CAAC,MAAM,IAAI,GAA4C;IAC3D,IAAI,EAAE,MAAM;IACZ,IAAI,EAAE,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,eAAe,EAAE,SAAS,CAAC;CACjE,CAAC;AAEF,MAAM,CAAC,MAAM,aAAa,GAA2D;IACnF,IAAI,EAAE,MAAM;IACZ,KAAK,EAAE,CAAC,EAAE,KAAK,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC,CAAC,GAAG,EAAE,EAAE,OAAO,EAAE,CAAC,EAAE,EAAE,MAAM,GAAG,IAAI,EAAE,EAAE;QACpE,IAAI,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,WAAW,CAAC,GAAG,CAAC,EAAE,CAAC;YACxC,OAAO,CAAC,GAAG,EAAE,GAAG,EAAE,SAAS,CAAC,CAAC;QAC/B,CAAC;aAAM,CAAC;YACN,CAAC,CAAC,WAAW,CAAC,GAAG,E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Q,EAAE,QAAQ,EAAE,GAAG,EAAE,GAAG,EAAE,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAC/D,GAAG,CAA2B;QAC5B,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC,QAAQ,CAAC,GAAG,EAAE,SAAS,CAAC,EAAE;QACvC,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC,QAAQ,CAAC,KAAK,EAAE,SAAS,CAAC,EAAE;QACzC,EAAE,GAAG,EAAE,GAAG,EAAE;gBACV,MAAM,GAAG,GAAG,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;gBACnC,MAAM,IAAI,GAAG,GAAG,CAAU;oBACxB,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC,QAAQ,CAAC,GAAG,EAAE,SAAS,CAAC,EAAE;oBACvC,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC,QAAQ,CAAC,KAAK,EAAE,SAAS,CAAC,EAAE;iBAC1C,CAAC,CAAC;gBACH,OAAO,MAAM,CAAC,GAAG,EAAE,CACjB,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,EAAE,CAAE,IAAI,CAAE,EAAE,CAAC,CAAC,OAAO,CAAC,cAAc,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC;YACxE,CAAC,EAAE;KACJ,CAAC;CACL,CAAC","sourcesContent":["import type { RuleDefReturn } from '@traqula/core';\nimport type { IToken, TokenType } from 'chevrotain';\nimport * as l from '../lexer';\nimport type { TermIri, PathNegatedElt, Path, PathModified, PathNegated } from '../RoundTripTypes';\nimport type {\n SparqlGeneratorRule,\n SparqlGrammarRule,\n} from '../Sparql11types';\nimport { iri, verbA } from './literals';\n\n/**\n * [[88]](https://www.w3.org/TR/sparql11-query/#rPath)\n */\nexport const path: SparqlGrammarRule<'path', Path> = <const> {\n name: 'path',\n impl: ({ SUBRULE }) => () => SUBRULE(pathAlternative, undefined),\n};\n\nexport const pathGenerator: SparqlGeneratorRule<'path', Path, boolean | undefined> = {\n name: 'path',\n gImpl: ({ PRINT, SUBRULE }) => (ast, { factory: F }, braces = true) => {\n if (F.isTerm(ast) && F.isTermNamed(ast)) {\n SUBRULE(iri, ast, undefined);\n } else {\n F.printFilter(ast, () => braces && PRINT('('));\n switch (ast.subType) {\n case '|':\n case '/': {\n const [ head, ...tail ] = ast.items;\n SUBRULE(pathGenerator, head, braces);\n for (const val of tail) {\n F.printFilter(ast, () => PRINT(ast.subType));\n SUBRULE(pathGenerator, val, braces);\n }\n break;\n }\n case '^':\n F.printFilter(ast, () => PRINT('^'));\n SUBRULE(pathGenerator, ast.items[0], braces);\n break;\n case '?':\n case '*':\n case '+':\n SUBRULE(pathGenerator, ast.items[0], braces);\n F.printFilter(ast, () => PRINT(ast.subType));\n break;\n case '!':\n F.printFilter(ast, () => PRINT('!'));\n F.printFilter(ast, () => PRINT('('));\n SUBRULE(pathGenerator, ast.items[0], false);\n F.printFilter(ast, () => PRINT(')'));\n break;\n }\n F.printFilter(ast, () => braces && PRINT(')'));\n }\n },\n};\n\nexport function pathChainHelper<T extends string>(\n name: T,\n SEP: TokenType,\n subType: '|' | '/',\n subRule: SparqlGrammarRule<string, Path>,\n): SparqlGrammarRule<T, Path | TermIri> {\n return {\n name,\n impl: ({ ACTION, CONSUME, SUBRULE1, SUBRULE2, MANY }) => (C) => {\n const head = SUBRULE1(subRule, undefined);\n let tailEnd: Path = head;\n const tail: Path[] = [];\n\n MANY(() => {\n CONSUME(SEP);\n tailEnd = SUBRULE2(subRule, undefined);\n tail.push(tailEnd);\n });\n\n return ACTION(() => tail.length === 0 ?\n head :\n C.factory.path(subType, [ head, ...tail ], C.factory.sourceLocation(head, tailEnd)));\n },\n };\n}\n\n/**\n * [[92]](https://www.w3.org/TR/sparql11-query/#rPathEltOrInverse)\n */\nexport const pathEltOrInverse: SparqlGrammarRule<'pathEltOrInverse', PathModified | Path> = <const> {\n name: 'pathEltOrInverse',\n impl: ({ ACTION, CONSUME, SUBRULE1, SUBRULE2, OR }) => C => OR<Path | TermIri>([\n { ALT: () => SUBRULE1(pathElt, undefined) },\n { ALT: () => {\n const hat = CONSUME(l.symbols.hat);\n const item = SUBRULE2(pathElt, undefined);\n return ACTION(() => C.factory.path('^', [ item ], C.factory.sourceLocation(hat, item)));\n } },\n ]),\n};\n\n/**\n * [[90]](https://www.w3.org/TR/sparql11-query/#rPathSequence)\n */\nexport const pathSequence = pathChainHelper('pathSequence', l.symbols.slash, '/', pathEltOrInverse);\n\n/**\n * [[89]](https://www.w3.org/TR/sparql11-query/#rPathAlternative)\n */\nexport const pathAlternative = pathChainHelper('pathAlternative', l.symbols.pipe, '|', pathSequence);\n\n/**\n * [[91]](https://www.w3.org/TR/sparql11-query/#rPathElt)\n */\nexport const pathElt: SparqlGrammarRule<'pathElt', PathModified | Path> = <const> {\n name: 'pathElt',\n impl: ({ ACTION, SUBRULE, OPTION }) => (C) => {\n const item = SUBRULE(pathPrimary, undefined);\n const modification = OPTION(() => SUBRULE(pathMod, undefined));\n return ACTION(() => modification === undefined ?\n item :\n C.factory.path(modification.image, [ item ], C.factory.sourceLocation(item, modification)));\n },\n};\n\n/**\n * [[93]](https://www.w3.org/TR/sparql11-query/#rPathMod)\n */\nexport const pathMod: SparqlGrammarRule<'pathMod', IToken & { image: '*' | '+' | '?' }> = <const> {\n name: 'pathMod',\n impl: ({ CONSUME, OR }) => () => OR<RuleDefReturn<typeof pathMod>>([\n { ALT: () => <RuleDefReturn<typeof pathMod>> CONSUME(l.symbols.question) },\n { ALT: () => <RuleDefReturn<typeof pathMod>> CONSUME(l.symbols.star) },\n { ALT: () => <RuleDefReturn<typeof pathMod>> CONSUME(l.symbols.opPlus) },\n ]),\n};\n\n/**\n * [[94]](https://www.w3.org/TR/sparql11-query/#rPathPrimary)\n */\nexport const pathPrimary: SparqlGrammarRule<'pathPrimary', Path> = <const> {\n name: 'pathPrimary',\n impl: ({ SUBRULE, CONSUME, OR }) => () => OR<Path>([\n { ALT: () => SUBRULE(iri, undefined) },\n { ALT: () => SUBRULE(verbA, undefined) },\n { ALT: () => SUBRULE(pathNegatedPropertySet, undefined) },\n { ALT: () => {\n CONSUME(l.symbols.LParen);\n const resRecursive = SUBRULE(path, undefined);\n CONSUME(l.symbols.RParen);\n return resRecursive;\n } },\n ]),\n};\n\n/**\n * [[95]](https://www.w3.org/TR/sparql11-query/#rPathNegatedPropertySet)\n */\nexport const pathNegatedPropertySet: SparqlGrammarRule<'pathNegatedPropertySet', PathNegated> = <const> {\n name: 'pathNegatedPropertySet',\n impl: ({ ACTION, CONSUME, SUBRULE1, SUBRULE2, SUBRULE3, OR, MANY }) => (C) => {\n const exclamation = CONSUME(l.symbols.exclamation);\n return OR<PathNegated>([\n { ALT: () => {\n const noAlternative = SUBRULE1(pathOneInPropertySet, undefined);\n return ACTION(() =>\n C.factory.path('!', [ noAlternative ], C.factory.sourceLocation(exclamation, noAlternative)));\n } },\n { ALT: () => {\n const open = CONSUME(l.symbols.LParen);\n\n const head = SUBRULE2(pathOneInPropertySet, undefined);\n const tail: (TermIri | PathNegatedElt)[] = [];\n MANY(() => {\n CONSUME(l.symbols.pipe);\n const item = SUBRULE3(pathOneInPropertySet, undefined);\n tail.push(item);\n });\n\n const close = CONSUME(l.symbols.RParen);\n\n return ACTION(() => {\n const F = C.factory;\n if (tail.length === 0) {\n return F.path('!', [ head ], F.sourceLocation(exclamation, close));\n }\n return F.path(\n '!',\n [ F.path('|', [ head, ...tail ], F.sourceLocation(open, close)) ],\n F.sourceLocation(exclamation, close),\n );\n });\n } },\n ]);\n },\n};\n\n/**\n * [[96]](https://www.w3.org/TR/sparql11-query/#rPathOneInPropertySet)\n */\nexport const pathOneInPropertySet: SparqlGrammarRule<'pathOneInPropertySet', TermIri | PathNegatedElt> = <const> {\n name: 'pathOneInPropertySet',\n impl: ({ ACTION, CONSUME, SUBRULE1, SUBRULE2, OR1, OR2 }) => C =>\n OR1<TermIri | PathNegatedElt>([\n { ALT: () => SUBRULE1(iri, undefined) },\n { ALT: () => SUBRULE1(verbA, undefined) },\n { ALT: () => {\n const hat = CONSUME(l.symbols.hat);\n const item = OR2<TermIri>([\n { ALT: () => SUBRULE2(iri, undefined) },\n { ALT: () => SUBRULE2(verbA, undefined) },\n ]);\n return ACTION(() =>\n C.factory.path('^', [ item ], C.factory.sourceLocation(hat, item)));\n } },\n ]),\n};\n"]}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type { Wrap } from '@traqula/core';
|
|
2
|
+
import type { PatternBgp, PatternValues, Query, QueryAsk, QueryConstruct, QueryDescribe, QuerySelect, SubSelect } from '../../RoundTripTypes';
|
|
3
|
+
import type { SparqlGrammarRule, SparqlRule } from '../../Sparql11types';
|
|
4
|
+
/**
|
|
5
|
+
* [[1]](https://www.w3.org/TR/sparql11-query/#rQueryUnit)
|
|
6
|
+
*/
|
|
7
|
+
export declare const queryUnit: SparqlGrammarRule<'queryUnit', Query>;
|
|
8
|
+
export type HandledByBase = 'type' | 'context' | 'values';
|
|
9
|
+
/**
|
|
10
|
+
* [[2]](https://www.w3.org/TR/sparql11-query/#rQuery)
|
|
11
|
+
*/
|
|
12
|
+
export declare const query: SparqlRule<'query', Query>;
|
|
13
|
+
/**
|
|
14
|
+
* [[7]](https://www.w3.org/TR/sparql11-query/#rSelectQuery)
|
|
15
|
+
*/
|
|
16
|
+
export declare const selectQuery: SparqlRule<'selectQuery', Omit<QuerySelect, HandledByBase>>;
|
|
17
|
+
/**
|
|
18
|
+
* [[8]](https://www.w3.org/TR/sparql11-query/#rSubSelect)
|
|
19
|
+
*/
|
|
20
|
+
export declare const subSelect: SparqlGrammarRule<'subSelect', SubSelect>;
|
|
21
|
+
/**
|
|
22
|
+
* [[9]](https://www.w3.org/TR/sparql11-query/#rSelectClause)
|
|
23
|
+
*/
|
|
24
|
+
export declare const selectClause: SparqlRule<'selectClause', Wrap<Pick<QuerySelect, 'variables' | 'distinct' | 'reduced'>>>;
|
|
25
|
+
/**
|
|
26
|
+
* [[10]](https://www.w3.org/TR/sparql11-query/#rConstructQuery)
|
|
27
|
+
*/
|
|
28
|
+
export declare const constructQuery: SparqlRule<'constructQuery', Omit<QueryConstruct, HandledByBase>>;
|
|
29
|
+
/**
|
|
30
|
+
* [[11]](https://www.w3.org/TR/sparql11-query/#rDescribeQuery)
|
|
31
|
+
*/
|
|
32
|
+
export declare const describeQuery: SparqlRule<'describeQuery', Omit<QueryDescribe, HandledByBase>>;
|
|
33
|
+
/**
|
|
34
|
+
* [[12]](https://www.w3.org/TR/sparql11-query/#rAskQuery)
|
|
35
|
+
*/
|
|
36
|
+
export declare const askQuery: SparqlRule<'askQuery', Omit<QueryAsk, HandledByBase>>;
|
|
37
|
+
/**
|
|
38
|
+
* [[28]](https://www.w3.org/TR/sparql11-query/#rValuesClause)
|
|
39
|
+
*/
|
|
40
|
+
export declare const valuesClause: SparqlGrammarRule<'valuesClause', PatternValues | undefined>;
|
|
41
|
+
/**
|
|
42
|
+
* [[73]](https://www.w3.org/TR/sparql11-query/#ConstructTemplate)
|
|
43
|
+
*/
|
|
44
|
+
export declare const constructTemplate: SparqlGrammarRule<'constructTemplate', Wrap<PatternBgp>>;
|
|
45
|
+
/**
|
|
46
|
+
* [[12]](https://www.w3.org/TR/sparql11-query/#rConstructTriples)
|
|
47
|
+
*/
|
|
48
|
+
export declare const constructTriples: SparqlGrammarRule<'constructTriples', PatternBgp>;
|
|
@@ -0,0 +1,366 @@
|
|
|
1
|
+
import * as l from '../../lexer';
|
|
2
|
+
import { queryIsGood } from '../../validation/validators';
|
|
3
|
+
import { datasetClauseStar } from '../dataSetClause';
|
|
4
|
+
import { expression } from '../expression';
|
|
5
|
+
import { prologue, var_, varOrIri, varOrTerm } from '../general';
|
|
6
|
+
import { solutionModifier } from '../solutionModifier';
|
|
7
|
+
import { triplesBlock, triplesTemplate } from '../tripleBlock';
|
|
8
|
+
import { inlineData, whereClause } from '../whereClause';
|
|
9
|
+
/**
|
|
10
|
+
* [[1]](https://www.w3.org/TR/sparql11-query/#rQueryUnit)
|
|
11
|
+
*/
|
|
12
|
+
export const queryUnit = {
|
|
13
|
+
name: 'queryUnit',
|
|
14
|
+
impl: ({ SUBRULE }) => () => SUBRULE(query, undefined),
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* [[2]](https://www.w3.org/TR/sparql11-query/#rQuery)
|
|
18
|
+
*/
|
|
19
|
+
export const query = {
|
|
20
|
+
name: 'query',
|
|
21
|
+
impl: ({ ACTION, SUBRULE, OR }) => (C) => {
|
|
22
|
+
const prologueValues = SUBRULE(prologue, undefined);
|
|
23
|
+
const subType = OR([
|
|
24
|
+
{ ALT: () => SUBRULE(selectQuery, undefined) },
|
|
25
|
+
{ ALT: () => SUBRULE(constructQuery, undefined) },
|
|
26
|
+
{ ALT: () => SUBRULE(describeQuery, undefined) },
|
|
27
|
+
{ ALT: () => SUBRULE(askQuery, undefined) },
|
|
28
|
+
]);
|
|
29
|
+
const values = SUBRULE(valuesClause, undefined);
|
|
30
|
+
return ACTION(() => ({
|
|
31
|
+
context: prologueValues,
|
|
32
|
+
...subType,
|
|
33
|
+
type: 'query',
|
|
34
|
+
...(values && { values }),
|
|
35
|
+
loc: C.factory.sourceLocation(prologueValues.at(0), subType, values),
|
|
36
|
+
}));
|
|
37
|
+
},
|
|
38
|
+
gImpl: ({ SUBRULE }) => (ast, { factory: F }) => {
|
|
39
|
+
SUBRULE(prologue, ast.context, undefined);
|
|
40
|
+
if (F.isQuerySelect(ast)) {
|
|
41
|
+
SUBRULE(selectQuery, ast, undefined);
|
|
42
|
+
}
|
|
43
|
+
else if (F.isQueryConstruct(ast)) {
|
|
44
|
+
SUBRULE(constructQuery, ast, undefined);
|
|
45
|
+
}
|
|
46
|
+
else if (F.isQueryDescribe(ast)) {
|
|
47
|
+
SUBRULE(describeQuery, ast, undefined);
|
|
48
|
+
}
|
|
49
|
+
else if (F.isQueryAsk(ast)) {
|
|
50
|
+
SUBRULE(askQuery, ast, undefined);
|
|
51
|
+
}
|
|
52
|
+
if (ast.values) {
|
|
53
|
+
SUBRULE(inlineData, ast.values, undefined);
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
};
|
|
57
|
+
/**
|
|
58
|
+
* [[7]](https://www.w3.org/TR/sparql11-query/#rSelectQuery)
|
|
59
|
+
*/
|
|
60
|
+
export const selectQuery = {
|
|
61
|
+
name: 'selectQuery',
|
|
62
|
+
impl: ({ ACTION, SUBRULE }) => (C) => {
|
|
63
|
+
const selectVal = SUBRULE(selectClause, undefined);
|
|
64
|
+
const from = SUBRULE(datasetClauseStar, undefined);
|
|
65
|
+
const where = SUBRULE(whereClause, undefined);
|
|
66
|
+
const modifiers = SUBRULE(solutionModifier, undefined);
|
|
67
|
+
return ACTION(() => {
|
|
68
|
+
const ret = {
|
|
69
|
+
subType: 'select',
|
|
70
|
+
where: where.val,
|
|
71
|
+
solutionModifiers: modifiers,
|
|
72
|
+
datasets: from,
|
|
73
|
+
...selectVal.val,
|
|
74
|
+
loc: C.factory.sourceLocation(selectVal, where, modifiers.group, modifiers.having, modifiers.order, modifiers.limitOffset),
|
|
75
|
+
};
|
|
76
|
+
queryIsGood(ret);
|
|
77
|
+
return ret;
|
|
78
|
+
});
|
|
79
|
+
},
|
|
80
|
+
gImpl: ({ SUBRULE }) => (ast, { factory: F }) => {
|
|
81
|
+
SUBRULE(selectClause, F.wrap({
|
|
82
|
+
variables: ast.variables,
|
|
83
|
+
distinct: ast.distinct,
|
|
84
|
+
reduced: ast.reduced,
|
|
85
|
+
}, F.sourceLocation(...ast.variables)), undefined);
|
|
86
|
+
SUBRULE(datasetClauseStar, ast.datasets, undefined);
|
|
87
|
+
SUBRULE(whereClause, F.wrap(ast.where, ast.where.loc), undefined);
|
|
88
|
+
SUBRULE(solutionModifier, ast.solutionModifiers, undefined);
|
|
89
|
+
},
|
|
90
|
+
};
|
|
91
|
+
/**
|
|
92
|
+
* [[8]](https://www.w3.org/TR/sparql11-query/#rSubSelect)
|
|
93
|
+
*/
|
|
94
|
+
export const subSelect = {
|
|
95
|
+
name: 'subSelect',
|
|
96
|
+
impl: ({ ACTION, SUBRULE }) => (C) => {
|
|
97
|
+
const selectVal = SUBRULE(selectClause, undefined);
|
|
98
|
+
const where = SUBRULE(whereClause, undefined);
|
|
99
|
+
const modifiers = SUBRULE(solutionModifier, undefined);
|
|
100
|
+
const values = SUBRULE(valuesClause, undefined);
|
|
101
|
+
return ACTION(() => C.factory.querySelect({
|
|
102
|
+
where: where.val,
|
|
103
|
+
datasets: C.factory.datasetClauses([], C.factory.sourceLocation()),
|
|
104
|
+
context: [],
|
|
105
|
+
solutionModifiers: modifiers,
|
|
106
|
+
...selectVal.val,
|
|
107
|
+
...(values && { values }),
|
|
108
|
+
}, C.factory.sourceLocation(selectVal, where, modifiers.group, modifiers.having, modifiers.order, modifiers.limitOffset, values)));
|
|
109
|
+
},
|
|
110
|
+
};
|
|
111
|
+
/**
|
|
112
|
+
* [[9]](https://www.w3.org/TR/sparql11-query/#rSelectClause)
|
|
113
|
+
*/
|
|
114
|
+
export const selectClause = {
|
|
115
|
+
name: 'selectClause',
|
|
116
|
+
impl: ({ ACTION, AT_LEAST_ONE, SUBRULE1, SUBRULE2, CONSUME, OPTION, OR1, OR2, OR3, }) => (C) => {
|
|
117
|
+
const select = CONSUME(l.select);
|
|
118
|
+
const couldParseAgg = ACTION(() => C.parseMode.has('canParseAggregate') || !C.parseMode.add('canParseAggregate'));
|
|
119
|
+
const distinctAndReduced = OPTION(() => OR1([
|
|
120
|
+
{ ALT: () => {
|
|
121
|
+
CONSUME(l.distinct);
|
|
122
|
+
return [true, false];
|
|
123
|
+
} },
|
|
124
|
+
{ ALT: () => {
|
|
125
|
+
CONSUME(l.reduced);
|
|
126
|
+
return [false, true];
|
|
127
|
+
} },
|
|
128
|
+
])) ?? [false, false];
|
|
129
|
+
const distRed = ACTION(() => {
|
|
130
|
+
const [distinct, reduced] = distinctAndReduced;
|
|
131
|
+
return {
|
|
132
|
+
...(distinct && { distinct }),
|
|
133
|
+
...(reduced && { reduced }),
|
|
134
|
+
};
|
|
135
|
+
});
|
|
136
|
+
let last;
|
|
137
|
+
const val = OR2([
|
|
138
|
+
{ ALT: () => {
|
|
139
|
+
const star = CONSUME(l.symbols.star);
|
|
140
|
+
return ACTION(() => {
|
|
141
|
+
last = star;
|
|
142
|
+
return { variables: [C.factory.wildcard(C.factory.sourceLocation(star))], ...distRed };
|
|
143
|
+
});
|
|
144
|
+
} },
|
|
145
|
+
{ ALT: () => {
|
|
146
|
+
const usedVars = [];
|
|
147
|
+
const variables = [];
|
|
148
|
+
AT_LEAST_ONE(() => OR3([
|
|
149
|
+
{ ALT: () => {
|
|
150
|
+
const raw = SUBRULE1(var_, undefined);
|
|
151
|
+
ACTION(() => {
|
|
152
|
+
if (usedVars.some(v => v.value === raw.value)) {
|
|
153
|
+
throw new Error(`Variable ${raw.value} used more than once in SELECT clause`);
|
|
154
|
+
}
|
|
155
|
+
usedVars.push(raw);
|
|
156
|
+
variables.push(raw);
|
|
157
|
+
last = raw;
|
|
158
|
+
});
|
|
159
|
+
} },
|
|
160
|
+
{ ALT: () => {
|
|
161
|
+
const open = CONSUME(l.symbols.LParen);
|
|
162
|
+
const expr = SUBRULE1(expression, undefined);
|
|
163
|
+
CONSUME(l.as);
|
|
164
|
+
const variable = SUBRULE2(var_, undefined);
|
|
165
|
+
const close = CONSUME(l.symbols.RParen);
|
|
166
|
+
ACTION(() => {
|
|
167
|
+
last = close;
|
|
168
|
+
if (usedVars.some(v => v.value === variable.value)) {
|
|
169
|
+
throw new Error(`Variable ${variable.value} used more than once in SELECT clause`);
|
|
170
|
+
}
|
|
171
|
+
usedVars.push(variable);
|
|
172
|
+
variables.push(C.factory.patternBind(expr, variable, C.factory.sourceLocation(open, last)));
|
|
173
|
+
});
|
|
174
|
+
} },
|
|
175
|
+
]));
|
|
176
|
+
return { variables, ...distRed };
|
|
177
|
+
} },
|
|
178
|
+
]);
|
|
179
|
+
ACTION(() => !couldParseAgg && C.parseMode.delete('canParseAggregate'));
|
|
180
|
+
return ACTION(() => C.factory.wrap(val, C.factory.sourceLocation(select, last)));
|
|
181
|
+
},
|
|
182
|
+
gImpl: ({ SUBRULE, PRINT_WORD }) => (ast, { factory: F }) => {
|
|
183
|
+
F.printFilter(ast, () => {
|
|
184
|
+
PRINT_WORD('SELECT');
|
|
185
|
+
if (ast.val.distinct) {
|
|
186
|
+
PRINT_WORD('DISTINCT');
|
|
187
|
+
}
|
|
188
|
+
else if (ast.val.reduced) {
|
|
189
|
+
PRINT_WORD('REDUCED');
|
|
190
|
+
}
|
|
191
|
+
});
|
|
192
|
+
for (const variable of ast.val.variables) {
|
|
193
|
+
if (F.isWildcard(variable)) {
|
|
194
|
+
F.printFilter(ast, () => PRINT_WORD('*'));
|
|
195
|
+
}
|
|
196
|
+
else if (F.isTerm(variable)) {
|
|
197
|
+
SUBRULE(var_, variable, undefined);
|
|
198
|
+
}
|
|
199
|
+
else {
|
|
200
|
+
F.printFilter(ast, () => PRINT_WORD('('));
|
|
201
|
+
SUBRULE(expression, variable.expression, undefined);
|
|
202
|
+
F.printFilter(ast, () => PRINT_WORD('AS'));
|
|
203
|
+
SUBRULE(var_, variable.variable, undefined);
|
|
204
|
+
F.printFilter(ast, () => PRINT_WORD(')'));
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
},
|
|
208
|
+
};
|
|
209
|
+
/**
|
|
210
|
+
* [[10]](https://www.w3.org/TR/sparql11-query/#rConstructQuery)
|
|
211
|
+
*/
|
|
212
|
+
export const constructQuery = {
|
|
213
|
+
name: 'constructQuery',
|
|
214
|
+
impl: ({ ACTION, SUBRULE1, SUBRULE2, CONSUME, OR }) => (C) => {
|
|
215
|
+
const construct = CONSUME(l.construct);
|
|
216
|
+
return OR([
|
|
217
|
+
{ ALT: () => {
|
|
218
|
+
const template = SUBRULE1(constructTemplate, undefined);
|
|
219
|
+
const from = SUBRULE1(datasetClauseStar, undefined);
|
|
220
|
+
const where = SUBRULE1(whereClause, undefined);
|
|
221
|
+
const modifiers = SUBRULE1(solutionModifier, undefined);
|
|
222
|
+
return ACTION(() => ({
|
|
223
|
+
subType: 'construct',
|
|
224
|
+
template: template.val,
|
|
225
|
+
datasets: from,
|
|
226
|
+
where: where.val,
|
|
227
|
+
solutionModifiers: modifiers,
|
|
228
|
+
loc: C.factory.sourceLocation(construct, where, modifiers.group, modifiers.having, modifiers.order, modifiers.limitOffset),
|
|
229
|
+
}));
|
|
230
|
+
} },
|
|
231
|
+
{ ALT: () => {
|
|
232
|
+
const from = SUBRULE2(datasetClauseStar, undefined);
|
|
233
|
+
CONSUME(l.where);
|
|
234
|
+
// ConstructTemplate is same as '{' TriplesTemplate? '}'
|
|
235
|
+
const template = SUBRULE2(constructTemplate, undefined);
|
|
236
|
+
const modifiers = SUBRULE2(solutionModifier, undefined);
|
|
237
|
+
return ACTION(() => ({
|
|
238
|
+
subType: 'construct',
|
|
239
|
+
template: template.val,
|
|
240
|
+
datasets: from,
|
|
241
|
+
where: C.factory.patternGroup([template.val], C.factory.sourceLocation()),
|
|
242
|
+
solutionModifiers: modifiers,
|
|
243
|
+
loc: C.factory.sourceLocation(construct, template, modifiers.group, modifiers.having, modifiers.order, modifiers.limitOffset),
|
|
244
|
+
}));
|
|
245
|
+
} },
|
|
246
|
+
]);
|
|
247
|
+
},
|
|
248
|
+
gImpl: ({ SUBRULE, PRINT_WORD }) => (ast, { factory: F }) => {
|
|
249
|
+
F.printFilter(ast, () => PRINT_WORD('CONSTRUCT'));
|
|
250
|
+
if (!F.isSourceLocationNoMaterialize(ast.where.loc)) {
|
|
251
|
+
// You are NOT in second case construct
|
|
252
|
+
F.printFilter(ast, () => PRINT_WORD('{'));
|
|
253
|
+
SUBRULE(triplesBlock, ast.template, undefined);
|
|
254
|
+
F.printFilter(ast, () => PRINT_WORD('}'));
|
|
255
|
+
}
|
|
256
|
+
SUBRULE(datasetClauseStar, ast.datasets, undefined);
|
|
257
|
+
if (F.isSourceLocationNoMaterialize(ast.where.loc)) {
|
|
258
|
+
SUBRULE(whereClause, F.wrap(F.patternGroup([ast.template], ast.template.loc), ast.template.loc), undefined);
|
|
259
|
+
}
|
|
260
|
+
else {
|
|
261
|
+
SUBRULE(whereClause, F.wrap(ast.where, ast.where.loc), undefined);
|
|
262
|
+
}
|
|
263
|
+
SUBRULE(solutionModifier, ast.solutionModifiers, undefined);
|
|
264
|
+
},
|
|
265
|
+
};
|
|
266
|
+
/**
|
|
267
|
+
* [[11]](https://www.w3.org/TR/sparql11-query/#rDescribeQuery)
|
|
268
|
+
*/
|
|
269
|
+
export const describeQuery = {
|
|
270
|
+
name: 'describeQuery',
|
|
271
|
+
impl: ({ ACTION, AT_LEAST_ONE, SUBRULE1, CONSUME, OPTION, OR }) => (C) => {
|
|
272
|
+
const describe = CONSUME(l.describe);
|
|
273
|
+
const variables = OR([
|
|
274
|
+
{ ALT: () => {
|
|
275
|
+
const variables = [];
|
|
276
|
+
AT_LEAST_ONE(() => {
|
|
277
|
+
variables.push(SUBRULE1(varOrIri, undefined));
|
|
278
|
+
});
|
|
279
|
+
return variables;
|
|
280
|
+
} },
|
|
281
|
+
{ ALT: () => {
|
|
282
|
+
const star = CONSUME(l.symbols.star);
|
|
283
|
+
return [ACTION(() => C.factory.wildcard(C.factory.sourceLocation(star)))];
|
|
284
|
+
} },
|
|
285
|
+
]);
|
|
286
|
+
const from = SUBRULE1(datasetClauseStar, undefined);
|
|
287
|
+
const where = OPTION(() => SUBRULE1(whereClause, undefined));
|
|
288
|
+
const modifiers = SUBRULE1(solutionModifier, undefined);
|
|
289
|
+
return ACTION(() => ({
|
|
290
|
+
subType: 'describe',
|
|
291
|
+
variables,
|
|
292
|
+
datasets: from,
|
|
293
|
+
...(where && { where: where.val }),
|
|
294
|
+
solutionModifiers: modifiers,
|
|
295
|
+
loc: C.factory.sourceLocation(describe, ...variables, from, where, modifiers.group, modifiers.having, modifiers.order, modifiers.limitOffset),
|
|
296
|
+
}));
|
|
297
|
+
},
|
|
298
|
+
gImpl: ({ SUBRULE, PRINT_WORD }) => (ast, { factory: F }) => {
|
|
299
|
+
F.printFilter(ast, () => PRINT_WORD('DESCRIBE'));
|
|
300
|
+
if (F.isWildcard(ast.variables[0])) {
|
|
301
|
+
F.printFilter(ast, () => PRINT_WORD('*'));
|
|
302
|
+
}
|
|
303
|
+
else {
|
|
304
|
+
for (const variable of ast.variables) {
|
|
305
|
+
SUBRULE(varOrTerm, variable, undefined);
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
SUBRULE(datasetClauseStar, ast.datasets, undefined);
|
|
309
|
+
if (ast.where) {
|
|
310
|
+
SUBRULE(whereClause, F.wrap(ast.where, ast.loc), undefined);
|
|
311
|
+
}
|
|
312
|
+
SUBRULE(solutionModifier, ast.solutionModifiers, undefined);
|
|
313
|
+
},
|
|
314
|
+
};
|
|
315
|
+
/**
|
|
316
|
+
* [[12]](https://www.w3.org/TR/sparql11-query/#rAskQuery)
|
|
317
|
+
*/
|
|
318
|
+
export const askQuery = {
|
|
319
|
+
name: 'askQuery',
|
|
320
|
+
impl: ({ ACTION, SUBRULE, CONSUME }) => (C) => {
|
|
321
|
+
const ask = CONSUME(l.ask);
|
|
322
|
+
const from = SUBRULE(datasetClauseStar, undefined);
|
|
323
|
+
const where = SUBRULE(whereClause, undefined);
|
|
324
|
+
const modifiers = SUBRULE(solutionModifier, undefined);
|
|
325
|
+
return ACTION(() => ({
|
|
326
|
+
subType: 'ask',
|
|
327
|
+
datasets: from,
|
|
328
|
+
where: where.val,
|
|
329
|
+
solutionModifiers: modifiers,
|
|
330
|
+
loc: C.factory.sourceLocation(ask, from, where, modifiers.group, modifiers.having, modifiers.order, modifiers.limitOffset),
|
|
331
|
+
}));
|
|
332
|
+
},
|
|
333
|
+
gImpl: ({ SUBRULE, PRINT_WORD }) => (ast, { factory: F }) => {
|
|
334
|
+
F.printFilter(ast, () => PRINT_WORD('ASK'));
|
|
335
|
+
SUBRULE(datasetClauseStar, ast.datasets, undefined);
|
|
336
|
+
SUBRULE(whereClause, F.wrap(ast.where, ast.loc), undefined);
|
|
337
|
+
SUBRULE(solutionModifier, ast.solutionModifiers, undefined);
|
|
338
|
+
},
|
|
339
|
+
};
|
|
340
|
+
/**
|
|
341
|
+
* [[28]](https://www.w3.org/TR/sparql11-query/#rValuesClause)
|
|
342
|
+
*/
|
|
343
|
+
export const valuesClause = {
|
|
344
|
+
name: 'valuesClause',
|
|
345
|
+
impl: ({ OPTION, SUBRULE }) => () => OPTION(() => SUBRULE(inlineData, undefined)),
|
|
346
|
+
};
|
|
347
|
+
/**
|
|
348
|
+
* [[73]](https://www.w3.org/TR/sparql11-query/#ConstructTemplate)
|
|
349
|
+
*/
|
|
350
|
+
export const constructTemplate = {
|
|
351
|
+
name: 'constructTemplate',
|
|
352
|
+
impl: ({ ACTION, SUBRULE1, CONSUME, OPTION }) => (C) => {
|
|
353
|
+
const open = CONSUME(l.symbols.LCurly);
|
|
354
|
+
const triples = OPTION(() => SUBRULE1(constructTriples, undefined));
|
|
355
|
+
const close = CONSUME(l.symbols.RCurly);
|
|
356
|
+
return ACTION(() => C.factory.wrap(triples ?? C.factory.patternBgp([], C.factory.sourceLocation()), C.factory.sourceLocation(open, close)));
|
|
357
|
+
},
|
|
358
|
+
};
|
|
359
|
+
/**
|
|
360
|
+
* [[12]](https://www.w3.org/TR/sparql11-query/#rConstructTriples)
|
|
361
|
+
*/
|
|
362
|
+
export const constructTriples = {
|
|
363
|
+
name: 'constructTriples',
|
|
364
|
+
impl: triplesTemplate.impl,
|
|
365
|
+
};
|
|
366
|
+
//# sourceMappingURL=queryUnit.js.map
|