(
expression: string,
context: { field: IField; fieldMap: IFieldMap; state: IReduxState },
updateCache?: boolean,
)
| 132 | } |
| 133 | |
| 134 | export function parse( |
| 135 | expression: string, |
| 136 | context: { field: IField; fieldMap: IFieldMap; state: IReduxState }, |
| 137 | updateCache?: boolean, |
| 138 | ): IFormulaExpr | IFormulaError { |
| 139 | if (!expression || !expression.trim()) { |
| 140 | return { |
| 141 | error: new Error(t(Strings.function_content_empty)), |
| 142 | }; |
| 143 | } |
| 144 | |
| 145 | const field = context.field; |
| 146 | const datasheetId = (field && field.property && (field.property as any).datasheetId) || ''; |
| 147 | |
| 148 | if (!updateCache && ExpCache.has(datasheetId, field.id, expression)) { |
| 149 | return ExpCache.get(datasheetId, field.id, expression)!; |
| 150 | } |
| 151 | |
| 152 | const lexer = new FormulaExprLexer(expression); |
| 153 | if (lexer.errors.length) { |
| 154 | ExpCache.set(datasheetId, field.id, expression, { error: lexer.errors[0]! }); |
| 155 | } else { |
| 156 | try { |
| 157 | const ast = new FormulaExprParser(lexer, context).parse(); |
| 158 | ExpCache.set(datasheetId, field.id, expression, { lexer, ast }); |
| 159 | } catch (e) { |
| 160 | ExpCache.set(datasheetId, field.id, expression, { error: e as Error }); |
| 161 | } |
| 162 | } |
| 163 | |
| 164 | return ExpCache.get(datasheetId, field.id, expression)!; |
| 165 | } |
| 166 | |
| 167 | /** |
| 168 | * Pass in the expression and context, enter row evaluation |
no test coverage detected