Security News
Opengrep Emerges as Open Source Alternative Amid Semgrep Licensing Controversy
Opengrep forks Semgrep to preserve open source SAST in response to controversial licensing changes.
ifc-expressions
Advanced tools
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.
Two ways to interact with 'ifc-expression':
ExprEvalSuccessResult | ExprEvalError
or
IfcExpressionParseResult
IfcExpressionParseResult
- receive ExprEvalSuccessResult | ExprEvalError
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);
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:
+ - * / ^
for numerics&& || >< !
for booleans (><
is xor)== != >= <= > <
for strings, booleans and numerics.toString()
method on anything (or, equivalently, a function toString(x)
for any x
).REPLACE
, which only knows the wildcard character *
. (same for MATCHES, CONTAINS
)REGEXREPLACE
with full js Regular Expressions (same for REGEXMATCHES, REGEXCONTAINS
)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
'hello world'
, or 17
$property
or $element
,(for accessing the IFC model).... or a combination of multiple expressions:
REPLACE("hello world", "world", "friends")
"hello world".replace("world", "friends")
+
, &&
, ==
string
, e.g. 'abc'
or "abc"
: text enclosed in single or double quotesboolean
, e.g. TRUE
or false
: true or false, either spelled all-uppercase or all-lowercasenumeric
, e.g. 1
or 3.141
: a decimal number optionally containing one period to separate integer part from fractional partarray
, e.g. `[1,2,"hi there"]: an ordered list of expressions2^3
(= 8)&&',
||,
><`: boolean and, or, xor!
: boolean notequals(a,b)
, greaterThan(a,b)
, greaterThanOrEquals(a,b)
, lessThan(a,b)
, lessThanOrEqual(a,b)
",
not(a)
, and(a,b)
, or(a,b)
, xor(a,b)
, implies(a,b)
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.
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
.
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)
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.
FAQs
Parsing and evaluation of IFC expressions
We found that ifc-expressions demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Opengrep forks Semgrep to preserve open source SAST in response to controversial licensing changes.
Security News
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
Security News
cURL and Go security teams are publicly rejecting CVSS as flawed for assessing vulnerabilities and are calling for more accurate, context-aware approaches.