Files
calctext/calcpad-engine/src/pipeline.rs
C. Cassel 0d38bd3108 feat(web): implement complete workspace with themes, tabs, sidebar, and mobile
Transform CalcText from a single-document calculator into a full workspace
application with multi-document support, theming, and responsive mobile experience.

- Theme system: 5 presets (Light, Dark, Matrix, Midnight, Warm) + accent colors
- Document model with localStorage persistence and auto-save
- Tab bar with keyboard shortcuts (Ctrl+N/W/Tab/1-9), rename, close
- Sidebar with search, recent, favorites, folders, templates, drag-and-drop
- 5 templates: Budget, Invoice, Unit Converter, Trip Planner, Loan Calculator
- Status bar with cursor position, engine status, dedication to Igor Cassel
- Results panel: type-specific colors, click-to-copy, error hints
- Format toolbar: H, B, I, //, color labels with live preview toggle
- Syntax highlighting using theme CSS variables
- Error hover tooltips
- Mobile: bottom results tray, sidebar drawer, touch targets, safe areas
- Docker multi-stage build (Rust WASM + Vite + Nginx)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-18 09:12:05 -04:00

48 lines
1.6 KiB
Rust

use crate::context::EvalContext;
use crate::interpreter::evaluate;
use crate::lexer::tokenize;
use crate::parser::parse;
use crate::span::Span;
use crate::types::CalcResult;
use crate::variables::aggregators;
/// Evaluate a single line of input and return the result.
pub fn eval_line(input: &str, ctx: &mut EvalContext) -> CalcResult {
let trimmed = input.trim();
if trimmed.is_empty() {
return CalcResult::empty(Span::new(0, 0));
}
// Detect headings (# Title) and aggregator keywords (sum, total, etc.)
// before tokenizing — the lexer misinterprets `#` as a line reference prefix.
if aggregators::is_heading(trimmed) || aggregators::detect_aggregator(trimmed).is_some() {
return CalcResult::non_calculable(Span::new(0, trimmed.len()));
}
let tokens = tokenize(trimmed);
// Check for text-only or comment-only lines
let has_expr = tokens.iter().any(|t| {
!matches!(
t.kind,
crate::token::TokenKind::Text(_)
| crate::token::TokenKind::Comment(_)
| crate::token::TokenKind::Eof
)
});
if !has_expr {
return CalcResult::non_calculable(Span::new(0, trimmed.len()));
}
match parse(tokens) {
Ok(expr) => evaluate(&expr, ctx),
Err(e) => CalcResult::error(&e.message, e.span),
}
}
/// Evaluate multiple lines of input, sharing context across lines.
/// Variable assignments on earlier lines are visible to later lines.
pub fn eval_sheet(lines: &[&str], ctx: &mut EvalContext) -> Vec<CalcResult> {
lines.iter().map(|line| eval_line(line, ctx)).collect()
}