--- epic: 7 story: 7.3 title: "Syntax Highlighting" status: draft --- ## Epic 7 — macOS App (Swift/SwiftUI) **Goal:** A beautiful, native macOS app that feels like it belongs on the platform. ### Story 7.3: Syntax Highlighting As a **macOS user**, I want syntax highlighting in the editor that colors numbers, operators, units, variables, comments, and errors, So that I can visually parse my calculations quickly and spot mistakes at a glance. **Acceptance Criteria:** **Given** the user types `monthly_rent = $1250 // housing cost` **When** the text is rendered in the editor **Then** `monthly_rent` is colored as a variable, `=` as an operator, `$1250` as a number/currency, and `// housing cost` as a comment **And** each category has a distinct color **Given** the user types an invalid expression that produces an error **When** the text is rendered **Then** the erroneous portion is highlighted with an error color (e.g., red underline or red text) **Given** the system appearance is set to Light mode **When** the editor renders syntax highlighting **Then** colors are appropriate for a light background (sufficient contrast, readable) **Given** the system appearance is set to Dark mode **When** the editor renders syntax highlighting **Then** colors are appropriate for a dark background (sufficient contrast, readable) **Given** the user types or edits text **When** characters are inserted or deleted **Then** syntax highlighting updates incrementally without visible flicker or lag **Given** the editor uses a custom `NSTextStorage` subclass **When** the engine tokenizer produces token spans for a line **Then** the `NSTextStorage` applies the corresponding `NSAttributedString` attributes to match those spans