@traqula/rules-sparql-1-1 0.0.1-alpha.148 → 0.0.1-alpha.9

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 (107) hide show
  1. package/README.md +5 -3
  2. package/lib/RoundTripTypes.d.ts +379 -0
  3. package/lib/RoundTripTypes.js +2 -0
  4. package/lib/RoundTripTypes.js.map +1 -0
  5. package/lib/Sparql11types.d.ts +32 -241
  6. package/lib/Sparql11types.js.map +1 -1
  7. package/lib/SparqlParser.d.ts +14 -5
  8. package/lib/SparqlParser.js +7 -4
  9. package/lib/SparqlParser.js.map +1 -1
  10. package/lib/expressionHelpers.d.ts +8 -17
  11. package/lib/expressionHelpers.js +42 -105
  12. package/lib/expressionHelpers.js.map +1 -1
  13. package/lib/factory.d.ts +446 -0
  14. package/lib/factory.js +105 -0
  15. package/lib/factory.js.map +1 -0
  16. package/lib/factoryMixins/ContextFactory.d.ts +38 -0
  17. package/lib/factoryMixins/ContextFactory.js +30 -0
  18. package/lib/factoryMixins/ContextFactory.js.map +1 -0
  19. package/lib/factoryMixins/ExpressionFactory.d.ts +59 -0
  20. package/lib/factoryMixins/ExpressionFactory.js +83 -0
  21. package/lib/factoryMixins/ExpressionFactory.js.map +1 -0
  22. package/lib/factoryMixins/GraphRefFactory.d.ts +43 -0
  23. package/lib/factoryMixins/GraphRefFactory.js +51 -0
  24. package/lib/factoryMixins/GraphRefFactory.js.map +1 -0
  25. package/lib/factoryMixins/PathFactory.d.ts +51 -0
  26. package/lib/factoryMixins/PathFactory.js +68 -0
  27. package/lib/factoryMixins/PathFactory.js.map +1 -0
  28. package/lib/factoryMixins/Patternfactory.d.ts +55 -0
  29. package/lib/factoryMixins/Patternfactory.js +98 -0
  30. package/lib/factoryMixins/Patternfactory.js.map +1 -0
  31. package/lib/factoryMixins/QueryFactory.d.ts +41 -0
  32. package/lib/factoryMixins/QueryFactory.js +43 -0
  33. package/lib/factoryMixins/QueryFactory.js.map +1 -0
  34. package/lib/factoryMixins/SolutionModifiersFactory.d.ts +43 -0
  35. package/lib/factoryMixins/SolutionModifiersFactory.js +55 -0
  36. package/lib/factoryMixins/SolutionModifiersFactory.js.map +1 -0
  37. package/lib/factoryMixins/TermFactory.d.ts +76 -0
  38. package/lib/factoryMixins/TermFactory.js +84 -0
  39. package/lib/factoryMixins/TermFactory.js.map +1 -0
  40. package/lib/factoryMixins/UpdateOperationFactory.d.ts +68 -0
  41. package/lib/factoryMixins/UpdateOperationFactory.js +126 -0
  42. package/lib/factoryMixins/UpdateOperationFactory.js.map +1 -0
  43. package/lib/factoryMixins/mixins.d.ts +14 -0
  44. package/lib/factoryMixins/mixins.js +20 -0
  45. package/lib/factoryMixins/mixins.js.map +1 -0
  46. package/lib/grammar/builtIn.d.ts +60 -60
  47. package/lib/grammar/builtIn.js +58 -46
  48. package/lib/grammar/builtIn.js.map +1 -1
  49. package/lib/grammar/dataSetClause.d.ts +22 -9
  50. package/lib/grammar/dataSetClause.js +57 -13
  51. package/lib/grammar/dataSetClause.js.map +1 -1
  52. package/lib/grammar/expression.d.ts +20 -24
  53. package/lib/grammar/expression.js +239 -253
  54. package/lib/grammar/expression.js.map +1 -1
  55. package/lib/grammar/general.d.ts +10 -14
  56. package/lib/grammar/general.js +68 -95
  57. package/lib/grammar/general.js.map +1 -1
  58. package/lib/grammar/literals.d.ts +16 -13
  59. package/lib/grammar/literals.js +164 -112
  60. package/lib/grammar/literals.js.map +1 -1
  61. package/lib/grammar/propertyPaths.d.ts +16 -12
  62. package/lib/grammar/propertyPaths.js +103 -114
  63. package/lib/grammar/propertyPaths.js.map +1 -1
  64. package/lib/grammar/queryUnit/queryUnit.d.ts +15 -19
  65. package/lib/grammar/queryUnit/queryUnit.js +209 -247
  66. package/lib/grammar/queryUnit/queryUnit.js.map +1 -1
  67. package/lib/grammar/solutionModifier.d.ts +13 -12
  68. package/lib/grammar/solutionModifier.js +128 -78
  69. package/lib/grammar/solutionModifier.js.map +1 -1
  70. package/lib/grammar/tripleBlock.d.ts +27 -32
  71. package/lib/grammar/tripleBlock.js +197 -123
  72. package/lib/grammar/tripleBlock.js.map +1 -1
  73. package/lib/grammar/updateUnit/updateUnit.d.ts +32 -37
  74. package/lib/grammar/updateUnit/updateUnit.js +315 -264
  75. package/lib/grammar/updateUnit/updateUnit.js.map +1 -1
  76. package/lib/grammar/whereClause.d.ts +22 -21
  77. package/lib/grammar/whereClause.js +249 -191
  78. package/lib/grammar/whereClause.js.map +1 -1
  79. package/lib/grammar-helpers/utils.d.ts +12 -0
  80. package/lib/grammar-helpers/utils.js +16 -0
  81. package/lib/grammar-helpers/utils.js.map +1 -0
  82. package/lib/index.cjs +3281 -2126
  83. package/lib/index.d.ts +5 -1
  84. package/lib/index.js +5 -1
  85. package/lib/index.js.map +1 -1
  86. package/lib/lexer/BuildinCalls.d.ts +62 -184
  87. package/lib/lexer/BuildinCalls.js +1 -2
  88. package/lib/lexer/BuildinCalls.js.map +1 -1
  89. package/lib/lexer/graph.d.ts +5 -13
  90. package/lib/lexer/graph.js +1 -2
  91. package/lib/lexer/graph.js.map +1 -1
  92. package/lib/lexer/lexer.d.ts +50 -143
  93. package/lib/lexer/lexer.js +12 -9
  94. package/lib/lexer/lexer.js.map +1 -1
  95. package/lib/lexer/symbols.d.ts +27 -79
  96. package/lib/lexer/symbols.js +1 -2
  97. package/lib/lexer/symbols.js.map +1 -1
  98. package/lib/lexer/terminals.d.ts +25 -107
  99. package/lib/lexer/terminals.js +36 -49
  100. package/lib/lexer/terminals.js.map +1 -1
  101. package/lib/utils.d.ts +5 -3
  102. package/lib/utils.js +22 -5
  103. package/lib/utils.js.map +1 -1
  104. package/lib/validation/validators.d.ts +14 -0
  105. package/lib/validation/validators.js +235 -0
  106. package/lib/validation/validators.js.map +1 -0
  107. package/package.json +12 -14
