formula-fields-parser
This repository contains the WIP Formula Fields Parser. Currently implemented:
- Lexer
- Parser
- Visitor
- Symbol Table
- Semantic Analysis
Exports
default
The default export is a convenience function that takes the text of a formula,
parses it, and runs semantic validation. It takes the following parameters:
formulaText
- The formula textrecordType
- Optional. The type definition of the record the formula is
being applied to. If not provided, all fields are assumed to be semantically
validrecordTypeName
- Optional, but required if recordType
is provided. The
human friendly name of recordType
. If recordType
is provided and this is
not, all fields are assumed to be semantically valid
It returns an object with the following properties:
ast
- The formula abstract syntax tree. This may
be undefined if there are errors during the lexing or parsing phases.errors
- An array of any lex,
parse, or semantic
errors that occurred when validating the formula.
All errors are guaranteed to have the following properties, although some may
have additional:
name
- The name of the error type (e.g. MismatchedTokenException)message
- The error messagelocation
- The location where the error occurred
Example
import parseAndValidate from '@lanetix/formula-fields-parser'
const { ast, errors } = parseAndValidate('CONCAT($first_name, $last_name)')
const recordType = ...
const recordTypeName = ...
const { ast, errors } = parseAndValidate('CONCAT($first_name, $last_name)', recordType, recordTypeName)