ifc-expressions 2.0.1-beta.1 → 2.0.1-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/IfcExpression.d.ts
CHANGED
|
@@ -24,7 +24,8 @@ import type { BoxedValueTypes } from "./value/BoxedValueTypes.js";
|
|
|
24
24
|
import { ExprEvalError, ExprEvalResult, isExprEvalError, isExprEvalSuccess } from "./expression/ExprEvalResult.js";
|
|
25
25
|
import { ExprKind } from "./expression/ExprKind.js";
|
|
26
26
|
import { TypeManager } from "./compiler/TypeManager.js";
|
|
27
|
-
|
|
27
|
+
import { ExprToTextInputLinker } from "./compiler/ExprToTextInputLinker";
|
|
28
|
+
export { IfcElementAccessor, IfcExpressionContext, Value, StringValue, BooleanValue, LogicalValue, NumericValue, ExpressionValue, ReferenceValue, IfcPropertySetAccessor, IfcPropertyAccessor, IfcRootObjectAccessor, IfcTypeObjectAccessor, NamedObjectAccessor, ObjectAccessor, Expr, ExprCompiler, ExprKind, IfcExpressionEvaluationException, IfcExpressionErrorListener, IfcExpressionVisitor, isPresent, isNullish, ExprEvalResult, ExprEvalError, isExprEvalError, isExprEvalSuccess, ExprToTextInputLinker, };
|
|
28
29
|
export type { BoxedValueTypes };
|
|
29
30
|
export declare class IfcExpressionParseResult {
|
|
30
31
|
private readonly _input;
|
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.IfcExpression = exports.IfcExpressionParseResult = exports.isExprEvalSuccess = exports.isExprEvalError = exports.isNullish = exports.isPresent = exports.IfcExpressionVisitor = exports.IfcExpressionErrorListener = exports.IfcExpressionEvaluationException = exports.ExprKind = exports.ExprCompiler = exports.NamedObjectAccessor = exports.IfcTypeObjectAccessor = exports.IfcRootObjectAccessor = exports.IfcPropertyAccessor = exports.IfcPropertySetAccessor = exports.ReferenceValue = exports.NumericValue = exports.LogicalValue = exports.BooleanValue = exports.StringValue = exports.IfcElementAccessor = void 0;
|
|
6
|
+
exports.IfcExpression = exports.IfcExpressionParseResult = exports.ExprToTextInputLinker = exports.isExprEvalSuccess = exports.isExprEvalError = exports.isNullish = exports.isPresent = exports.IfcExpressionVisitor = exports.IfcExpressionErrorListener = exports.IfcExpressionEvaluationException = exports.ExprKind = exports.ExprCompiler = exports.NamedObjectAccessor = exports.IfcTypeObjectAccessor = exports.IfcRootObjectAccessor = exports.IfcPropertyAccessor = exports.IfcPropertySetAccessor = exports.ReferenceValue = exports.NumericValue = exports.LogicalValue = exports.BooleanValue = exports.StringValue = exports.IfcElementAccessor = void 0;
|
|
7
7
|
const antlr4_1 = require("antlr4");
|
|
8
8
|
const ExprCompiler_js_1 = require("./compiler/ExprCompiler.js");
|
|
9
9
|
Object.defineProperty(exports, "ExprCompiler", { enumerable: true, get: function () { return ExprCompiler_js_1.ExprCompiler; } });
|
|
@@ -50,6 +50,7 @@ const ValidationException_js_1 = require("./error/ValidationException.js");
|
|
|
50
50
|
const ExceptionToExprEvalErrorMapper_js_1 = require("./error/ExceptionToExprEvalErrorMapper.js");
|
|
51
51
|
const NopContext_js_1 = require("./context/NopContext.js");
|
|
52
52
|
const ExprToTextInputLinker_1 = require("./compiler/ExprToTextInputLinker");
|
|
53
|
+
Object.defineProperty(exports, "ExprToTextInputLinker", { enumerable: true, get: function () { return ExprToTextInputLinker_1.ExprToTextInputLinker; } });
|
|
53
54
|
class IfcExpressionParseResult {
|
|
54
55
|
constructor(input, typeManager, exprContext) {
|
|
55
56
|
this._typeManager = typeManager;
|
|
@@ -88,7 +89,8 @@ class IfcExpression {
|
|
|
88
89
|
}
|
|
89
90
|
lexer.addErrorListener(myErrorListener);
|
|
90
91
|
parser.addErrorListener(myErrorListener);
|
|
91
|
-
|
|
92
|
+
let expr;
|
|
93
|
+
expr = parser.expr();
|
|
92
94
|
const validationListener = new IfcExpressionValidationListener_js_1.IfcExpressionValidationListener();
|
|
93
95
|
if (!myErrorListener.isErrorOccurred()) {
|
|
94
96
|
const walker = new antlr4_1.ParseTreeWalker();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/IfcExpression.ts"],"names":[],"mappings":";;;;;;AAAA,mCAOgB;AAChB,gEAA0D;AA2DxD,6FA3DO,8BAAY,OA2DP;AA1Dd,mFAA6E;AA6D3E,2GA7DO,0DAA0B,OA6DP;AA5D5B,sGAAgG;AAEhG,wEAAoE;AA6DlE,0FA7DO,iCAAS,OA6DP;AADT,0FA5DkB,iCAAS,OA4DlB;AAxDX,2EAAqE;AAmCnE,mGAnCO,0CAAkB,OAmCP;AAjCpB,2DAAqD;AAoCnD,4FApCO,4BAAW,OAoCP;AAnCb,6DAAuD;AAsCrD,6FAtCO,8BAAY,OAsCP;AArCd,6DAAuD;AAmCrD,6FAnCO,8BAAY,OAmCP;AAlCd,6DAAuD;AAmCrD,6FAnCO,8BAAY,OAmCP;AAlCd,iEAA2D;AAqCzD,+FArCO,kCAAc,OAqCP;AApChB,mFAA6E;AAqC3E,uGArCO,kDAAsB,OAqCP;AApCxB,6EAAuE;AAqCrE,oGArCO,4CAAmB,OAqCP;AApCrB,iFAA2E;AAqCzE,sGArCO,gDAAqB,OAqCP;AApCvB,iFAA2E;AAqCzE,sGArCO,gDAAqB,OAqCP;AApCvB,6EAAuE;AAqCrE,oGArCO,4CAAmB,OAqCP;AApCrB,iGAAsE;AACtE,mGAAwE;AA0CtE,+BA1CK,iCAAoB,CA0CL;AAzCtB,+FAAoE;AAEpE,0GAAoG;AAqClG,iHArCO,sEAAgC,OAqCP;AAlClC,sEAMwC;AAmCtC,gGArCA,mCAAe,OAqCA;AACf,kGArCA,qCAAiB,OAqCA;AAnCnB,0DAAoD;AA0BlD,yFA1BO,sBAAQ,OA0BP;AAzBV,2EAAqE;AAErE,iGAAyE;AACzE,2DAAqD;AACrD,4EAAy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C,kBAAkB,CAC9B,IAA2B,EAC3B,UAAgC,IAAI,0BAAU,EAAE;QAEhD,IAAI,IAAA,iCAAS,EAAC,IAAI,CAAC,WAAW,EAAE,CAAC,EAAE;YACjC,sEAAsE;YACtE,sGAAsG;YACtG,sBAAsB;YACtB,iCAAiC;YACjC,IAAI,CAAC,YAAY,EAAE,CAAC;SACrB;QACD,OAAO,IAAI,CAAC,QAAQ,CAAC,OAAO,EAAE,IAAI,GAAG,EAAE,CAAC,CAAC;IAC3C,CAAC;CACF;AAvHD,sCAuHC","file":"IfcExpression.js","sourcesContent":["import {\n CharStream,\n CommonTokenStream,\n ErrorListener,\n ParserRuleContext,\n ParseTreeWalker,\n Token,\n} from \"antlr4\";\nimport { ExprCompiler } from \"./compiler/ExprCompiler.js\";\nimport { IfcExpressionErrorListener } from \"./IfcExpressionErrorListener.js\";\nimport { IfcExpressionValidationListener } from \"./compiler/IfcExpressionValidationListener.js\";\n\nimport { isNullish, isPresent } from \"./util/IfcExpressionUtils.js\";\nimport { IfcExpressionContext } from \"./context/IfcExpressionContext.js\";\nimport { Expr } from \"./expression/Expr.js\";\n\nimport { IfcElementAccessor } from \"./context/IfcElementAccessor.js\";\nimport { Value } from \"./value/Value.js\";\nimport { StringValue } from \"./value/StringValue.js\";\nimport { NumericValue } from \"./value/NumericValue.js\";\nimport { BooleanValue } from \"./value/BooleanValue.js\";\nimport { LogicalValue } from \"./value/LogicalValue.js\";\nimport { ReferenceValue } from \"./value/ReferenceValue.js\";\nimport { IfcPropertySetAccessor } from \"./context/IfcPropertySetAccessor.js\";\nimport { IfcPropertyAccessor } from \"./context/IfcPropertyAccessor.js\";\nimport { IfcRootObjectAccessor } from \"./context/IfcRootObjectAccessor.js\";\nimport { IfcTypeObjectAccessor } from \"./context/IfcTypeObjectAccessor.js\";\nimport { NamedObjectAccessor } from \"./context/NamedObjectAccessor.js\";\nimport IfcExpressionParser from \"./gen/parser/IfcExpressionParser.js\";\nimport IfcExpressionVisitor from \"./gen/parser/IfcExpressionVisitor.js\";\nimport IfcExpressionLexer from \"./gen/parser/IfcExpressionLexer.js\";\nimport { ObjectAccessor } from \"./context/ObjectAccessor.js\";\nimport { IfcExpressionEvaluationException } from \"./expression/IfcExpressionEvaluationException.js\";\nimport type { ExpressionValue } from \"./value/ExpressionValue.js\";\nimport type { BoxedValueTypes } from \"./value/BoxedValueTypes.js\";\nimport {\n ExprEvalConsequentialError1Obj,\n ExprEvalError,\n ExprEvalResult,\n isExprEvalError,\n isExprEvalSuccess,\n} from \"./expression/ExprEvalResult.js\";\nimport { ExprKind } from \"./expression/ExprKind.js\";\nimport { ValidationException } from \"./error/ValidationException.js\";\nimport { TypeManager } from \"./compiler/TypeManager.js\";\nimport { mapException } from \"./error/ExceptionToExprEvalErrorMapper.js\";\nimport { NopContext } from \"./context/NopContext.js\";\nimport { ExprToTextInputLinker } from \"./compiler/ExprToTextInputLinker\";\nimport { TextSpan } from \"./util/TextSpan\";\n\nexport {\n IfcElementAccessor,\n IfcExpressionContext,\n Value,\n StringValue,\n BooleanValue,\n LogicalValue,\n NumericValue,\n ExpressionValue,\n ReferenceValue,\n IfcPropertySetAccessor,\n IfcPropertyAccessor,\n IfcRootObjectAccessor,\n IfcTypeObjectAccessor,\n NamedObjectAccessor,\n ObjectAccessor,\n Expr,\n ExprCompiler,\n ExprKind,\n IfcExpressionEvaluationException,\n IfcExpressionErrorListener,\n IfcExpressionVisitor,\n isPresent,\n isNullish,\n ExprEvalResult,\n ExprEvalError,\n isExprEvalError,\n isExprEvalSuccess,\n};\n\nexport type { BoxedValueTypes };\n\nexport class IfcExpressionParseResult {\n private readonly _input: string;\n private readonly _typeManager: TypeManager;\n private readonly _parseTree: ParserRuleContext;\n\n constructor(input: string, typeManager: TypeManager, exprContext) {\n this._typeManager = typeManager;\n this._parseTree = exprContext;\n this._input = input;\n }\n\n get typeManager(): TypeManager {\n return this._typeManager;\n }\n\n get parseTree(): ParserRuleContext {\n return this._parseTree;\n }\n\n get input(): string {\n return this._input;\n }\n}\n\nexport class IfcExpression {\n /**\n * Parses the input and returns a parse result, which contains the parse tree, the type information per parse tree node, and the input.\n * @param input\n * @param errorListener\n * @return the parse result, which can subequently be compiled into an Expr using compile().\n */\n public static parse(\n input: string,\n errorListener?: ErrorListener<Token | number>\n ): IfcExpressionParseResult {\n const chars = new CharStream(input); // replace this with a FileStream as required\n const lexer = new IfcExpressionLexer(chars);\n const tokens = new CommonTokenStream(lexer);\n const parser = new IfcExpressionParser(tokens);\n lexer.removeErrorListeners();\n parser.removeErrorListeners();\n const myErrorListener = new IfcExpressionErrorListener();\n if (isPresent(errorListener)) {\n lexer.addErrorListener(errorListener);\n parser.addErrorListener(errorListener);\n }\n lexer.addErrorListener(myErrorListener);\n parser.addErrorListener(myErrorListener);\n const expr = parser.expr();\n const validationListener = new IfcExpressionValidationListener();\n if (!myErrorListener.isErrorOccurred()) {\n const walker = new ParseTreeWalker();\n try {\n walker.walk(validationListener, expr);\n } catch (e) {\n if (e instanceof ValidationException) {\n if (errorListener instanceof IfcExpressionErrorListener) {\n errorListener.validationException(e);\n }\n myErrorListener.validationException(e);\n }\n }\n }\n return new IfcExpressionParseResult(\n input,\n validationListener.getTypeManager(),\n expr\n );\n }\n\n /**\n * Compiles the specified parseResult into an Expr.\n * @param parseResult\n * @return the Expression (Expr), which can be evaluated to obtain its result.\n */\n public static compile(\n parseResult: IfcExpressionParseResult\n ): Expr<ExpressionValue> {\n const compiler = new ExprCompiler(parseResult.typeManager);\n const expr = compiler.visit(parseResult.parseTree);\n ExprToTextInputLinker.linkTextToExpressions(\n parseResult.input,\n expr,\n compiler.getExprManager()\n );\n return expr;\n }\n\n /**\n * Evaluates the specified input expression and returns the evaluation result. The parse\n * and compile steps are done internally.\n *\n * @param expression: the input expression\n * @param context: the context required for accessing the IFC model\n * @return the result (or an error object).\n */\n public static evaluate(\n expression: string,\n context: IfcExpressionContext = new NopContext()\n ): ExprEvalResult<ExpressionValue> {\n const errorListener = new IfcExpressionErrorListener();\n const parseResult = IfcExpression.parse(expression, errorListener);\n if (errorListener.isErrorOccurred()) {\n return mapException(errorListener.getException());\n }\n const compiledExpression = this.compile(parseResult);\n return compiledExpression.evaluate(context, new Map<string, any>());\n }\n\n public static formatError(input: string, error: ExprEvalError) {\n const lines = [\"** Error **\"];\n if (!isNullish(error[\"textSpan\"])) {\n const span: TextSpan = error[\"textSpan\"];\n const underlined = span.underline(input, \"^\");\n const startString = \"Input: \";\n const indented = this.indent(underlined, startString.length);\n const replaced = startString + indented.substr(startString.length);\n replaced.split(\"\\n\").forEach((line) => lines.push(line));\n }\n lines.push(\"Problem: \" + error.message);\n return lines.join(\"\\n\");\n }\n\n private static indent(s: string, by: number) {\n return s\n .split(\"\\n\")\n .map((line) => \" \".repeat(by) + line)\n .join(\"\\n\");\n }\n\n public static evaluateExpression(\n expr: Expr<ExpressionValue>,\n context: IfcExpressionContext = new NopContext()\n ) {\n if (isNullish(expr.getTextSpan())) {\n // if the expr was created by parsing an input, it has a textSpan set.\n // If the expr was created programmatically, we have to generate its exprString once, which causes its\n // textspan to be set.\n // make sure we know the position\n expr.toExprString();\n }\n return expr.evaluate(context, new Map());\n }\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../../src/IfcExpression.ts"],"names":[],"mappings":";;;;;;AAAA,mCAOgB;AAChB,gEAA0D;AA0DxD,6FA1DO,8BAAY,OA0DP;AAzDd,mFAA6E;AA4D3E,2GA5DO,0DAA0B,OA4DP;AA3D5B,sGAAgG;AAEhG,wEAAoE;AA4DlE,0FA5DO,iCAAS,OA4DP;AADT,0FA3DkB,iCAAS,OA2DlB;AAvDX,2EAAqE;AAkCnE,mGAlCO,0CAAkB,OAkCP;AAhCpB,2DAAqD;AAmCnD,4FAnCO,4BAAW,OAmCP;AAlCb,6DAAuD;AAqCrD,6FArCO,8BAAY,OAqCP;AApCd,6DAAuD;AAkCrD,6FAlCO,8BAAY,OAkCP;AAjCd,6DAAuD;AAkCrD,6FAlCO,8BAAY,OAkCP;AAjCd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MAAM,QAAQ,GAAG,WAAW,GAAG,QAAQ,CAAC,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC;YACnE,QAAQ,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;SAC1D;QACD,KAAK,CAAC,IAAI,CAAC,WAAW,GAAG,KAAK,CAAC,OAAO,CAAC,CAAC;QACxC,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC1B,CAAC;IAEO,MAAM,CAAC,MAAM,CAAC,CAAS,EAAE,EAAU;QACzC,OAAO,CAAC;aACL,KAAK,CAAC,IAAI,CAAC;aACX,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC;aACpC,IAAI,CAAC,IAAI,CAAC,CAAC;IAChB,CAAC;IAEM,MAAM,CAAC,kBAAkB,CAC9B,IAA2B,EAC3B,UAAgC,IAAI,0BAAU,EAAE;QAEhD,IAAI,IAAA,iCAAS,EAAC,IAAI,CAAC,WAAW,EAAE,CAAC,EAAE;YACjC,sEAAsE;YACtE,sGAAsG;YACtG,sBAAsB;YACtB,iCAAiC;YACjC,IAAI,CAAC,YAAY,EAAE,CAAC;SACrB;QACD,OAAO,IAAI,CAAC,QAAQ,CAAC,OAAO,EAAE,IAAI,GAAG,EAAE,CAAC,CAAC;IAC3C,CAAC;CACF;AAxHD,sCAwHC","file":"IfcExpression.js","sourcesContent":["import {\n CharStream,\n CommonTokenStream,\n ErrorListener,\n ParserRuleContext,\n ParseTreeWalker,\n Token,\n} from \"antlr4\";\nimport { ExprCompiler } from \"./compiler/ExprCompiler.js\";\nimport { IfcExpressionErrorListener } from \"./IfcExpressionErrorListener.js\";\nimport { IfcExpressionValidationListener } from \"./compiler/IfcExpressionValidationListener.js\";\n\nimport { isNullish, isPresent } from \"./util/IfcExpressionUtils.js\";\nimport { IfcExpressionContext } from \"./context/IfcExpressionContext.js\";\nimport { Expr } from \"./expression/Expr.js\";\n\nimport { IfcElementAccessor } from \"./context/IfcElementAccessor.js\";\nimport { Value } from \"./value/Value.js\";\nimport { StringValue } from \"./value/StringValue.js\";\nimport { NumericValue } from \"./value/NumericValue.js\";\nimport { BooleanValue } from \"./value/BooleanValue.js\";\nimport { LogicalValue } from \"./value/LogicalValue.js\";\nimport { ReferenceValue } from \"./value/ReferenceValue.js\";\nimport { IfcPropertySetAccessor } from \"./context/IfcPropertySetAccessor.js\";\nimport { IfcPropertyAccessor } from \"./context/IfcPropertyAccessor.js\";\nimport { IfcRootObjectAccessor } from \"./context/IfcRootObjectAccessor.js\";\nimport { IfcTypeObjectAccessor } from \"./context/IfcTypeObjectAccessor.js\";\nimport { NamedObjectAccessor } from \"./context/NamedObjectAccessor.js\";\nimport IfcExpressionParser from \"./gen/parser/IfcExpressionParser.js\";\nimport IfcExpressionVisitor from \"./gen/parser/IfcExpressionVisitor.js\";\nimport IfcExpressionLexer from \"./gen/parser/IfcExpressionLexer.js\";\nimport { ObjectAccessor } from \"./context/ObjectAccessor.js\";\nimport { IfcExpressionEvaluationException } from \"./expression/IfcExpressionEvaluationException.js\";\nimport type { ExpressionValue } from \"./value/ExpressionValue.js\";\nimport type { BoxedValueTypes } from \"./value/BoxedValueTypes.js\";\nimport {\n ExprEvalError,\n ExprEvalResult,\n isExprEvalError,\n isExprEvalSuccess,\n} from \"./expression/ExprEvalResult.js\";\nimport { ExprKind } from \"./expression/ExprKind.js\";\nimport { ValidationException } from \"./error/ValidationException.js\";\nimport { TypeManager } from \"./compiler/TypeManager.js\";\nimport { mapException } from \"./error/ExceptionToExprEvalErrorMapper.js\";\nimport { NopContext } from \"./context/NopContext.js\";\nimport { ExprToTextInputLinker } from \"./compiler/ExprToTextInputLinker\";\nimport { TextSpan } from \"./util/TextSpan\";\n\nexport {\n IfcElementAccessor,\n IfcExpressionContext,\n Value,\n StringValue,\n BooleanValue,\n LogicalValue,\n NumericValue,\n ExpressionValue,\n ReferenceValue,\n IfcPropertySetAccessor,\n IfcPropertyAccessor,\n IfcRootObjectAccessor,\n IfcTypeObjectAccessor,\n NamedObjectAccessor,\n ObjectAccessor,\n Expr,\n ExprCompiler,\n ExprKind,\n IfcExpressionEvaluationException,\n IfcExpressionErrorListener,\n IfcExpressionVisitor,\n isPresent,\n isNullish,\n ExprEvalResult,\n ExprEvalError,\n isExprEvalError,\n isExprEvalSuccess,\n ExprToTextInputLinker,\n};\n\nexport type { BoxedValueTypes };\n\nexport class IfcExpressionParseResult {\n private readonly _input: string;\n private readonly _typeManager: TypeManager;\n private readonly _parseTree: ParserRuleContext;\n\n constructor(input: string, typeManager: TypeManager, exprContext) {\n this._typeManager = typeManager;\n this._parseTree = exprContext;\n this._input = input;\n }\n\n get typeManager(): TypeManager {\n return this._typeManager;\n }\n\n get parseTree(): ParserRuleContext {\n return this._parseTree;\n }\n\n get input(): string {\n return this._input;\n }\n}\n\nexport class IfcExpression {\n /**\n * Parses the input and returns a parse result, which contains the parse tree, the type information per parse tree node, and the input.\n * @param input\n * @param errorListener\n * @return the parse result, which can subequently be compiled into an Expr using compile().\n */\n public static parse(\n input: string,\n errorListener?: ErrorListener<Token | number>\n ): IfcExpressionParseResult {\n const chars = new CharStream(input); // replace this with a FileStream as required\n const lexer = new IfcExpressionLexer(chars);\n const tokens = new CommonTokenStream(lexer);\n const parser = new IfcExpressionParser(tokens);\n lexer.removeErrorListeners();\n parser.removeErrorListeners();\n const myErrorListener = new IfcExpressionErrorListener();\n if (isPresent(errorListener)) {\n lexer.addErrorListener(errorListener);\n parser.addErrorListener(errorListener);\n }\n lexer.addErrorListener(myErrorListener);\n parser.addErrorListener(myErrorListener);\n let expr;\n expr = parser.expr();\n const validationListener = new IfcExpressionValidationListener();\n if (!myErrorListener.isErrorOccurred()) {\n const walker = new ParseTreeWalker();\n try {\n walker.walk(validationListener, expr);\n } catch (e) {\n if (e instanceof ValidationException) {\n if (errorListener instanceof IfcExpressionErrorListener) {\n errorListener.validationException(e);\n }\n myErrorListener.validationException(e);\n }\n }\n }\n return new IfcExpressionParseResult(\n input,\n validationListener.getTypeManager(),\n expr\n );\n }\n\n /**\n * Compiles the specified parseResult into an Expr.\n * @param parseResult\n * @return the Expression (Expr), which can be evaluated to obtain its result.\n */\n public static compile(\n parseResult: IfcExpressionParseResult\n ): Expr<ExpressionValue> {\n const compiler = new ExprCompiler(parseResult.typeManager);\n const expr = compiler.visit(parseResult.parseTree);\n ExprToTextInputLinker.linkTextToExpressions(\n parseResult.input,\n expr,\n compiler.getExprManager()\n );\n return expr;\n }\n\n /**\n * Evaluates the specified input expression and returns the evaluation result. The parse\n * and compile steps are done internally.\n *\n * @param expression: the input expression\n * @param context: the context required for accessing the IFC model\n * @return the result (or an error object).\n */\n public static evaluate(\n expression: string,\n context: IfcExpressionContext = new NopContext()\n ): ExprEvalResult<ExpressionValue> {\n const errorListener = new IfcExpressionErrorListener();\n const parseResult = IfcExpression.parse(expression, errorListener);\n if (errorListener.isErrorOccurred()) {\n return mapException(errorListener.getException());\n }\n const compiledExpression = this.compile(parseResult);\n return compiledExpression.evaluate(context, new Map<string, any>());\n }\n\n public static formatError(input: string, error: ExprEvalError) {\n const lines = [\"** Error **\"];\n if (!isNullish(error[\"textSpan\"])) {\n const span: TextSpan = error[\"textSpan\"];\n const underlined = span.underline(input, \"^\");\n const startString = \"Input: \";\n const indented = this.indent(underlined, startString.length);\n const replaced = startString + indented.substr(startString.length);\n replaced.split(\"\\n\").forEach((line) => lines.push(line));\n }\n lines.push(\"Problem: \" + error.message);\n return lines.join(\"\\n\");\n }\n\n private static indent(s: string, by: number) {\n return s\n .split(\"\\n\")\n .map((line) => \" \".repeat(by) + line)\n .join(\"\\n\");\n }\n\n public static evaluateExpression(\n expr: Expr<ExpressionValue>,\n context: IfcExpressionContext = new NopContext()\n ) {\n if (isNullish(expr.getTextSpan())) {\n // if the expr was created by parsing an input, it has a textSpan set.\n // If the expr was created programmatically, we have to generate its exprString once, which causes its\n // textspan to be set.\n // make sure we know the position\n expr.toExprString();\n }\n return expr.evaluate(context, new Map());\n }\n}\n"]}
|
|
@@ -24,7 +24,7 @@ import { ValidationException } from "./error/ValidationException.js";
|
|
|
24
24
|
import { mapException } from "./error/ExceptionToExprEvalErrorMapper.js";
|
|
25
25
|
import { NopContext } from "./context/NopContext.js";
|
|
26
26
|
import { ExprToTextInputLinker } from "./compiler/ExprToTextInputLinker";
|
|
27
|
-
export { IfcElementAccessor, StringValue, BooleanValue, LogicalValue, NumericValue, ReferenceValue, IfcPropertySetAccessor, IfcPropertyAccessor, IfcRootObjectAccessor, IfcTypeObjectAccessor, NamedObjectAccessor, ExprCompiler, ExprKind, IfcExpressionEvaluationException, IfcExpressionErrorListener, IfcExpressionVisitor, isPresent, isNullish, isExprEvalError, isExprEvalSuccess, };
|
|
27
|
+
export { IfcElementAccessor, StringValue, BooleanValue, LogicalValue, NumericValue, ReferenceValue, IfcPropertySetAccessor, IfcPropertyAccessor, IfcRootObjectAccessor, IfcTypeObjectAccessor, NamedObjectAccessor, ExprCompiler, ExprKind, IfcExpressionEvaluationException, IfcExpressionErrorListener, IfcExpressionVisitor, isPresent, isNullish, isExprEvalError, isExprEvalSuccess, ExprToTextInputLinker, };
|
|
28
28
|
export class IfcExpressionParseResult {
|
|
29
29
|
constructor(input, typeManager, exprContext) {
|
|
30
30
|
this._typeManager = typeManager;
|
|
@@ -62,7 +62,8 @@ export class IfcExpression {
|
|
|
62
62
|
}
|
|
63
63
|
lexer.addErrorListener(myErrorListener);
|
|
64
64
|
parser.addErrorListener(myErrorListener);
|
|
65
|
-
|
|
65
|
+
let expr;
|
|
66
|
+
expr = parser.expr();
|
|
66
67
|
const validationListener = new IfcExpressionValidationListener();
|
|
67
68
|
if (!myErrorListener.isErrorOccurred()) {
|
|
68
69
|
const walker = new ParseTreeWalker();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":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C,IAAI,CAAC,CAAC,CAAC;SAC1D;QACD,KAAK,CAAC,IAAI,CAAC,WAAW,GAAG,KAAK,CAAC,OAAO,CAAC,CAAC;QACxC,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC1B,CAAC;IAEO,MAAM,CAAC,MAAM,CAAC,CAAS,EAAE,EAAU;QACzC,OAAO,CAAC;aACL,KAAK,CAAC,IAAI,CAAC;aACX,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC;aACpC,IAAI,CAAC,IAAI,CAAC,CAAC;IAChB,CAAC;IAEM,MAAM,CAAC,kBAAkB,CAC9B,IAA2B,EAC3B,UAAgC,IAAI,UAAU,EAAE;QAEhD,IAAI,SAAS,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC,EAAE;YACjC,sEAAsE;YACtE,sGAAsG;YACtG,sBAAsB;YACtB,iCAAiC;YACjC,IAAI,CAAC,YAAY,EAAE,CAAC;SACrB;QACD,OAAO,IAAI,CAAC,QAAQ,CAAC,OAAO,EAAE,IAAI,GAAG,EAAE,CAAC,CAAC;IAC3C,CAAC;CACF","file":"IfcExpression.js","sourcesContent":["import {\n CharStream,\n CommonTokenStream,\n ErrorListener,\n ParserRuleContext,\n ParseTreeWalker,\n Token,\n} from \"antlr4\";\nimport { ExprCompiler } from \"./compiler/ExprCompiler.js\";\nimport { IfcExpressionErrorListener } from \"./IfcExpressionErrorListener.js\";\nimport { IfcExpressionValidationListener } from \"./compiler/IfcExpressionValidationListener.js\";\n\nimport { isNullish, isPresent } from \"./util/IfcExpressionUtils.js\";\nimport { IfcExpressionContext } from \"./context/IfcExpressionContext.js\";\nimport { Expr } from \"./expression/Expr.js\";\n\nimport { IfcElementAccessor } from \"./context/IfcElementAccessor.js\";\nimport { Value } from \"./value/Value.js\";\nimport { StringValue } from \"./value/StringValue.js\";\nimport { NumericValue } from \"./value/NumericValue.js\";\nimport { BooleanValue } from \"./value/BooleanValue.js\";\nimport { LogicalValue } from \"./value/LogicalValue.js\";\nimport { ReferenceValue } from \"./value/ReferenceValue.js\";\nimport { IfcPropertySetAccessor } from \"./context/IfcPropertySetAccessor.js\";\nimport { IfcPropertyAccessor } from \"./context/IfcPropertyAccessor.js\";\nimport { IfcRootObjectAccessor } from \"./context/IfcRootObjectAccessor.js\";\nimport { IfcTypeObjectAccessor } from \"./context/IfcTypeObjectAccessor.js\";\nimport { NamedObjectAccessor } from \"./context/NamedObjectAccessor.js\";\nimport IfcExpressionParser from \"./gen/parser/IfcExpressionParser.js\";\nimport IfcExpressionVisitor from \"./gen/parser/IfcExpressionVisitor.js\";\nimport IfcExpressionLexer from \"./gen/parser/IfcExpressionLexer.js\";\nimport { ObjectAccessor } from \"./context/ObjectAccessor.js\";\nimport { IfcExpressionEvaluationException } from \"./expression/IfcExpressionEvaluationException.js\";\nimport type { ExpressionValue } from \"./value/ExpressionValue.js\";\nimport type { BoxedValueTypes } from \"./value/BoxedValueTypes.js\";\nimport {\n ExprEvalConsequentialError1Obj,\n ExprEvalError,\n ExprEvalResult,\n isExprEvalError,\n isExprEvalSuccess,\n} from \"./expression/ExprEvalResult.js\";\nimport { ExprKind } from \"./expression/ExprKind.js\";\nimport { ValidationException } from \"./error/ValidationException.js\";\nimport { TypeManager } from \"./compiler/TypeManager.js\";\nimport { mapException } from \"./error/ExceptionToExprEvalErrorMapper.js\";\nimport { NopContext } from \"./context/NopContext.js\";\nimport { ExprToTextInputLinker } from \"./compiler/ExprToTextInputLinker\";\nimport { TextSpan } from \"./util/TextSpan\";\n\nexport {\n IfcElementAccessor,\n IfcExpressionContext,\n Value,\n StringValue,\n BooleanValue,\n LogicalValue,\n NumericValue,\n ExpressionValue,\n ReferenceValue,\n IfcPropertySetAccessor,\n IfcPropertyAccessor,\n IfcRootObjectAccessor,\n IfcTypeObjectAccessor,\n NamedObjectAccessor,\n ObjectAccessor,\n Expr,\n ExprCompiler,\n ExprKind,\n IfcExpressionEvaluationException,\n IfcExpressionErrorListener,\n IfcExpressionVisitor,\n isPresent,\n isNullish,\n ExprEvalResult,\n ExprEvalError,\n isExprEvalError,\n isExprEvalSuccess,\n};\n\nexport type { BoxedValueTypes };\n\nexport class IfcExpressionParseResult {\n private readonly _input: string;\n private readonly _typeManager: TypeManager;\n private readonly _parseTree: ParserRuleContext;\n\n constructor(input: string, typeManager: TypeManager, exprContext) {\n this._typeManager = typeManager;\n this._parseTree = exprContext;\n this._input = input;\n }\n\n get typeManager(): TypeManager {\n return this._typeManager;\n }\n\n get parseTree(): ParserRuleContext {\n return this._parseTree;\n }\n\n get input(): string {\n return this._input;\n }\n}\n\nexport class IfcExpression {\n /**\n * Parses the input and returns a parse result, which contains the parse tree, the type information per parse tree node, and the input.\n * @param input\n * @param errorListener\n * @return the parse result, which can subequently be compiled into an Expr using compile().\n */\n public static parse(\n input: string,\n errorListener?: ErrorListener<Token | number>\n ): IfcExpressionParseResult {\n const chars = new CharStream(input); // replace this with a FileStream as required\n const lexer = new IfcExpressionLexer(chars);\n const tokens = new CommonTokenStream(lexer);\n const parser = new IfcExpressionParser(tokens);\n lexer.removeErrorListeners();\n parser.removeErrorListeners();\n const myErrorListener = new IfcExpressionErrorListener();\n if (isPresent(errorListener)) {\n lexer.addErrorListener(errorListener);\n parser.addErrorListener(errorListener);\n }\n lexer.addErrorListener(myErrorListener);\n parser.addErrorListener(myErrorListener);\n const expr = parser.expr();\n const validationListener = new IfcExpressionValidationListener();\n if (!myErrorListener.isErrorOccurred()) {\n const walker = new ParseTreeWalker();\n try {\n walker.walk(validationListener, expr);\n } catch (e) {\n if (e instanceof ValidationException) {\n if (errorListener instanceof IfcExpressionErrorListener) {\n errorListener.validationException(e);\n }\n myErrorListener.validationException(e);\n }\n }\n }\n return new IfcExpressionParseResult(\n input,\n validationListener.getTypeManager(),\n expr\n );\n }\n\n /**\n * Compiles the specified parseResult into an Expr.\n * @param parseResult\n * @return the Expression (Expr), which can be evaluated to obtain its result.\n */\n public static compile(\n parseResult: IfcExpressionParseResult\n ): Expr<ExpressionValue> {\n const compiler = new ExprCompiler(parseResult.typeManager);\n const expr = compiler.visit(parseResult.parseTree);\n ExprToTextInputLinker.linkTextToExpressions(\n parseResult.input,\n expr,\n compiler.getExprManager()\n );\n return expr;\n }\n\n /**\n * Evaluates the specified input expression and returns the evaluation result. The parse\n * and compile steps are done internally.\n *\n * @param expression: the input expression\n * @param context: the context required for accessing the IFC model\n * @return the result (or an error object).\n */\n public static evaluate(\n expression: string,\n context: IfcExpressionContext = new NopContext()\n ): ExprEvalResult<ExpressionValue> {\n const errorListener = new IfcExpressionErrorListener();\n const parseResult = IfcExpression.parse(expression, errorListener);\n if (errorListener.isErrorOccurred()) {\n return mapException(errorListener.getException());\n }\n const compiledExpression = this.compile(parseResult);\n return compiledExpression.evaluate(context, new Map<string, any>());\n }\n\n public static formatError(input: string, error: ExprEvalError) {\n const lines = [\"** Error **\"];\n if (!isNullish(error[\"textSpan\"])) {\n const span: TextSpan = error[\"textSpan\"];\n const underlined = span.underline(input, \"^\");\n const startString = \"Input: \";\n const indented = this.indent(underlined, startString.length);\n const replaced = startString + indented.substr(startString.length);\n replaced.split(\"\\n\").forEach((line) => lines.push(line));\n }\n lines.push(\"Problem: \" + error.message);\n return lines.join(\"\\n\");\n }\n\n private static indent(s: string, by: number) {\n return s\n .split(\"\\n\")\n .map((line) => \" \".repeat(by) + line)\n .join(\"\\n\");\n }\n\n public static evaluateExpression(\n expr: Expr<ExpressionValue>,\n context: IfcExpressionContext = new NopContext()\n ) {\n if (isNullish(expr.getTextSpan())) {\n // if the expr was created by parsing an input, it has a textSpan set.\n // If the expr was created programmatically, we have to generate its exprString once, which causes its\n // textspan to be set.\n // make sure we know the position\n expr.toExprString();\n }\n return expr.evaluate(context, new Map());\n }\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["IfcExpression.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,EACV,iBAAiB,EAGjB,eA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IAAI,CAAC,WAAW,GAAG,KAAK,CAAC,OAAO,CAAC,CAAC;QACxC,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC1B,CAAC;IAEO,MAAM,CAAC,MAAM,CAAC,CAAS,EAAE,EAAU;QACzC,OAAO,CAAC;aACL,KAAK,CAAC,IAAI,CAAC;aACX,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC;aACpC,IAAI,CAAC,IAAI,CAAC,CAAC;IAChB,CAAC;IAEM,MAAM,CAAC,kBAAkB,CAC9B,IAA2B,EAC3B,UAAgC,IAAI,UAAU,EAAE;QAEhD,IAAI,SAAS,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC,EAAE;YACjC,sEAAsE;YACtE,sGAAsG;YACtG,sBAAsB;YACtB,iCAAiC;YACjC,IAAI,CAAC,YAAY,EAAE,CAAC;SACrB;QACD,OAAO,IAAI,CAAC,QAAQ,CAAC,OAAO,EAAE,IAAI,GAAG,EAAE,CAAC,CAAC;IAC3C,CAAC;CACF","file":"IfcExpression.js","sourcesContent":["import {\n CharStream,\n CommonTokenStream,\n ErrorListener,\n ParserRuleContext,\n ParseTreeWalker,\n Token,\n} from \"antlr4\";\nimport { ExprCompiler } from \"./compiler/ExprCompiler.js\";\nimport { IfcExpressionErrorListener } from \"./IfcExpressionErrorListener.js\";\nimport { IfcExpressionValidationListener } from \"./compiler/IfcExpressionValidationListener.js\";\n\nimport { isNullish, isPresent } from \"./util/IfcExpressionUtils.js\";\nimport { IfcExpressionContext } from \"./context/IfcExpressionContext.js\";\nimport { Expr } from \"./expression/Expr.js\";\n\nimport { IfcElementAccessor } from \"./context/IfcElementAccessor.js\";\nimport { Value } from \"./value/Value.js\";\nimport { StringValue } from \"./value/StringValue.js\";\nimport { NumericValue } from \"./value/NumericValue.js\";\nimport { BooleanValue } from \"./value/BooleanValue.js\";\nimport { LogicalValue } from \"./value/LogicalValue.js\";\nimport { ReferenceValue } from \"./value/ReferenceValue.js\";\nimport { IfcPropertySetAccessor } from \"./context/IfcPropertySetAccessor.js\";\nimport { IfcPropertyAccessor } from \"./context/IfcPropertyAccessor.js\";\nimport { IfcRootObjectAccessor } from \"./context/IfcRootObjectAccessor.js\";\nimport { IfcTypeObjectAccessor } from \"./context/IfcTypeObjectAccessor.js\";\nimport { NamedObjectAccessor } from \"./context/NamedObjectAccessor.js\";\nimport IfcExpressionParser from \"./gen/parser/IfcExpressionParser.js\";\nimport IfcExpressionVisitor from \"./gen/parser/IfcExpressionVisitor.js\";\nimport IfcExpressionLexer from \"./gen/parser/IfcExpressionLexer.js\";\nimport { ObjectAccessor } from \"./context/ObjectAccessor.js\";\nimport { IfcExpressionEvaluationException } from \"./expression/IfcExpressionEvaluationException.js\";\nimport type { ExpressionValue } from \"./value/ExpressionValue.js\";\nimport type { BoxedValueTypes } from \"./value/BoxedValueTypes.js\";\nimport {\n ExprEvalError,\n ExprEvalResult,\n isExprEvalError,\n isExprEvalSuccess,\n} from \"./expression/ExprEvalResult.js\";\nimport { ExprKind } from \"./expression/ExprKind.js\";\nimport { ValidationException } from \"./error/ValidationException.js\";\nimport { TypeManager } from \"./compiler/TypeManager.js\";\nimport { mapException } from \"./error/ExceptionToExprEvalErrorMapper.js\";\nimport { NopContext } from \"./context/NopContext.js\";\nimport { ExprToTextInputLinker } from \"./compiler/ExprToTextInputLinker\";\nimport { TextSpan } from \"./util/TextSpan\";\n\nexport {\n IfcElementAccessor,\n IfcExpressionContext,\n Value,\n StringValue,\n BooleanValue,\n LogicalValue,\n NumericValue,\n ExpressionValue,\n ReferenceValue,\n IfcPropertySetAccessor,\n IfcPropertyAccessor,\n IfcRootObjectAccessor,\n IfcTypeObjectAccessor,\n NamedObjectAccessor,\n ObjectAccessor,\n Expr,\n ExprCompiler,\n ExprKind,\n IfcExpressionEvaluationException,\n IfcExpressionErrorListener,\n IfcExpressionVisitor,\n isPresent,\n isNullish,\n ExprEvalResult,\n ExprEvalError,\n isExprEvalError,\n isExprEvalSuccess,\n ExprToTextInputLinker,\n};\n\nexport type { BoxedValueTypes };\n\nexport class IfcExpressionParseResult {\n private readonly _input: string;\n private readonly _typeManager: TypeManager;\n private readonly _parseTree: ParserRuleContext;\n\n constructor(input: string, typeManager: TypeManager, exprContext) {\n this._typeManager = typeManager;\n this._parseTree = exprContext;\n this._input = input;\n }\n\n get typeManager(): TypeManager {\n return this._typeManager;\n }\n\n get parseTree(): ParserRuleContext {\n return this._parseTree;\n }\n\n get input(): string {\n return this._input;\n }\n}\n\nexport class IfcExpression {\n /**\n * Parses the input and returns a parse result, which contains the parse tree, the type information per parse tree node, and the input.\n * @param input\n * @param errorListener\n * @return the parse result, which can subequently be compiled into an Expr using compile().\n */\n public static parse(\n input: string,\n errorListener?: ErrorListener<Token | number>\n ): IfcExpressionParseResult {\n const chars = new CharStream(input); // replace this with a FileStream as required\n const lexer = new IfcExpressionLexer(chars);\n const tokens = new CommonTokenStream(lexer);\n const parser = new IfcExpressionParser(tokens);\n lexer.removeErrorListeners();\n parser.removeErrorListeners();\n const myErrorListener = new IfcExpressionErrorListener();\n if (isPresent(errorListener)) {\n lexer.addErrorListener(errorListener);\n parser.addErrorListener(errorListener);\n }\n lexer.addErrorListener(myErrorListener);\n parser.addErrorListener(myErrorListener);\n let expr;\n expr = parser.expr();\n const validationListener = new IfcExpressionValidationListener();\n if (!myErrorListener.isErrorOccurred()) {\n const walker = new ParseTreeWalker();\n try {\n walker.walk(validationListener, expr);\n } catch (e) {\n if (e instanceof ValidationException) {\n if (errorListener instanceof IfcExpressionErrorListener) {\n errorListener.validationException(e);\n }\n myErrorListener.validationException(e);\n }\n }\n }\n return new IfcExpressionParseResult(\n input,\n validationListener.getTypeManager(),\n expr\n );\n }\n\n /**\n * Compiles the specified parseResult into an Expr.\n * @param parseResult\n * @return the Expression (Expr), which can be evaluated to obtain its result.\n */\n public static compile(\n parseResult: IfcExpressionParseResult\n ): Expr<ExpressionValue> {\n const compiler = new ExprCompiler(parseResult.typeManager);\n const expr = compiler.visit(parseResult.parseTree);\n ExprToTextInputLinker.linkTextToExpressions(\n parseResult.input,\n expr,\n compiler.getExprManager()\n );\n return expr;\n }\n\n /**\n * Evaluates the specified input expression and returns the evaluation result. The parse\n * and compile steps are done internally.\n *\n * @param expression: the input expression\n * @param context: the context required for accessing the IFC model\n * @return the result (or an error object).\n */\n public static evaluate(\n expression: string,\n context: IfcExpressionContext = new NopContext()\n ): ExprEvalResult<ExpressionValue> {\n const errorListener = new IfcExpressionErrorListener();\n const parseResult = IfcExpression.parse(expression, errorListener);\n if (errorListener.isErrorOccurred()) {\n return mapException(errorListener.getException());\n }\n const compiledExpression = this.compile(parseResult);\n return compiledExpression.evaluate(context, new Map<string, any>());\n }\n\n public static formatError(input: string, error: ExprEvalError) {\n const lines = [\"** Error **\"];\n if (!isNullish(error[\"textSpan\"])) {\n const span: TextSpan = error[\"textSpan\"];\n const underlined = span.underline(input, \"^\");\n const startString = \"Input: \";\n const indented = this.indent(underlined, startString.length);\n const replaced = startString + indented.substr(startString.length);\n replaced.split(\"\\n\").forEach((line) => lines.push(line));\n }\n lines.push(\"Problem: \" + error.message);\n return lines.join(\"\\n\");\n }\n\n private static indent(s: string, by: number) {\n return s\n .split(\"\\n\")\n .map((line) => \" \".repeat(by) + line)\n .join(\"\\n\");\n }\n\n public static evaluateExpression(\n expr: Expr<ExpressionValue>,\n context: IfcExpressionContext = new NopContext()\n ) {\n if (isNullish(expr.getTextSpan())) {\n // if the expr was created by parsing an input, it has a textSpan set.\n // If the expr was created programmatically, we have to generate its exprString once, which causes its\n // textspan to be set.\n // make sure we know the position\n expr.toExprString();\n }\n return expr.evaluate(context, new Map());\n }\n}\n"]}
|