How is your experience with the OutSystems Community?
expression-editor-pro
Reactive icon

Expression Editor Pro

Stable version 1.0.0 (Compatible with OutSystems 11)
Uploaded
 on 25 Nov (2 days ago)
 by 
0.0
 (0 ratings)
expression-editor-pro

Expression Editor Pro

Documentation
1.0.0

Expression Editor Pro is a reusable Reactive Web block for building mathematical and business expressions without hand-typing everything. Users compose formulas from predefined inputs, rate tables, operators and numeric constants. Typing is fully supported, with autocomplete and live validation. It was designed for rating and pricing scenarios, such as insurance premium formulas, but works for any calculation rule.

Key features

Editor

  • Advanced text editor built on CodeMirror 5, not the standard OutSystems Input widget
  • Type directly, or click inputs, rate tables, operators and numbers to insert them at the cursor
  • Selection replace, Backspace and Delete, Undo, Redo and Clear
  • Colour-coded tokens: inputs, rate tables, numbers, operators and brackets each have their own style

Autocomplete

  • Suggestions appear near the cursor as you type and are filtered by what you have typed
  • Up/Down to navigate, Enter or Tab to select, Esc to close, or click a suggestion
  • Selecting a suggestion replaces only the identifier being typed and keeps the rest of the formula
  • Works for both inputs and rate tables
  • You can keep typing without selecting anything

Validation

  • Red wavy underline only on the invalid identifier, never on the whole formula
  • A partially typed identifier is not flagged while you are still typing it
  • Separate indicators for "Brackets match", "Every item exists" and "Formula syntax is valid"
  • "Formula valid" / "Formula invalid" badge with clear messages
  • Detects:
    • empty formulas
    • unknown or disallowed identifiers (with a "Did you mean…" hint for wrong case)
    • consecutive operators
    • missing operands or operators
    • unbalanced or empty brackets
    • unexpected characters
  • Correct operator precedence, so A + B × C is read as A + (B × C)


Supported syntax

Expression  = Term (( + | - ) Term)*
Term        = Factor (( × | ÷ ) Factor)*
Factor      = Number | Identifier | ( Expression )

* and / are accepted and normalised to × and ÷. Identifiers are case-sensitive and may contain letters, digits and underscores.

Storing and using the formula

  • FormulaText is plain text with single spaces and × / ÷, for example BuildingContentRate × ContentsSI. Save it in a Text attribute (length 2000 or more).
  • To load it later, pass it into InitialFormula.
  • ASCII form for a backend: Replace(Replace(FormulaText, "×", "*"), "÷", "/"), or in JS FormulaBuilderLib.Parser.toAscii(text).
  • Expression tree: FormulaBuilderLib.Parser.toJson(text) returns{"version":1,"formula":"A + B × C","formulaAscii":"A + B * C","valid":true,"ast":{...}}.
  • FormulaBuilderLib.Parser.fromJson(value) accepts that JSON or plain text.
  • Always re-validate on the server before using a formula in a calculation.


Limitations

  • Unary minus (for example A × -5) is not supported, in line with the "consecutive operators are invalid" rule
  • Validation runs on the client. Re-validate the stored formula on the server before using it in calculations