Skip to main content

Module formula_highlight

Module formula_highlight 

Source
Expand description

Pure syntax highlighting for the formula editor: &str -> LayoutJob.

A small independent char-class scanner (identifiers / numbers / strings / date literals / operators), good enough for visually useful highlighting — it does not need to match core_model::parser’s exact grammar. Kept free of any egui::Ui access so it’s unit-testable without a window.

Structs§

Token
One scanned token: its kind and byte range in the source text.

Enums§

TokenKind
The lexical class of one highlighted token.

Constants§

ERROR_COLOR
The color of formula error text and of the error-position underline. The palette has no red, so an error is marked by the underline, not by hue.
ERROR_UNDERLINE 🔒
The error-position underline: thicker than a text underline so it reads.
FUNCTIONS 🔒
A known scalar/aggregation function name, highlighted distinctly from a plain measure/category identifier.

Functions§

char_at 🔒
The character at byte offset i of text. i must be a char boundary (every offset scan advances to is one, by construction).
color_for 🔒
Token colors, within the NeXTSTEP grayscale palette (theme.rs): names, functions and numbers in black on the white field, operators and literals in dark gray (7.5:1 on white).
highlight_formula
Build a highlighted [LayoutJob] for text, coloring tokens per scan/color_for. If error is Some(start..end), those bytes (clamped to the text and to char boundaries; a span may cover part of a token or several) are rendered in ERROR_COLOR with a 2 px underline so the error’s location is visible inline. crate::diagnostics places it: the token at a parse error’s position, or the name a compile error names.
scan
Scan text into a flat sequence of Tokens covering every byte (no gaps), classifying identifiers/numbers/strings/date-literals/operators by simple char class. Never fails — unrecognized characters become single-char Operator tokens so the whole string is always covered.