-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathValue.ts
More file actions
31 lines (30 loc) · 979 Bytes
/
Value.ts
File metadata and controls
31 lines (30 loc) · 979 Bytes
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
import { Expression } from "./Expression"
export class Value extends Expression {
static readonly precedence = 19
readonly precedence = Value.precedence
readonly class = "Value"
readonly value: Value | string | number
constructor(value: Value | string | number, readonly name?: string) {
super()
if (typeof value == "string")
this.value = isNaN(+value.replace(",", ".")) ? value : +value.replace(",", ".")
else
this.value = value
}
toString(): string {
return this.name ? `${this.name?.toString()}.` + this.value.toString() : this.value.toString()
}
evaluate(variable?: any): number {
return variable ? this.get(variable) : +this.value
}
get(variable?: any): number {
return typeof this.value == "string"
? +variable[this.value]
: this.name && typeof this.value == "object"
? this.value.get(variable[this.name])
: +this.value
}
static create(value: Value | string | number, name?: string): Value {
return new Value(value, name)
}
}