Skip to content

This site describes solve-engine 2.44.0, the version npm installs.

TABLES_PACKAGE

const TABLES_PACKAGE: IEnginePackage;

Defined in: packages/engine/src/packages/tables/TablesPackage.ts:71

Read a markdown table’s column as data: sum of column "cost" in table above, average of column "cost" above.

A markdown table is markup the evaluator skips, on both document paths (see lexer/TableBlocks; until #616 only its separator row was skipped and every other row reported an error), so a note can hold a table of numbers and none of them can be totalled from where they sit. This package addresses the nearest table above the query line, names one of its columns, and reduces that column’s numeric cells, reusing the same cross-line plumbing the lines package built for total above (a per-line LineExecutionContext, extended with getLineText so the skipped table rows can be read back from source).

Trigger-word collision policy (this codebase’s phrase-fusion rule, see MathPhrasesPackage.ts): the whole verb-and-noun is phrase-fused, never the bare verb. average of is already fused to AVERAGE_OF by the math-phrases package; registering the longer average of column in the same phrase trie wins by longest-match, so plain average of 1, 2, 3 is untouched while average of column "x" routes here. sum of is claimed by no one, so sum of column fuses cleanly. Synonyms (total->sum, mean->average) share a token type and parselet, matching how the lines package treats sum/total as one.

Decisions worth stating (also in the docs and changeset):

  • Addressing: nearest table above only. An explicit table label is deferred.
  • Non-numeric cells: skipped, not an error, so a stray label or a blank cell does not break an otherwise-numeric column. A column with no numbers at all is a clear error (except count, which is then zero).
  • Money in cells: read, through the same cell reader a lookup uses, and combined as total above combines the same figures on lines (#651). A percentage cell is refused by name. A cell with a unit (5 km) is not read yet and is skipped as text.

Lookups and banded rates (issue #507) read the same nearest table: column "cost" for "food" answers one cell by its row’s label, column "rate" for 45,000 in bands above answers the cell of the band an amount falls in, and 45,000 through bands above is the progressive total across the bands. Their cells are read as numbers, money or percentages (see TableCells.ts), since a price list or a rate schedule is written that way; the column aggregates above are unchanged and still read plain numbers only. column is fused only when a quoted name follows it (TableLookupNormalizerRule.ts), and through bands is a phrase, so neither word becomes a keyword.