formcalc-js
is an open-source, clean-room JavaScript implementation of the XFA-FormCalc language. The lexer, parser, and interpreter were built using Chevrotain.
Inspired by htmx and the locality of behavior principle, I wanted to explore the adaptation of XFA-FormCalc for validation and calculated fields in HTML forms.
<script type="importmap">
{
"imports": {
"chevrotain": "https://unpkg.com/chevrotain@11.0.3/lib/chevrotain.min.mjs",
"formcalc": "https://unpkg.com/formcalc@1.0.1/dist/formcalc.mjs"
}
}
</script>
<script type="module">
import { calculate } from "formcalc";
const results = calculate('1 + 3')
console.log(results.value);
console.log(results.cst);
console.log(results.errors);
</script>
- JetForm. XFA-FormCalc 1.0, 1999-05-14.
- Adobe. XFA-FormCalc 3.3, 2012-01-09, pp 1049-1077.
- Adobe. AEM 6.3 Forms: Designer FormCalc Reference, 2017-04-26.
Subject to the W3C Document Notice/License, the lexical and syntactical grammar as implemented by formcalc-js
can be found in the same repository: