This repository has been archived by the owner on Sep 19, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathExpressions.ts
104 lines (89 loc) · 2.95 KB
/
Expressions.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
import type * as RDF from '@rdfjs/types';
import type { Algebra } from 'sparqlalgebrajs';
import type { EvalContextAsync, EvalContextSync } from '../functions';
export enum ExpressionType {
Aggregate = 'aggregate',
Existence = 'existence',
Named = 'named',
Operator = 'operator',
SpecialOperator = 'specialOperator',
Term = 'term',
Variable = 'variable',
AsyncExtension = 'asyncExtension',
SyncExtension = 'syncExtension',
}
export type Expression =
AggregateExpression |
ExistenceExpression |
NamedExpression |
OperatorExpression |
SpecialOperatorExpression |
TermExpression |
VariableExpression |
AsyncExtensionExpression |
SyncExtensionExpression;
export interface IExpressionProps {
expressionType: ExpressionType;
}
export type AggregateExpression = IExpressionProps & {
expressionType: ExpressionType.Aggregate;
name: string;
expression: Algebra.AggregateExpression;
};
export type ExistenceExpression = IExpressionProps & {
expressionType: ExpressionType.Existence;
expression: Algebra.ExistenceExpression;
};
export type NamedExpression = IExpressionProps & {
expressionType: ExpressionType.Named;
name: RDF.NamedNode;
apply: SimpleApplication;
args: Expression[];
};
export type AsyncExtensionExpression = IExpressionProps & {
expressionType: ExpressionType.AsyncExtension;
name: RDF.NamedNode;
apply: AsyncExtensionApplication;
args: Expression[];
};
export type SyncExtensionExpression = IExpressionProps & {
expressionType: ExpressionType.SyncExtension;
name: RDF.NamedNode;
apply: SimpleApplication;
args: Expression[];
};
export type OperatorExpression = IExpressionProps & {
expressionType: ExpressionType.Operator;
args: Expression[];
apply: SimpleApplication;
};
export type SpecialOperatorExpression = IExpressionProps & {
expressionType: ExpressionType.SpecialOperator;
args: Expression[];
applyAsync: SpecialApplicationAsync;
applySync: SpecialApplicationSync;
};
// TODO: Create alias Term = TermExpression
export function asTermType(type: string): TermType | undefined {
if (type === 'namedNode' || type === 'literal' || type === 'blankNode' || type === 'quad') {
return type;
}
return undefined;
}
export type TermType = 'namedNode' | 'literal' | 'blankNode' | 'quad';
export type TermExpression = IExpressionProps & {
expressionType: ExpressionType.Term;
termType: TermType;
str: () => string;
coerceEBV: () => boolean;
toRDF: () => RDF.Term;
};
export type VariableExpression = IExpressionProps & {
expressionType: ExpressionType.Variable;
name: string;
};
// Export type Application = SimpleApplication | SpecialApplication;
export type SimpleApplication = (args: TermExpression[]) => TermExpression;
export type AsyncExtensionApplication = (args: TermExpression[]) => Promise<TermExpression>;
export type SpecialApplicationAsync = (context: EvalContextAsync) => Promise<TermExpression>;
export type SpecialApplicationSync = (context: EvalContextSync) => TermExpression;