@@ -1,245 +1,36 @@
1
- import type * as RdfJs from '@rdfjs/types';
2
- import type * as RDF from '@rdfjs/types';
3
- import type { BlankNode, DataFactory } from 'rdf-data-factory';
4
- import type { CommonIRIs, RuleDef } from '@traqula/core';
5
- export type GraphTerm = IriTerm | BlankTerm | LiteralTerm;
6
- export type Term = GraphTerm | VariableTerm;
7
- export type VerbA = IriTerm<CommonIRIs.TYPE>;
8
- export interface Wildcard {
9
- readonly termType: 'Wildcard';
10
- readonly value: '*';
11
- equals: (other: RdfJs.Term | null | undefined) => boolean;
12
- }
13
- export type Triple = {
14
- subject: Term;
15
- predicate: IriTerm | VariableTerm | PropertyPath;
16
- object: Term;
17
- };
18
- export interface IGraphNode {
19
- node: ITriplesNode['node'] | Term;
20
- triples: Triple[];
21
- }
22
- export interface ITriplesNode {
23
- node: IriTerm | BlankNode;
24
- triples: Triple[];
25
- }
26
- export type Pattern = BgpPattern | BlockPattern | FilterPattern | BindPattern | ValuesPattern | Omit<SelectQuery, 'prefixes'>;
27
- export type Expression = OperationExpression | FunctionCallExpression | AggregateExpression | Expression[] | IriTerm | VariableTerm | LiteralTerm;
28
- export interface FunctionCallExpression extends BaseExpression {
29
- type: 'functionCall';
30
- function: IriTerm;
31
- args: Expression[];
32
- }
1
+ import type { GeneratorRule, ParserRule } from '@traqula/core';
2
+ import type { Factory } from './factory';
3
+ export type SparqlRule<
33
4
  /**
34
- * Basic Graph Pattern
5
+ * Name of grammar rule, should be a strict subtype of string like 'myGrammarRule'.
35
6
  */
36
- export interface BgpPattern {
37
- type: 'bgp';
38
- triples: Triple[];
39
- }
40
- export interface GraphQuads {
41
- type: 'graph';
42
- name: IriTerm | VariableTerm;
43
- triples: Triple[];
44
- }
45
- export type VariableTerm = RdfJs.Variable;
46
- export type IriTerm<IRI extends string = string> = RdfJs.NamedNode<IRI>;
47
- export type LiteralTerm = RdfJs.Literal;
48
- export type BlankTerm = RdfJs.BlankNode;
49
- export type PropertyPath = NegatedPropertySet | {
50
- type: 'path';
51
- pathType: '|' | '/' | '^' | '+' | '*' | '?';
52
- items: (IriTerm | PropertyPath)[];
53
- };
54
- export type SparqlQuery = Query | Update | Pick<Update, 'base' | 'prefixes'>;
55
- export type Query = SelectQuery | ConstructQuery | AskQuery | DescribeQuery;
56
- export interface SelectQuery extends BaseQuery {
57
- queryType: 'SELECT';
58
- variables: Variable[] | [Wildcard];
59
- distinct?: true | undefined;
60
- reduced?: true | undefined;
61
- group?: Grouping[] | undefined;
62
- having?: Expression[] | undefined;
63
- order?: Ordering[] | undefined;
64
- limit?: number | undefined;
65
- offset?: number | undefined;
66
- }
67
- export interface Grouping {
68
- expression: Expression;
69
- variable?: VariableTerm;
70
- }
71
- export interface Ordering {
72
- expression: Expression;
73
- descending?: true | undefined;
74
- }
75
- export interface ConstructQuery extends BaseQuery {
76
- queryType: 'CONSTRUCT';
77
- template?: Triple[] | undefined;
78
- }
79
- export interface AskQuery extends BaseQuery {
80
- queryType: 'ASK';
81
- }
82
- export interface DescribeQuery extends BaseQuery {
83
- queryType: 'DESCRIBE';
84
- variables: (VariableTerm | IriTerm)[] | [Wildcard];
85
- }
86
- export interface Update {
87
- type: 'update';
88
- base?: string | undefined;
89
- prefixes: Record<string, string>;
90
- updates: UpdateOperation[];
91
- }
92
- export type UpdateOperation = InsertDeleteOperation | ManagementOperation;
93
- export type InsertDeleteOperation = {
94
- updateType: 'insert';
95
- graph?: GraphOrDefault;
96
- insert: Quads[];
97
- } | {
98
- updateType: 'delete';
99
- graph?: GraphOrDefault;
100
- delete: Quads[];
101
- } | {
102
- updateType: 'insertdelete';
103
- graph?: IriTerm;
104
- insert: Quads[];
105
- delete: Quads[];
106
- using?: {
107
- default: IriTerm[];
108
- named: IriTerm[];
109
- };
110
- where: Pattern[];
111
- } | {
112
- updateType: 'deletewhere';
113
- graph?: GraphOrDefault;
114
- delete: Quads[];
115
- };
116
- export type Quads = BgpPattern | GraphQuads;
117
- export type ManagementOperation = CopyMoveAddOperation | LoadOperation | CreateOperation | ClearDropOperation;
118
- export interface CopyMoveAddOperation {
119
- type: 'copy' | 'move' | 'add';
120
- silent: boolean;
121
- source: GraphOrDefault;
122
- destination: GraphOrDefault;
123
- }
124
- export interface LoadOperation {
125
- type: 'load';
126
- silent: boolean;
127
- source: IriTerm;
128
- destination?: IriTerm;
129
- }
130
- export interface CreateOperation {
131
- type: 'create';
132
- silent: boolean;
133
- graph: GraphOrDefault;
134
- }
135
- export interface ClearDropOperation {
136
- type: 'clear' | 'drop';
137
- silent: boolean;
138
- graph: GraphReference;
139
- }
140
- export interface GraphOrDefault {
141
- type?: 'graph';
142
- name?: IriTerm | undefined;
143
- default?: true | undefined;
144
- }
145
- export interface GraphReference extends GraphOrDefault {
146
- named?: true | undefined;
147
- all?: true | undefined;
148
- }
7
+ NameType extends string = string,
149
8
  /**
150
- * Examples: '?var', '*',
151
- * SELECT (?a as ?b) ... ==> { expression: '?a', variable: '?b' }
9
+ * Type that will be returned after a correct parse of this rule.
10
+ * This type will be the return type of calling SUBRULE with this grammar rule.
152
11
  */
153
- export type Variable = VariableExpression | VariableTerm;
154
- export interface VariableExpression {
155
- expression: Expression;
156
- variable: VariableTerm;
157
- }
158
- export interface BaseQuery {
159
- type: 'query';
160
- base?: string | undefined;
161
- prefixes: Record<string, string>;
162
- from?: {
163
- default: IriTerm[];
164
- named: IriTerm[];
165
- } | undefined;
166
- where?: Pattern[] | undefined;
167
- values?: ValuePatternRow[] | undefined;
168
- }
169
- export type IriTermOrElt = IriTerm | {
170
- type: 'path';
171
- pathType: '^';
172
- items: [IriTerm];
173
- };
174
- export interface NegatedPropertySet {
175
- type: 'path';
176
- pathType: '!';
177
- items: IriTermOrElt[] | [
178
- {
179
- type: 'path';
180
- pathType: '|';
181
- items: (IriTermOrElt)[];
182
- }
183
- ];
184
- }
185
- export interface GroupPattern {
186
- type: 'group';
187
- patterns: Pattern[];
188
- }
189
- export interface GraphPattern {
190
- type: 'graph';
191
- name: IriTerm | VariableTerm;
192
- patterns: Pattern[];
193
- }
194
- export interface MinusPattern {
195
- type: 'minus';
196
- patterns: Pattern[];
197
- }
198
- export interface ServicePattern {
199
- type: 'service';
200
- name: IriTerm | VariableTerm;
201
- silent: boolean;
202
- patterns: Pattern[];
203
- }
204
- export type BlockPattern = OptionalPattern | UnionPattern | GroupPattern | GraphPattern | MinusPattern | ServicePattern;
205
- export interface OptionalPattern {
206
- type: 'optional';
207
- patterns: Pattern[];
208
- }
209
- export interface UnionPattern {
210
- type: 'union';
211
- patterns: Pattern[];
212
- }
213
- export type ValuePatternRow = Record<string, IriTerm | BlankTerm | LiteralTerm | undefined>;
214
- export interface FilterPattern {
215
- type: 'filter';
216
- expression: Expression;
217
- }
218
- export interface BindPattern {
219
- type: 'bind';
220
- expression: Expression;
221
- variable: VariableTerm;
222
- }
223
- export interface ValuesPattern {
224
- type: 'values';
225
- values: ValuePatternRow[];
226
- }
227
- export interface BaseExpression {
228
- type: string;
229
- distinct?: boolean | undefined;
230
- }
231
- export interface OperationExpression extends BaseExpression {
232
- type: 'operation';
233
- operator: string;
234
- args: (Expression | Pattern)[];
235
- }
236
- export interface AggregateExpression extends BaseExpression {
237
- type: 'aggregate';
238
- expression: Expression | Wildcard;
239
- aggregation: string;
240
- separator?: string | undefined;
241
- }
242
- export type SparqlRuleDef<
12
+ ReturnType = unknown, GenInputType = ReturnType,
13
+ /**
14
+ * Function arguments that can be given to convey the state of the current parse operation.
15
+ */
16
+ ParamType = undefined> = SparqlGrammarRule<NameType, ReturnType, ParamType> & SparqlGeneratorRule<NameType, GenInputType, ParamType>;
17
+ export type SparqlGeneratorRule<
18
+ /**
19
+ * Name of grammar rule, should be a strict subtype of string like 'myGrammarRule'.
20
+ */
21
+ NameType extends string = string,
22
+ /**
23
+ * Type that will be returned after a correct parse of this rule.
24
+ * This type will be the return type of calling SUBRULE with this grammar rule.
25
+ */
26
+ ReturnType = unknown,
27
+ /**
28
+ * Function arguments that can be given to convey the state of the current parse operation.
29
+ */
30
+ ParamType = undefined> = GeneratorRule<{
31
+ factory: Factory;
32
+ }, NameType, ReturnType, ParamType>;
33
+ export type SparqlGrammarRule<
243
34
  /**
244
35
  * Name of grammar rule, should be a strict subtype of string like 'myGrammarRule'.
245
36
  */
