MCPcopy Create free account
hub / github.com/apitable/apitable / parse

Function parse

packages/core/src/formula_parser/evaluate.ts:134–165  ·  view source on GitHub ↗
(
  expression: string,
  context: { field: IField; fieldMap: IFieldMap; state: IReduxState },
  updateCache?: boolean,
)

Source from the content-addressed store, hash-verified

132}
133
134export 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

Callers 7

getParseResultMethod · 0.90
basicValueTypeMethod · 0.90
computeRefMapMethod · 0.90
validateExpressionMethod · 0.90
getExpValueTypeFunction · 0.90
getExpValueTypeFunction · 0.90
evaluateFunction · 0.70

Calls 5

tFunction · 0.90
hasMethod · 0.65
getMethod · 0.65
setMethod · 0.65
parseMethod · 0.65

Tested by

no test coverage detected