Skip to content
CodelessOps

/architect · Technical

The grammar.

Anaplan's formula language has no published grammar. Every reach count, every hub, every test about a formula on this site rests on a parser I wrote for it, published on its own under MIT.

What it does

Parse a formula to a tree of plain dictionaries, list the references it makes, and write it back out unchanged. On top of that, a graph layer loads the Line Items and Modules exports and answers the questions builders ask: everything downstream of a line item with its distance, everything upstream, the most depended-on line items.

from anaplan_grammar import parse, references, unparse

ast = parse("'Employee Expenses'.Salary[SUM: 'Employee Details'.Region, LOOKUP: Grade]")
references(ast)
# [['Employee Expenses', 'Salary'], ['Employee Details', 'Region'], ['Grade']]

How it was checked

Reverse-engineered from the documentation and a corpus of unique formulas from ten production models. Every formula in the corpus parses; the round-trip and reference-recall checks are documented in the repo. The dependency edges the graph produces were compared with Anaplan's own Referenced By column, edge by edge: 0.998 precision and 0.994 recall. The same check runs on every estate as test 6.2 of the Model Health Check, and below 95% agreement every dependent finding is downgraded.

What the corpus taught that the documentation does not say

  • A doubled single quote inside a quoted name is an escaped apostrophe: 'FOX''s Share'.
  • Bare names may contain spaces, digits and ? % # / | !, and may begin or end with words that are keywords elsewhere. A clause kind (SUM, LOOKUP, SELECT) is only a keyword when followed by a colon or a bracket.
  • Production formulas mix clause kinds in one bracket, [LOOKUP: a, SUM: b], despite the documentation's warnings. The grammar accepts them; a lint flags them.
  • IF ( is ambiguous between a parenthesised condition and the spreadsheet form IF(c, a, b). The parser tries the classic form first.

Where it sits

The Model Health Check installs it and runs the 42 tests over the graph it builds. The Architect installs both at pinned commits and never sees a half-saved edit of either. The parser knows nothing about Anaplan models beyond the formula text; that is the point.

Run Anaplan in-house?

Start with the Model Health Check on your own exports.

The 42 tests and the action plan run free, hosted or on your own machine, and nothing is stored. Then give me 30 minutes and bring the three questions you would ask about your estate.