🙃
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::cell::CellRef;
|
||||
use crate::grid::Grid;
|
||||
use crate::parser::*;
|
||||
@@ -5,7 +7,8 @@ use crate::tokenizer::Literal;
|
||||
use std::collections::HashSet;
|
||||
use std::fmt;
|
||||
|
||||
#[derive(Debug, PartialEq, Clone)]
|
||||
#[derive(Debug, PartialEq, Clone, Deserialize, Serialize)]
|
||||
#[serde(rename_all = "lowercase")]
|
||||
pub enum Eval {
|
||||
Literal(Literal),
|
||||
CellRef { eval: Box<Eval>, reference: CellRef },
|
||||
|
||||
@@ -11,10 +11,8 @@ use std::{env, io::Error};
|
||||
use tokio::net::{TcpListener, TcpStream};
|
||||
|
||||
use crate::{
|
||||
evaluator::Eval,
|
||||
grid::Grid,
|
||||
messages::{LeadMsg, MsgType},
|
||||
tokenizer::Literal,
|
||||
};
|
||||
|
||||
#[tokio::main]
|
||||
@@ -70,15 +68,11 @@ async fn accept_connection(stream: TcpStream) {
|
||||
|
||||
for update in &updates {
|
||||
if let Ok(cell) = grid.get_cell(*update) {
|
||||
let Eval::Literal(lit) = cell.eval() else {
|
||||
continue;
|
||||
};
|
||||
|
||||
msgs.push(LeadMsg {
|
||||
msg_type: MsgType::Set,
|
||||
cell: Some(*update),
|
||||
raw: Some(cell.raw()),
|
||||
eval: Some(lit),
|
||||
eval: Some(cell.eval()),
|
||||
bulk_msgs: None,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::{cell::CellRef, tokenizer::Literal};
|
||||
use crate::{cell::CellRef, evaluator::Eval};
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
#[serde(rename_all = "lowercase")]
|
||||
@@ -16,6 +16,6 @@ pub struct LeadMsg {
|
||||
pub msg_type: MsgType,
|
||||
pub cell: Option<CellRef>,
|
||||
pub raw: Option<String>,
|
||||
pub eval: Option<Literal>,
|
||||
pub eval: Option<Eval>,
|
||||
pub bulk_msgs: Option<Vec<LeadMsg>>,
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
import Cell from '$lib/components/grid/cell.svelte';
|
||||
import { onDestroy, onMount } from 'svelte';
|
||||
import CellHeader from './cell-header.svelte';
|
||||
import { colToStr, refToStr, type CellT } from './utils';
|
||||
import { colToStr, getEvalLiteral, refToStr, type CellT } from './utils';
|
||||
import clsx from 'clsx';
|
||||
|
||||
let {
|
||||
@@ -44,7 +44,7 @@
|
||||
console.error('Expected cell value for SET msgponse from server.');
|
||||
return;
|
||||
}
|
||||
setCellVal(msg.cell.row, msg.cell.col, msg.eval.value);
|
||||
setCellVal(msg.cell.row, msg.cell.col, getEvalLiteral(msg.eval));
|
||||
break;
|
||||
}
|
||||
case 'bulk': {
|
||||
|
||||
@@ -2,7 +2,7 @@ interface LeadMsg {
|
||||
msg_type: 'set' | 'get' | 'error' | 'bulk';
|
||||
cell?: CellRef;
|
||||
raw?: string;
|
||||
eval?: Literal;
|
||||
eval?: Eval;
|
||||
bulk_msgs?: Array<LeadMsg>;
|
||||
}
|
||||
|
||||
@@ -13,8 +13,17 @@ interface CellRef {
|
||||
|
||||
type LiteralType = 'Number' | 'Boolean' | 'String';
|
||||
type LiteralValue = number | string | boolean;
|
||||
type EvalRange = Array<Eval>;
|
||||
|
||||
interface Literal {
|
||||
type: LiteralType;
|
||||
value: LiteralValue;
|
||||
}
|
||||
|
||||
interface EvalCellRef {
|
||||
eval: Eval;
|
||||
reference: CellRef;
|
||||
}
|
||||
|
||||
// Tagged union
|
||||
type Eval = { literal: Literal } | { cellref: EvalCellRef } | { range: Range } | 'unset';
|
||||
|
||||
@@ -42,3 +42,11 @@ export function colToStr(col: number): string {
|
||||
export function refToStr(row: number, col: number): string {
|
||||
return colToStr(col) + (row + 1).toString();
|
||||
}
|
||||
|
||||
export function getEvalLiteral(value: Eval): LiteralValue {
|
||||
if (value === 'unset') return '';
|
||||
if ('literal' in value) return value.literal.value;
|
||||
if ('cellref' in value) return getEvalLiteral(value.cellref.eval);
|
||||
// if ('range' in value) return 'err';
|
||||
return 'todo!';
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user