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§
- Token
Kind - 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
ioftext.imust be a char boundary (every offsetscanadvances 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] fortext, coloring tokens perscan/color_for. IferrorisSome(start..end), those bytes (clamped to the text and to char boundaries; a span may cover part of a token or several) are rendered inERROR_COLORwith a 2 px underline so the error’s location is visible inline.crate::diagnosticsplaces it: the token at a parse error’s position, or the name a compile error names. - scan
- Scan
textinto a flat sequence ofTokens covering every byte (no gaps), classifying identifiers/numbers/strings/date-literals/operators by simple char class. Never fails — unrecognized characters become single-charOperatortokens so the whole string is always covered.