From 4a3e92b910ffb0f24d1e754753d50152ffb7c1c6 Mon Sep 17 00:00:00 2001 From: garrettmills Date: Sat, 9 Apr 2022 17:48:41 -0500 Subject: [PATCH] Implement adding expression and var decls --- src/components/Statement.vue | 5 +- src/pages/Editor.vue | 112 +++++++++++++++++++++++++++++---- src/pages/ExpressionEditor.vue | 78 +++++++++++++++++++++++ src/pages/Scratch.vue | 2 - src/pages/VarDeclEditor.vue | 94 +++++++++++++++++++++++++++ src/support/page.ts | 5 ++ src/support/parse.ts | 14 +++++ vite.config.ts | 3 + 8 files changed, 296 insertions(+), 17 deletions(-) create mode 100644 src/pages/ExpressionEditor.vue create mode 100644 src/pages/VarDeclEditor.vue diff --git a/src/components/Statement.vue b/src/components/Statement.vue index 8712aab..ce75d19 100644 --- a/src/components/Statement.vue +++ b/src/components/Statement.vue @@ -6,12 +6,11 @@ import Katex from './Katex.vue' const props = defineProps<{ statement: MathStatement, - evaluation: EvaluationResult, - renderVersion: number, + evaluation?: EvaluationResult, }>() const getValueStatement = (): Maybe => { - const value = props.evaluation.statements[props.statement.id] + const value = props.evaluation?.statements?.[props.statement.id] if ( value ) { return MathStatement.temp(String(value)) } diff --git a/src/pages/Editor.vue b/src/pages/Editor.vue index 3efbf92..3febc5e 100644 --- a/src/pages/Editor.vue +++ b/src/pages/Editor.vue @@ -1,3 +1,60 @@ + + - - diff --git a/src/pages/ExpressionEditor.vue b/src/pages/ExpressionEditor.vue new file mode 100644 index 0000000..6fffc12 --- /dev/null +++ b/src/pages/ExpressionEditor.vue @@ -0,0 +1,78 @@ + + + diff --git a/src/pages/Scratch.vue b/src/pages/Scratch.vue index 08c4cba..6e54ad8 100644 --- a/src/pages/Scratch.vue +++ b/src/pages/Scratch.vue @@ -10,7 +10,6 @@ const stmt1Id = page.addRaw('x = y+3/4') const stmt2Id = page.addRaw('y = 9') const evaluation = page.evaluate() - let renderVersion = 0 const stmt = page.getStatement(stmt1Id) console.log({page, stmt1Id}) @@ -69,6 +68,5 @@ v-on:edit="() => stmt ? editStatement(stmt) : {}" :statement="stmt" :evaluation="evaluation" - :render-version="renderVersion" /> diff --git a/src/pages/VarDeclEditor.vue b/src/pages/VarDeclEditor.vue new file mode 100644 index 0000000..a8f545f --- /dev/null +++ b/src/pages/VarDeclEditor.vue @@ -0,0 +1,94 @@ + + + diff --git a/src/support/page.ts b/src/support/page.ts index 3e77930..b4e60fa 100644 --- a/src/support/page.ts +++ b/src/support/page.ts @@ -16,6 +16,11 @@ export class MathPage { public readonly id: string, ) {} + /** Get all defined statements. */ + getStatements(): MathStatement[] { + return Object.values(this.statements) + } + /** Get a statement by ID if it exists. */ getStatement(id: StatementID): Maybe { return this.statements[id] diff --git a/src/support/parse.ts b/src/support/parse.ts index 4245dc2..f5d96da 100644 --- a/src/support/parse.ts +++ b/src/support/parse.ts @@ -324,4 +324,18 @@ export class MathStatement { uses(): math.SymbolNode[] { return (new RValSymbolWalk()).walk(this.parse()) } + + /** Returns true if the definition is correctly non-recursive. */ + isNotRecursive(): boolean { + const uses = this.uses() + const defines = this.defines() + + for ( const define of defines ) { + if ( uses.some(x => x.name === define.name) ) { + return false + } + } + + return true + } } diff --git a/vite.config.ts b/vite.config.ts index 3bc00d8..96e978b 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -9,6 +9,9 @@ export default defineConfig({ '/api': { target: 'http://localhost:8000/', }, + '/auth': { + target: 'http://localhost:8000/', + }, }, }, plugins: [