ifc-expressions 0.1.0

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/README.md ADDED
File without changes
@@ -0,0 +1,22 @@
1
+ import IfcExpressionVisitor from "../generated/parser/IfcExpressionVisitor";
2
+ import { AttributeRefContext, ExprContext, NestedObjectChainEndContext, NestedObjectChainInnerContext, NumAddSubContext, NumAttributeRefContext, NumLitContext, NumLiteralContext, NumMulDivContext, NumParensContext, ObjectRefContext, StringAttributeRefContext, StringConcatContext, StringLiteralContext } from "../generated/parser/IfcExpressionParser";
3
+ import { Expr } from "./expression/Expr";
4
+ export declare class ExprVisitor extends IfcExpressionVisitor<Expr<any>> {
5
+ constructor();
6
+ visitAttributeRef: (ctx: AttributeRefContext) => Expr<any>;
7
+ visitObjectRef: (ctx: ObjectRefContext) => Expr<any>;
8
+ visitNestedObjectChainInner: (ctx: NestedObjectChainInnerContext) => Expr<any>;
9
+ visitNestedObjectChainEnd: (ctx: NestedObjectChainEndContext) => Expr<any>;
10
+ private stripBrackets;
11
+ visitStringLiteral: (ctx: StringLiteralContext) => Expr<any>;
12
+ visitStringAttributeRef: (ctx: StringAttributeRefContext) => Expr<any>;
13
+ visitStringConcat: (ctx: StringConcatContext) => Expr<any>;
14
+ visitNumAttributeRef: (ctx: NumAttributeRefContext) => Expr<any>;
15
+ visitNumLiteral: (ctx: NumLiteralContext) => Expr<any>;
16
+ visitNumAddSub: (ctx: NumAddSubContext) => Expr<any>;
17
+ visitNumMulDiv: (ctx: NumMulDivContext) => Expr<any>;
18
+ visitNumParens: (ctx: NumParensContext) => Expr<any>;
19
+ visitExpr: (ctx: ExprContext) => Expr<any>;
20
+ visitNumLit: (ctx: NumLitContext) => Expr<any>;
21
+ private failNode;
22
+ }
@@ -0,0 +1,8 @@
1
+ import { ErrorListener, RecognitionException, Recognizer, Token } from "antlr4";
2
+ import { SyntaxErrorException } from "./SyntaxErrorException";
3
+ export declare class IfcErrorListener extends ErrorListener<Token> {
4
+ private exception;
5
+ syntaxError(recognizer: Recognizer<Token>, offendingSymbol: Token, line: number, column: number, msg: string, e: RecognitionException | undefined): void;
6
+ isErrorOccurred(): boolean;
7
+ getException(): SyntaxErrorException;
8
+ }
@@ -0,0 +1,9 @@
1
+ import { ErrorListener, Token } from "antlr4";
2
+ import { IfcExpressionContext } from "./context/IfcExpressionContext";
3
+ import { LiteralValueAnyArity } from "./context/value/LiteralValueAnyArity";
4
+ import { ExprContext } from "../generated/parser/IfcExpressionParser";
5
+ export declare class IfcExpression {
6
+ static parse(input: string, errorListener?: ErrorListener<Token>): ExprContext;
7
+ static evaluate(expression: string, context: IfcExpressionContext): LiteralValueAnyArity;
8
+ private static extractExprTree;
9
+ }
@@ -0,0 +1,10 @@
1
+ import { Token } from "antlr4";
2
+ export declare class SyntaxErrorException extends Error {
3
+ private readonly _offendingSymbol;
4
+ private readonly _line;
5
+ private readonly _column;
6
+ constructor(offendingSymbol: Token, line: number, column: number, msg: string);
7
+ get offendingSymbol(): Token;
8
+ get line(): number;
9
+ get column(): number;
10
+ }
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.IfcExpression = void 0;
7
+ const antlr4_1 = require("antlr4");
8
+ const ExprVisitor_1 = require("./ExprVisitor");
9
+ const IfcErrorListener_1 = require("./IfcErrorListener");
10
+ const utils_1 = require("./utils");
11
+ const IfcExpressionParser_1 = __importDefault(require("../generated/parser/IfcExpressionParser"));
12
+ const IfcExpressionLexer_1 = __importDefault(require("../generated/parser/IfcExpressionLexer"));
13
+ class IfcExpression {
14
+ static parse(input, errorListener) {
15
+ const chars = new antlr4_1.CharStream(input); // replace this with a FileStream as required
16
+ const lexer = new IfcExpressionLexer_1.default(chars);
17
+ const tokens = new antlr4_1.CommonTokenStream(lexer);
18
+ const parser = new IfcExpressionParser_1.default(tokens);
19
+ if ((0, utils_1.notNullish)(errorListener)) {
20
+ parser.removeErrorListeners();
21
+ parser.addErrorListener(errorListener);
22
+ }
23
+ return parser.expr();
24
+ }
25
+ static evaluate(expression, context) {
26
+ const errorListener = new IfcErrorListener_1.IfcErrorListener();
27
+ const tree = IfcExpression.parse(expression, errorListener);
28
+ if (errorListener.isErrorOccurred()) {
29
+ throw errorListener.getException();
30
+ }
31
+ const parsedExpression = this.extractExprTree(tree);
32
+ return parsedExpression.evaluate(context);
33
+ }
34
+ static extractExprTree(tree) {
35
+ const visitor = new ExprVisitor_1.ExprVisitor();
36
+ return visitor.visit(tree);
37
+ }
38
+ }
39
+ exports.IfcExpression = IfcExpression;
40
+ //# sourceMappingURL=IfcExpression.js.map
@@ -0,0 +1,2 @@
1
+ export declare function nullish(val: any): boolean;
2
+ export declare function notNullish(val: any): boolean;
package/package.json ADDED
@@ -0,0 +1,59 @@
1
+ {
2
+ "name": "ifc-expressions",
3
+ "version": "0.1.0",
4
+ "description": "Parsing and evaluation of IFC expressions",
5
+ "main": "dist/cjs/ifcExpression.js",
6
+ "module": "dist/mjs/ifcExpression.js",
7
+ "exports": {
8
+ ".": {
9
+ "import": "./dist/mjs/ifcExpression.js",
10
+ "require": "./dist/cjs/ifcExpression.js"
11
+ }
12
+ },
13
+ "types": "./dist/ifcExpression.d.ts",
14
+ "files": [
15
+ "./dist/*"
16
+ ],
17
+ "engines": {
18
+ "node": ">=14.16"
19
+ },
20
+ "scripts": {
21
+ "build-complete": "npm run format-apply && npm run build && npm run test",
22
+ "build": "npm run clean && npm run make-parser && npm run transpile",
23
+ "clean": "gulp clean",
24
+ "make-parser": "cd src/grammar && java -jar ../../antlr4/antlr-4.13.0-complete.jar -Werror -Dlanguage=TypeScript -visitor IfcExpression.g4 -o ../../generated/parser",
25
+ "transpile": "gulp build",
26
+ "test": "jest --coverage",
27
+ "format-apply": "prettier --write .",
28
+ "lint": "eslint .",
29
+ "format-check": "prettier --check .",
30
+ "check": "npm run format-check && npm run lint"
31
+ },
32
+ "keywords": [
33
+ "MMS",
34
+ "Expressions",
35
+ "BIM",
36
+ "Merkmalservice",
37
+ "Formula"
38
+ ],
39
+ "dependencies": {
40
+ "antlr4": "^4.13.0",
41
+ "decimal.js": "^10.4.3"
42
+ },
43
+ "devDependencies": {
44
+ "@types/jest": "^29.5.2",
45
+ "@typescript-eslint/eslint-plugin": "^5.60.0",
46
+ "@typescript-eslint/parser": "^5.60.0",
47
+ "del": "^7.0.0",
48
+ "eslint": "^8.43.0",
49
+ "eslint-config-prettier": "^8.8.0",
50
+ "eslint-plugin-prettier": "^4.2.1",
51
+ "gulp": "^4.0.2",
52
+ "gulp-typescript": "^6.0.0-alpha.1",
53
+ "gulp-uglify": "^3.0.2",
54
+ "jest": "^29.5.0",
55
+ "prettier": "^2.8.8",
56
+ "ts-jest": "^29.1.0",
57
+ "typescript": "^5.1.3"
58
+ }
59
+ }