@@ -252,12 +43,12 @@ ReturnType = unknown,
252
43
  /**
253
44
  * Function arguments that can be given to convey the state of the current parse operation.
254
45
  */
255
- ParamType = undefined> = RuleDef<SparqlContext, NameType, ReturnType, ParamType>;
46
+ ParamType = undefined> = ParserRule<SparqlContext, NameType, ReturnType, ParamType>;
256
47
  export interface SparqlContext {
257
48
  /**
258
- * Data-factory to be used when constructing rdf primitives.
49
+ * Data-factoryMixins to be used when constructing rdf primitives.
259
50
  */
260
- dataFactory: DataFactory<RDF.BaseQuad>;
51
+ factory: Factory;
261
52
  /**
262
53
  * Current scoped prefixes. Used for resolving prefixed names.
263
54
  */
@@ -1 +1 @@
1
- {"version":3,"file":"Sparql11types.js","sourceRoot":"","sources":["Sparql11types.ts"],"names":[],"mappings":"","sourcesContent":["import type * as RdfJs from '@rdfjs/types';\nimport type * as RDF from '@rdfjs/types';\nimport type {BlankNode, DataFactory} from 'rdf-data-factory';\nimport type {CommonIRIs, RuleDef} from '@traqula/core';\n\nexport type GraphTerm = IriTerm | BlankTerm | LiteralTerm;\nexport type Term = GraphTerm | VariableTerm;\nexport type VerbA = IriTerm<CommonIRIs.TYPE>;\n\nexport interface Wildcard {\n readonly termType: 'Wildcard';\n readonly value: '*';\n equals: (other: RdfJs.Term | null | undefined) => boolean;\n}\n\nexport type Triple = {\n subject: Term;\n predicate: IriTerm | VariableTerm | PropertyPath;\n object: Term;\n};\n\nexport interface IGraphNode {\n node: ITriplesNode['node'] | Term;\n triples: Triple[];\n}\n\nexport interface ITriplesNode {\n node: IriTerm | BlankNode;\n triples: Triple[];\n}\n\nexport type Pattern =\n | BgpPattern\n | BlockPattern\n | FilterPattern\n | BindPattern\n | ValuesPattern\n | Omit<SelectQuery, 'prefixes'>;\n\nexport type Expression =\n | OperationExpression\n | FunctionCallExpression\n | AggregateExpression\n // Used in `IN` operator\n | Expression[]\n | IriTerm\n | VariableTerm\n | LiteralTerm;\n\nexport interface FunctionCallExpression extends BaseExpression {\n type: 'functionCall';\n function: IriTerm;\n args: Expression[];\n}\n\n/**\n * Basic Graph Pattern\n */\nexport interface BgpPattern {\n type: 'bgp';\n triples: Triple[];\n}\n\nexport interface GraphQuads {\n type: 'graph';\n name: IriTerm | VariableTerm;\n triples: Triple[];\n}\n\nexport type VariableTerm = RdfJs.Variable;\nexport type IriTerm<IRI extends string = string> = RdfJs.NamedNode<IRI>;\nexport type LiteralTerm = RdfJs.Literal;\nexport type BlankTerm = RdfJs.BlankNode;\n\nexport type PropertyPath = NegatedPropertySet | {\n type: 'path';\n pathType: '|' | '/' | '^' | '+' | '*' | '?';\n items: (IriTerm | PropertyPath)[];\n};\n\nexport type SparqlQuery = Query | Update | Pick<Update, 'base' | 'prefixes'>;\n\nexport type Query = SelectQuery | ConstructQuery | AskQuery | DescribeQuery;\n\nexport interface SelectQuery extends BaseQuery {\n queryType: 'SELECT';\n variables: Variable[] | [Wildcard];\n distinct?: true | undefined;\n reduced?: true | undefined;\n group?: Grouping[] | undefined;\n having?: Expression[] | undefined;\n order?: Ordering[] | undefined;\n limit?: number | undefined;\n offset?: number | undefined;\n}\n\nexport interface Grouping {\n expression: Expression;\n variable?: VariableTerm;\n}\n\nexport interface Ordering {\n expression: Expression;\n descending?: true | undefined;\n}\n\nexport interface ConstructQuery extends BaseQuery {\n queryType: 'CONSTRUCT';\n template?: Triple[] | undefined;\n}\n\nexport interface AskQuery extends BaseQuery {\n queryType: 'ASK';\n}\n\nexport interface DescribeQuery extends BaseQuery {\n queryType: 'DESCRIBE';\n variables: (VariableTerm | IriTerm)[] | [Wildcard];\n}\n\nexport interface Update {\n type: 'update';\n base?: string | undefined;\n prefixes: Record<string, string>;\n updates: UpdateOperation[];\n}\n\nexport type UpdateOperation = InsertDeleteOperation | ManagementOperation;\n\nexport type InsertDeleteOperation =\n | {\n updateType: 'insert';\n graph?: GraphOrDefault;\n insert: Quads[];\n }\n | {\n updateType: 'delete';\n graph?: GraphOrDefault;\n delete: Quads[];\n }\n | {\n updateType: 'insertdelete';\n graph?: IriTerm;\n insert: Quads[];\n delete: Quads[];\n using?: {\n default: IriTerm[];\n named: IriTerm[];\n };\n where: Pattern[];\n }\n | {\n updateType: 'deletewhere';\n graph?: GraphOrDefault;\n delete: Quads[];\n };\n\nexport type Quads = BgpPattern | GraphQuads;\n\nexport type ManagementOperation =\n | CopyMoveAddOperation\n | LoadOperation\n | CreateOperation\n | ClearDropOperation;\n\nexport interface CopyMoveAddOperation {\n type: 'copy' | 'move' | 'add';\n silent: boolean;\n source: GraphOrDefault;\n destination: GraphOrDefault;\n}\n\nexport interface LoadOperation {\n type: 'load';\n silent: boolean;\n source: IriTerm;\n destination?: IriTerm;\n}\n\nexport interface CreateOperation {\n type: 'create';\n silent: boolean;\n graph: GraphOrDefault;\n}\n\nexport interface ClearDropOperation {\n type: 'clear' | 'drop';\n silent: boolean;\n graph: GraphReference;\n}\n\nexport interface GraphOrDefault {\n type?: 'graph';\n name?: IriTerm | undefined;\n default?: true | undefined;\n}\n\nexport interface GraphReference extends GraphOrDefault {\n named?: true | undefined;\n all?: true | undefined;\n}\n\n/**\n * Examples: '?var', '*',\n * SELECT (?a as ?b) ... ==> { expression: '?a', variable: '?b' }\n */\nexport type Variable = VariableExpression | VariableTerm;\n\nexport interface VariableExpression {\n expression: Expression;\n variable: VariableTerm;\n}\n\nexport interface BaseQuery {\n type: 'query';\n base?: string | undefined;\n prefixes: Record<string, string>;\n from?:\n | {\n default: IriTerm[];\n named: IriTerm[];\n }\n | undefined;\n where?: Pattern[] | undefined;\n values?: ValuePatternRow[] | undefined;\n}\n\nexport type IriTermOrElt = IriTerm | {\n type: 'path';\n pathType: '^';\n items: [IriTerm];\n};\n\nexport interface NegatedPropertySet {\n type: 'path';\n pathType: '!';\n items: IriTermOrElt[] | [{\n type: 'path';\n pathType: '|';\n items: (IriTermOrElt)[];\n }];\n}\n\nexport interface GroupPattern {\n type: 'group';\n patterns: Pattern[];\n}\n\nexport interface GraphPattern {\n type: 'graph';\n name: IriTerm | VariableTerm;\n patterns: Pattern[];\n}\n\nexport interface MinusPattern {\n type: 'minus';\n patterns: Pattern[];\n}\n\nexport interface ServicePattern {\n type: 'service';\n name: IriTerm | VariableTerm;\n silent: boolean;\n patterns: Pattern[];\n}\n\nexport type BlockPattern =\n | OptionalPattern\n | UnionPattern\n | GroupPattern\n | GraphPattern\n | MinusPattern\n | ServicePattern;\n\nexport interface OptionalPattern {\n type: 'optional';\n patterns: Pattern[];\n}\n\nexport interface UnionPattern {\n type: 'union';\n patterns: Pattern[];\n}\n\nexport type ValuePatternRow = Record<string, IriTerm | BlankTerm | LiteralTerm | undefined>;\n\nexport interface FilterPattern {\n type: 'filter';\n expression: Expression;\n}\n\nexport interface BindPattern {\n type: 'bind';\n expression: Expression;\n variable: VariableTerm;\n}\n\nexport interface ValuesPattern {\n type: 'values';\n values: ValuePatternRow[];\n}\n\nexport interface BaseExpression {\n type: string;\n distinct?: boolean | undefined;\n}\n\nexport interface OperationExpression extends BaseExpression {\n type: 'operation';\n operator: string;\n args: (Expression | Pattern)[];\n}\n\nexport interface AggregateExpression extends BaseExpression {\n type: 'aggregate';\n expression: Expression | Wildcard;\n aggregation: string;\n separator?: string | undefined;\n}\n\nexport type SparqlRuleDef<\n /**\n * Name of grammar rule, should be a strict subtype of string like 'myGrammarRule'.\n */\n NameType extends string = string,\n /**\n * Type that will be returned after a correct parse of this rule.\n * This type will be the return type of calling SUBRULE with this grammar rule.\n */\n ReturnType = unknown,\n /**\n * Function arguments that can be given to convey the state of the current parse operation.\n */\n ParamType = undefined,\n> = RuleDef<SparqlContext, NameType, ReturnType, ParamType>;\n\nexport interface SparqlContext {\n /**\n * Data-factory to be used when constructing rdf primitives.\n */\n dataFactory: DataFactory<RDF.BaseQuad>;\n /**\n * Current scoped prefixes. Used for resolving prefixed names.\n */\n prefixes: Record<string, string>;\n /**\n * The base IRI for the query. Used for resolving relative IRIs.\n */\n baseIRI: string | undefined;\n /**\n * Can be used to disable the validation that used variables in a select clause are in scope.\n */\n skipValidation: boolean;\n /**\n * Set of queryModes. Primarily used for note 8, 14.\n */\n parseMode: Set<'canParseVars' | 'canCreateBlankNodes' | 'inAggregate' | 'canParseAggregate' | string>;\n}"]}
1
+ {"version":3,"file":"Sparql11types.js","sourceRoot":"","sources":["Sparql11types.ts"],"names":[],"mappings":"","sourcesContent":["import type { GeneratorRule, ParserRule } from '@traqula/core';\nimport type { Factory } from './factory';\n\nexport type SparqlRule<\n /**\n * Name of grammar rule, should be a strict subtype of string like 'myGrammarRule'.\n */\n NameType extends string = string,\n /**\n * Type that will be returned after a correct parse of this rule.\n * This type will be the return type of calling SUBRULE with this grammar rule.\n */\n ReturnType = unknown,\n GenInputType = ReturnType,\n /**\n * Function arguments that can be given to convey the state of the current parse operation.\n */\n ParamType = undefined,\n> = SparqlGrammarRule<NameType, ReturnType, ParamType>\n & SparqlGeneratorRule<NameType, GenInputType, ParamType>;\n\nexport type SparqlGeneratorRule<\n /**\n * Name of grammar rule, should be a strict subtype of string like 'myGrammarRule'.\n */\n NameType extends string = string,\n /**\n * Type that will be returned after a correct parse of this rule.\n * This type will be the return type of calling SUBRULE with this grammar rule.\n */\n ReturnType = unknown,\n /**\n * Function arguments that can be given to convey the state of the current parse operation.\n */\n ParamType = undefined,\n> = GeneratorRule<{ factory: Factory }, NameType, ReturnType, ParamType>;\n\nexport type SparqlGrammarRule<\n /**\n * Name of grammar rule, should be a strict subtype of string like 'myGrammarRule'.\n */\n NameType extends string = string,\n /**\n * Type that will be returned after a correct parse of this rule.\n * This type will be the return type of calling SUBRULE with this grammar rule.\n */\n ReturnType = unknown,\n /**\n * Function arguments that can be given to convey the state of the current parse operation.\n */\n ParamType = undefined,\n> = ParserRule<SparqlContext, NameType, ReturnType, ParamType>;\n\nexport interface SparqlContext {\n /**\n * Data-factoryMixins to be used when constructing rdf primitives.\n */\n factory: Factory;\n /**\n * Current scoped prefixes. Used for resolving prefixed names.\n */\n prefixes: Record<string, string>;\n /**\n * The base IRI for the query. Used for resolving relative IRIs.\n */\n baseIRI: string | undefined;\n /**\n * Can be used to disable the validation that used variables in a select clause are in scope.\n */\n skipValidation: boolean;\n /**\n * Set of queryModes. Primarily used for note 8, 14.\n */\n parseMode: Set<'canParseVars' | 'canCreateBlankNodes' | 'inAggregate' | 'canParseAggregate' | string>;\n}\n"]}
@@ -1,14 +1,23 @@
1
- import { IriTerm, PropertyPath, SparqlContext } from "./Sparql11types";
1
+ import type { Path, TermIri } from './RoundTripTypes';
2
+ import type { SparqlContext } from './Sparql11types';
2
3
  interface Parser<ParseRet> {
3
4
  queryOrUpdate: (input: string, context: SparqlContext, arg: undefined) => ParseRet;
4
- path: (input: string, context: SparqlContext, arg: undefined) => IriTerm | PropertyPath;
5
+ path: (input: string, context: SparqlContext, arg: undefined) => TermIri | Path;
5
6
  }
7
+ export declare function completeParseContext(context: Partial<SparqlContext & {
8
+ origSource: string;
9
+ offset?: number;
10
+ }>): SparqlContext & {
11
+ origSource: string;
12
+ offset?: number;
13
+ };
6
14
  export declare class SparqlParser<ParseRet> {
7
- private parser;
15
+ private readonly parser;
8
16
  constructor(parser: Parser<ParseRet>);
17
+ private readonly F;
9
18
  parse(query: string, context?: Partial<SparqlContext>): ParseRet;
10
- parsePath(query: string, context?: Partial<SparqlContext>): (PropertyPath & {
19
+ parsePath(query: string, context?: Partial<SparqlContext>): (Path & {
11
20
  prefixes: object;
12
- }) | IriTerm;
21
+ }) | TermIri;
13
22
  }
14
23
  export {};
@@ -1,9 +1,11 @@
1
- import { DataFactory } from "rdf-data-factory";
2
- function completeParseContext(context) {
1
+ import { Factory } from './factory';
2
+ export function completeParseContext(context) {
3
3
  return {
4
- dataFactory: context.dataFactory ?? new DataFactory({ blankNodePrefix: 'g_' }),
4
+ factory: context.factory ?? new Factory(),
5
5
  baseIRI: context.baseIRI,
6
6
  prefixes: { ...context.prefixes },
7
+ origSource: context.origSource ?? '',
8
+ offset: context.offset,
7
9
  parseMode: context.parseMode ? new Set(context.parseMode) : new Set(['canParseVars', 'canCreateBlankNodes']),
8
10
  skipValidation: context.skipValidation ?? false,
9
11
  };
@@ -11,13 +13,14 @@ function completeParseContext(context) {
11
13
  export class SparqlParser {
12
14
  constructor(parser) {
13
15
  this.parser = parser;
16
+ this.F = new Factory();
14
17
  }
15
18
  parse(query, context = {}) {
16
19
  return this.parser.queryOrUpdate(query, completeParseContext(context), undefined);
17
20
  }
18
21
  parsePath(query, context = {}) {
19
22
  const result = this.parser.path(query, completeParseContext(context), undefined);
20
- if ('type' in result) {
23
+ if (this.F.isPathPure(result)) {
21
24
  return {
22
25
  ...result,
23
26
  prefixes: {},
@@ -1 +1 @@
1
- {"version":3,"file":"SparqlParser.js","sourceRoot":"","sources":["SparqlParser.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,WAAW,EAAC,MAAM,kBAAkB,CAAC;AAQ7C,SAAS,oBAAoB,CAAC,OAA+B;IAC3D,OAAO;QACL,WAAW,EAAE,OAAO,CAAC,WAAW,IAAI,IAAI,WAAW,CAAC,EAAE,eAAe,EAAE,IAAI,EAAE,CAAC;QAC9E,OAAO,EAAE,OAAO,CAAC,OAAO;QACxB,QAAQ,EAAE,EAAE,GAAG,OAAO,CAAC,QAAQ,EAAE;QACjC,SAAS,EAAE,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,GAAG,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,IAAI,GAAG,CAAC,CAAE,cAAc,EAAE,qBAAqB,CAAE,CAAC;QAC9G,cAAc,EAAE,OAAO,CAAC,cAAc,IAAI,KAAK;KAChD,CAAC;AACJ,CAAC;AAED,MAAM,OAAO,YAAY;IACvB,YAA2B,MAAwB;QAAxB,WAAM,GAAN,MAAM,CAAkB;IAAI,CAAC;IAEjD,KAAK,CAAC,KAAa,EAAE,UAAkC,EAAE;QAC9D,OAAO,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,KAAK,EAAE,oBAAoB,CAAC,OAAO,CAAC,EAAE,SAAS,CAAC,CAAC;IACpF,CAAC;IAEM,SAAS,CAAC,KAAa,EAAE,UAAkC,EAAE;QAClE,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,EAAE,oBAAoB,CAAC,OAAO,CAAC,EAAE,SAAS,CAAC,CAAC;QACjF,IAAI,MAAM,IAAI,MAAM,EAAE,CAAC;YACrB,OAAO;gBACL,GAAG,MAAM;gBACT,QAAQ,EAAE,EAAE;aACb,CAAC;QACJ,CAAC;QACD,OAAO,MAAM,CAAC;IAChB,CAAC;CACF","sourcesContent":["import {DataFactory} from \"rdf-data-factory\";\nimport {IriTerm, PropertyPath, SparqlContext} from \"./Sparql11types\";\n\ninterface Parser<ParseRet> {\n queryOrUpdate: (input: string, context: SparqlContext, arg: undefined) => ParseRet;\n path: (input: string, context: SparqlContext, arg: undefined) => IriTerm | PropertyPath;\n}\n\nfunction completeParseContext(context: Partial<SparqlContext>): SparqlContext {\n return {\n dataFactory: context.dataFactory ?? new DataFactory({ blankNodePrefix: 'g_' }),\n baseIRI: context.baseIRI,\n prefixes: { ...context.prefixes },\n parseMode: context.parseMode ? new Set(context.parseMode) : new Set([ 'canParseVars', 'canCreateBlankNodes' ]),\n skipValidation: context.skipValidation ?? false,\n };\n}\n\nexport class SparqlParser<ParseRet> {\n public constructor(private parser: Parser<ParseRet>) { }\n\n public parse(query: string, context: Partial<SparqlContext> = {}): ParseRet {\n return this.parser.queryOrUpdate(query, completeParseContext(context), undefined);\n }\n\n public parsePath(query: string, context: Partial<SparqlContext> = {}): (PropertyPath & { prefixes: object }) | IriTerm {\n const result = this.parser.path(query, completeParseContext(context), undefined);\n if ('type' in result) {\n return {\n ...result,\n prefixes: {},\n };\n }\n return result;\n }\n}\n"]}
1
+ {"version":3,"file":"SparqlParser.js","sourceRoot":"","sources":["SparqlParser.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AASpC,MAAM,UAAU,oBAAoB,CAClC,OAAyE;IAEzE,OAAO;QACL,OAAO,EAAE,OAAO,CAAC,OAAO,IAAI,IAAI,OAAO,EAAE;QACzC,OAAO,EAAE,OAAO,CAAC,OAAO;QACxB,QAAQ,EAAE,EAAE,GAAG,OAAO,CAAC,QAAQ,EAAE;QACjC,UAAU,EAAE,OAAO,CAAC,UAAU,IAAI,EAAE;QACpC,MAAM,EAAE,OAAO,CAAC,MAAM;QACtB,SAAS,EAAE,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,GAAG,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,IAAI,GAAG,CAAC,CAAE,cAAc,EAAE,qBAAqB,CAAE,CAAC;QAC9G,cAAc,EAAE,OAAO,CAAC,cAAc,IAAI,KAAK;KAChD,CAAC;AACJ,CAAC;AAED,MAAM,OAAO,YAAY;IACvB,YAAoC,MAAwB;QAAxB,WAAM,GAAN,MAAM,CAAkB;QAC3C,MAAC,GAAG,IAAI,OAAO,EAAE,CAAC;IAD4B,CAAC;IAGzD,KAAK,CAAC,KAAa,EAAE,UAAkC,EAAE;QAC9D,OAAO,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,KAAK,EAAE,oBAAoB,CAAC,OAAO,CAAC,EAAE,SAAS,CAAC,CAAC;IACpF,CAAC;IAEM,SAAS,CAAC,KAAa,EAAE,UAAkC,EAAE;QAElE,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,EAAE,oBAAoB,CAAC,OAAO,CAAC,EAAE,SAAS,CAAC,CAAC;QACjF,IAAI,IAAI,CAAC,CAAC,CAAC,UAAU,CAAC,MAAM,CAAC,EAAE,CAAC;YAC9B,OAAO;gBACL,GAAG,MAAM;gBACT,QAAQ,EAAE,EAAE;aACb,CAAC;QACJ,CAAC;QACD,OAAO,MAAM,CAAC;IAChB,CAAC;CACF","sourcesContent":["import { Factory } from './factory';\nimport type { Path, TermIri } from './RoundTripTypes';\nimport type { SparqlContext } from './Sparql11types';\n\ninterface Parser<ParseRet> {\n queryOrUpdate: (input: string, context: SparqlContext, arg: undefined) => ParseRet;\n path: (input: string, context: SparqlContext, arg: undefined) => TermIri | Path;\n}\n\nexport function completeParseContext(\n context: Partial<SparqlContext & { origSource: string; offset?: number }>,\n): SparqlContext & { origSource: string; offset?: number } {\n return {\n factory: context.factory ?? new Factory(),\n baseIRI: context.baseIRI,\n prefixes: { ...context.prefixes },\n origSource: context.origSource ?? '',\n offset: context.offset,\n parseMode: context.parseMode ? new Set(context.parseMode) : new Set([ 'canParseVars', 'canCreateBlankNodes' ]),\n skipValidation: context.skipValidation ?? false,\n };\n}\n\nexport class SparqlParser<ParseRet> {\n public constructor(private readonly parser: Parser<ParseRet>) {}\n private readonly F = new Factory();\n\n public parse(query: string, context: Partial<SparqlContext> = {}): ParseRet {\n return this.parser.queryOrUpdate(query, completeParseContext(context), undefined);\n }\n\n public parsePath(query: string, context: Partial<SparqlContext> = {}):\n (Path & { prefixes: object }) | TermIri {\n const result = this.parser.path(query, completeParseContext(context), undefined);\n if (this.F.isPathPure(result)) {\n return {\n ...result,\n prefixes: {},\n };\n }\n return result;\n }\n}\n"]}
@@ -1,12 +1,10 @@
1
1
  import type { TokenType } from 'chevrotain';
2
- import { Wildcard } from '@traqula/core';
3
- import type { Expression, Pattern, SparqlRuleDef, VariableTerm } from './Sparql11types';
4
- export interface IExpressionFunctionX<U extends (Expression | Pattern)[]> {
5
- type: 'operation';
6
- operator: string;
2
+ import type { Expression, ExpressionAggregateDefault, ExpressionOperation, ExpressionPatternOperation, TermVariable } from './RoundTripTypes';
3
+ import type { SparqlGrammarRule } from './Sparql11types';
4
+ export type ExpressionFunctionX<U extends Expression[]> = ExpressionOperation & {
7
5
  args: U;
8
- }
9
- export type RuleDefExpressionFunctionX<T extends string, U extends (Expression | Pattern)[]> = SparqlRuleDef<T, IExpressionFunctionX<U>>;
6
+ };
7
+ export type RuleDefExpressionFunctionX<T extends string, U extends Expression[]> = SparqlGrammarRule<T, ExpressionFunctionX<U>>;
10
8
  export declare function funcExpr1<T extends string>(func: TokenType & {
11
9
  name: T;
12
10
  }): RuleDefExpressionFunctionX<Uncapitalize<T>, [Expression]>;
@@ -18,7 +16,7 @@ export declare function funcExpr3<T extends string>(func: TokenType & {
18
16
  }): RuleDefExpressionFunctionX<Uncapitalize<T>, [Expression, Expression, Expression]>;
19
17
  export declare function funcVar1<T extends string>(func: TokenType & {
20
18
  name: T;
21
- }): RuleDefExpressionFunctionX<Uncapitalize<T>, [VariableTerm]>;
19
+ }): RuleDefExpressionFunctionX<Uncapitalize<T>, [TermVariable]>;
22
20
  export declare function funcExprOrNil1<T extends string>(func: TokenType & {
23
21
  name: T;
24
22
  }): RuleDefExpressionFunctionX<Uncapitalize<T>, [] | [Expression]>;
@@ -40,15 +38,8 @@ export declare function funcExpr3or4<T extends string>(func: TokenType & {
40
38
  ] | [Expression, Expression, Expression, Expression]>;
41
39
  export declare function funcGroupGraphPattern<T extends string>(func: TokenType & {
42
40
  name: T;
43
- }): RuleDefExpressionFunctionX<Uncapitalize<T>, Pattern[]>;
44
- export interface IExpressionAggregator {
45
- type: 'aggregate';
46
- distinct: boolean;
47
- expression: Expression | Wildcard;
48
- aggregation: string;
49
- separator?: string;
50
- }
51
- export type RuleDefExpressionAggregatorX<T extends string> = SparqlRuleDef<T, IExpressionAggregator>;
41
+ }): SparqlGrammarRule<Uncapitalize<T>, ExpressionPatternOperation>;
42
+ export type RuleDefExpressionAggregatorX<T extends string> = SparqlGrammarRule<T, ExpressionAggregateDefault>;
52
43
  export declare function baseAggregateFunc<T extends string>(func: TokenType & {
53
44
  name: T;
54
45
  }): RuleDefExpressionAggregatorX<Uncapitalize<T>>;