refactor: rewrite expression evaluation, fix #130

This commit is contained in:
harttle
2019-08-26 10:15:43 -05:00
committed by Jun Yang
parent 538610e169
commit 76019e9e18
31 changed files with 407 additions and 246 deletions
+23
View File
@@ -0,0 +1,23 @@
import { toValue } from '../util/underscore'
import { Context } from '../context/context'
import { parseLiteral } from '../parser/literal'
export class Value {
private str: string
public constructor (str: string = '') {
this.str = str
}
public evaluate (ctx: Context) {
const literalValue = parseLiteral(this.str)
if (literalValue !== undefined) {
return literalValue
}
return ctx.get(this.str)
}
public value (ctx: Context) {
return toValue(this.evaluate(ctx))
}
}