@bpmn-io/feel-analyzer
v0.1.0
Published
Static FEEL expression analyzer
Readme
FEEL Analyzer
A library for analyzing FEEL (Friendly Enough Expression Language) expressions.
Installation
npm install @bpmn-io/feel-analyzerUsage
To get started, create a FeelAnalyzer instance:
import { FeelAnalyzer } from '@bpmn-io/feel-analyzer';
const analyzer = new FeelAnalyzer();Analyze a FEEL expression to extract input variables:
const result = analyzer.analyzeExpression('x + y');
console.log(result.valid); // true
console.log(result.inputs);
// [
// { name: 'x' },
// { name: 'y' }
// ]Configure the FEEL dialect (expression or unary tests):
const analyzer = new FeelAnalyzer({
dialect: 'unaryTests' // defaults to 'expression'
});Builtins
You can provide builtins and reservedNameBuiltins to exclude built-in names from input detection. Use @camunda/feel-builtins to supply these:
import { FeelAnalyzer } from '@bpmn-io/feel-analyzer';
import { builtins, reservedNameBuiltins } from '@camunda/feel-builtins';
const analyzer = new FeelAnalyzer({
dialect: 'expression',
parserDialect: 'camunda',
builtins,
reservedNameBuiltins
});
const result = analyzer.analyzeExpression('sum(orders.amount) > 100');
console.log(result.inputs);
// [
// {
// name: 'orders',
// type: 'List',
// entries: [
// { name: 'amount' }
// ]
// }
// ]Input Variables
The analyzer extracts input variables with type information, including nested structures. The data model is aligned with variable-resolver:
const result = analyzer.analyzeExpression('person.name = "John" and scores[1] > 10');
console.log(result.inputs);
// [
// {
// name: 'person',
// type: 'Context',
// entries: [
// { name: 'name' }
// ]
// },
// {
// name: 'scores',
// type: 'List'
// }
// ]Related
- @bpmn-io/lezer-feel - FEEL language definition for the Lezer parser system
License
MIT
