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