-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathLesserThan.ts
More file actions
47 lines (44 loc) · 1.47 KB
/
LesserThan.ts
File metadata and controls
47 lines (44 loc) · 1.47 KB
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
import { Expression } from "./Expression"
import { Token } from "./lexer"
import { Rule } from "./Rule"
import { Type } from "./Type"
import { Value } from "./Value"
export class LesserThan extends Rule {
readonly precedence = 85
readonly class = "LesserThan"
readonly symbol = "<"
constructor(readonly value: bigint | boolean | number | string | Expression) {
super()
}
is(value: any): boolean
is(value: any, object?: any): boolean {
return (
(isNaN(+value) ? value : +value) <
((this.value instanceof Value && typeof this.value.value == "string" && this.value.value.includes("-")) ||
typeof this.value != "object"
? this.value
: this.value.evaluate(object))
)
}
toString(): string {
return this.value.toString()
}
}
export function lesserThan(criteria: bigint | boolean | number | string): LesserThan
export function lesserThan(criteria: bigint | boolean | number | string, value?: any): boolean
export function lesserThan(criteria: bigint | boolean | number | string, value?: any): LesserThan | boolean {
const result = new LesserThan(criteria)
return value ? result.is(value) : result
}
function complete(tokens: Token[], type: Type.String | Type.Number, baseObject: Type.Object): Type.Completion[] {
return Type.Completor.operators(
tokens,
(tokens?: Token[]) => (tokens && baseObject ? baseObject?.complete(tokens, undefined, type) : []),
{
value: "<",
suggestion: { value: "<" },
}
)
}
Type.Number.add(complete)
Type.String.add(complete)