sf-formula-ast
v0.0.1
Published
Salesforce formula parser (from formula to AST)
Downloads
3
Readme
SF-FORMULA-AST
SF-FORMULA-AST is a parser for Salesforce Formulas based on Formulon grammar. The parser only build properly AST (abstract symantic tree).
Usage
Install
npm install sf-formula-ast
Example
const build = require('sf-formula-ast');
try {
let ast = build('IF( DAY( DATE(2017, 12, 10) ) = 10, true, false )');
}
Result
{ type: 'callExpression',
id: 'if',
arguments:
[ { type: 'callExpression',
id: 'equal',
arguments:
[ { type: 'callExpression',
id: 'day',
arguments:
[ { type: 'callExpression',
id: 'date',
arguments:
[ { type: 'literal',
value: 2017,
dataType: 'number',
options: { length: 4, scale: 0 } },
{ type: 'literal',
value: 12,
dataType: 'number',
options: { length: 2, scale: 0 } },
{ type: 'literal',
value: 10,
dataType: 'number',
options: { length: 2, scale: 0 } } ] } ] },
{ type: 'literal',
value: 10,
dataType: 'number',
options: { length: 2, scale: 0 } } ] },
{ type: 'literal',
value: true,
dataType: 'checkbox',
options: {} },
{ type: 'literal',
value: false,
dataType: 'checkbox',
options: {} } ] }
Data Types
Currently the following data types are supported:
- number (Integer or Float)
- text
- checkbox (TRUE or FALSE)
- null
Number options:
- Length: Number of digits to the left of the decimal point
- Scale: Number of digits to the right of the decimal point
Text options:
- Length: Number of characters
Checkbox options:
no options