-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathWithin.ts
41 lines (38 loc) · 1.06 KB
/
Within.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
import { Token } from "./lexer"
import { Rule } from "./Rule"
import { Type } from "./Type"
import { Completor } from "./Type/Completor"
export class Within extends Rule {
readonly precedence = 85
readonly class = "Within"
constructor(readonly value: (string | number)[]) {
super()
}
is(value: any): boolean {
return this.value.includes(value)
}
toString(): string {
return `within(${this.value.join(", ")})`
}
}
export function within(criteria: string[]): Within
export function within(criteria: string[], value?: any): boolean
export function within(criteria: string[], value?: any): Within | boolean {
const result = new Within(criteria)
return value ? result.is(value) : result
}
function complete(
tokens: Token[],
type?: Type.String | Type.Number,
baseObject?: Type.Object
): Type.Completion[] | Type.Completion {
return baseObject && type?.class
? Completor.functions(tokens, (tokens?: Token[]) => [], {
value: "within()",
cursor: 7,
suggestion: { value: "within()" },
})
: []
}
Type.String.add(complete)
Type.Number.add(complete)