npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ifc-expressions

v2.1.1

Published

Parsing and evaluation of IFC expressions

Downloads

81

Readme

IFC Expressions

This project defines an expression language for IFC models. An expression is evaluated in the context of an element of the IFC model and a specific property of that element.

Interface

Two ways to interact with 'ifc-expression':

  • evaluate an expression string directly - receive ExprEvalSuccessResult | ExprEvalError

or

  • parse an expression - receive a IfcExpressionParseResult
  • evaluate a IfcExpressionParseResult - receive ExprEvalSuccessResult | ExprEvalError

Usage

To connect ifc-expressions with your IFC model, you have to provide an implementation of src/context/IfcExpressionContext. Without such a context, the expressions that contain references to the model cannot be evaluated.

import {IfcExpression} from "ifc-expression";
import {IfcExpressionContext} from "./IfcExpressionContext";

const result = IfcExpression.evaluate("1 + 1"); // evaluation without context
console.log(JSON.stringify(result));
// ExprEvalSuccessObj {
//   status: 1000,
//   result: NumericValue {
//     value: 2
//   }
//}
const ctx: IfcExpressionContext = ... ; // set to your context here
const result2 = IfcExpression.evaluate("$element.property('width').value() * 2 ", ctx);

Quick Reference

Get the current property value:

$property.value()

Get the name of the property set the property is in:

$property.propertySet.name()

Get the name of the current element:

$element.name()

Get the name of the type of the current element:

$element.type().name()

Get value of property myProp from property set myPset in the current element:

$element.propertySet('myPset').property('myProp').value()

The last expression can also be written as

VALUE(PROPERTY(PROPERTY_SET($element, 'myPset'),'myProp'))

Check if property myProp exists in property set myPset in the current element:

$element.propertySet('myPset').property('myProp').exists()

Hints:

  • Function/Method names are case-insensitive
  • you have + - * / ^ for numerics
  • you have && || >< ! for booleans (><is xor)
  • you have == != >= <= > < for strings, booleans and numerics
  • you have a .toString() method on anything (or, equivalently, a function toString(x) for any x ).
  • you have REPLACE, which only knows the wildcard character *. (same for MATCHES, CONTAINS)
  • you have REGEXREPLACE with full js Regular Expressions (same for REGEXMATCHES, REGEXCONTAINS)

IFC Expression Language Syntax

The project uses ANTLR4 for parsing. The grammar is in src/grammar/ifcExpression.g4.

The result of expression evaluation is a value of type string, numeric, boolean, ifcObjectRef, where ifcObjectRef is a reference to some object in the IFC model.

The language allows for specifying a single expression. There are no control statements and there is no way to define custom functions or custom types.

An expression can be

  • a literal, such as 'hello world', or 17
  • a variable reference, such as $property or $element,(for accessing the IFC model).

... or a combination of multiple expressions:

  • a function call, such as REPLACE("hello world", "world", "friends")
  • a function call in 'method-call style', such as "hello world".replace("world", "friends")
  • a combination using operators, such as +, &&, ==

Types

  • string, e.g. 'abc' or "abc": text enclosed in single or double quotes
  • boolean, e.g. TRUE or false: true or false, either spelled all-uppercase or all-lowercase
  • numeric, e.g. 1 or 3.141: a decimal number optionally containing one period to separate integer part from fractional part
  • array, e.g. `[1,2,"hi there"]: an ordered list of expressions

Operators

  • numeric operators
    • '+', '-', '*', '/': plus, minus, multiplication, division - with the ususal precedence rules and associativity
    • '^': raise to the power or, e.g. 2^3 (= 8)
  • boolean operators
    • &&', ||, ><`: boolean and, or, xor
    • !: boolean not
  • string operators
    • '+': string concatenation

Functions

comparison functions

equals(a,b), greaterThan(a,b), greaterThanOrEquals(a,b), lessThan(a,b), lessThanOrEqual(a,b)",

boolean operator functions

not(a), and(a,b), or(a,b), xor(a,b), implies(a,b)

string matching

contains(string, pattern), e.g. contains('hello world', 'he*o') returns true if the string contains the pattern. * matches any number of characters.

regexContains(string, regex), e.g. regexContains('hello, world', 'h[aeiou]ll[aeiou]+\\\s') returns true if the string contains the regular expression.

matches(string, pattern), e.g. matches('hello world', 'he*o') returns true if the whole string matches the pattern. * matches any number of characters.

regexMatches(string, regex), e.g. regexMatches('hello, world', 'h[aeiou]ll[aeiou]+\\\s') returns true if the whole string matches the regular expression.

string replacement

replace(string, pattern, replacement), e.g. replace('hello world', 'he*o', 'bye') returns the string, with all occurrences of the pattern replaced with replacement. * matches any number of characters.

regexReplace(string, regex, replacement), e.g. regexReplace('hello, world', 'h([aeiou]ll[aeiou]+) ', 'm$1w ') returns the string, with all occurrences of the regex replaced with replacement.

ifc object accessor functions

property(object: ifcPropertySetRef|ifcTypeObjectRef|ifcElementRef, name: string): returns an ifcPropertyRef or an error or an error if object has no property with that name

propertySet(object: ifcProperty): returns an ifcPropertySetRef

propertySet(object: ifcTypeObjectRef|ifcElementRef, name: string): returns an ifcPropertySetRef or an error if the element or type has no property set with that name.

type(object: ifcElementRef): returns an ifcTypeObjectRef or an error.

exists(object: ifcObjectRef): boolean check whether an object reference obtained by the above methods actually exists (suppresses the error they generate)

Translation and condition functions

map(input, mapping: [[in, out], [in, out], ... ], default): finds the first [in,out] pair in the specified mapping where in == input and returns that pair's out value. If none is found, default is returned.

if(condition, thenValue, elseValue): returns thenValue if condition is true, elseValue otherwise.

choose([[condition, out], [condition, out], ... ], default): finds the first [condition, out] pair where condition == true and returns its out value. In none is found, default is returned.