feat: with & for in render tag, closes #195

This commit is contained in:
harttle
2020-03-04 07:08:54 +08:00
parent aa27a6cd7b
commit 6ea6881f08
67 changed files with 1108 additions and 724 deletions
+3 -2
View File
@@ -4,14 +4,15 @@ import { Value } from './value'
import { Context } from '../context/context'
import { toValue } from '../util/underscore'
import { isOperator, precedence, operatorImpls } from './operator'
import { tokenize } from '../parser/expression-tokenizer'
import { Tokenizer } from '../parser/tokenizer'
export class Expression {
private operands: any[] = []
private postfix: string[]
public constructor (str = '') {
this.postfix = [...toPostfix(tokenize(str))]
const tokenizer = new Tokenizer(str)
this.postfix = [...toPostfix(tokenizer.readExpression())]
}
public * evaluate (ctx: Context) {
assert(ctx, 'unable to evaluate: context not defined')
+1 -3
View File
@@ -52,8 +52,6 @@ export const operatorImpls: {[key: string]: (lhs: any, rhs: any) => boolean} = {
'or': (l: any, r: any) => isTruthy(l) || isTruthy(r)
}
const list = Object.keys(precedence)
export function isOperator (token: string) {
return list.includes(token)
return precedence.hasOwnProperty(token)
}
+2 -2
View File
@@ -3,8 +3,8 @@ import { Context } from '../context/context'
import { range } from '../util/underscore'
import { Value } from './value'
export function isRange (token: string) {
return token[0] === '(' && token[token.length - 1] === ')'
export function isRange (str: string) {
return rangeLine.test(str)
}
export function * rangeValue (token: string, ctx: Context) {