From 93f665ba8fb9a5bb157f1ca5a9c459322c19119f Mon Sep 17 00:00:00 2001 From: Joeri Exelmans Date: Sun, 18 May 2025 11:10:25 +0200 Subject: [PATCH] rename Editor -> ExprBlock --- src/App.tsx | 12 ++++++------ src/CallBlock.tsx | 16 ++++++++-------- src/{Editor.css => ExprBlock.css} | 0 src/{Editor.tsx => ExprBlock.tsx} | 29 +++++++++++++++-------------- src/InputBlock.tsx | 2 +- src/LambdaBlock.tsx | 16 +++++++--------- src/LetInBlock.tsx | 14 +++++++------- src/configurations.ts | 12 ++++++------ src/eval.ts | 10 +++++----- 9 files changed, 55 insertions(+), 56 deletions(-) rename src/{Editor.css => ExprBlock.css} (100%) rename src/{Editor.tsx => ExprBlock.tsx} (90%) diff --git a/src/App.tsx b/src/App.tsx index 19ddda8..98b215a 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -1,7 +1,7 @@ import { useEffect, useState } from 'react'; import './App.css'; import { GlobalContext } from './GlobalContext'; -import { Editor, type EditorState } from './Editor'; +import { ExprBlock, type ExprBlockState } from './ExprBlock'; import { extendedEnv } from './EnvContext'; import { biggerExample, initialEditorState, lambda2Params, nonEmptyEditorState, tripleFunctionCallEditorState } from "./configurations"; import { evalEditorBlock } from "./eval"; @@ -14,7 +14,7 @@ const commands: [string, string[], string][] = [ ["lambda" , ['a' ], "λx: …" ], ]; -const examples: [string, EditorState][] = [ +const examples: [string, ExprBlockState][] = [ ["empty editor", initialEditorState], ["push to list", nonEmptyEditorState], ["function w/ 4 params", tripleFunctionCallEditorState], @@ -23,8 +23,8 @@ const examples: [string, EditorState][] = [ ]; type AppState = { - history: EditorState[], - future: EditorState[], + history: ExprBlockState[], + future: ExprBlockState[], } const defaultState = { @@ -63,7 +63,7 @@ export function App() { setAppState(_ => defaultState); } - const pushHistory = (callback: (p: EditorState) => EditorState) => { + const pushHistory = (callback: (p: ExprBlockState) => ExprBlockState) => { setAppState(({history}) => { const newState = callback(history.at(-1)!); return { @@ -162,7 +162,7 @@ export function App() {
- {}} diff --git a/src/CallBlock.tsx b/src/CallBlock.tsx index bda374a..6af73d2 100644 --- a/src/CallBlock.tsx +++ b/src/CallBlock.tsx @@ -1,6 +1,6 @@ import { useContext } from "react"; -import { Editor, type EditorState, type SetStateFn, type State2Props } from "./Editor"; +import { ExprBlock, type ExprBlockState, type SetStateFn, type State2Props } from "./ExprBlock"; import { EnvContext } from "./EnvContext"; import { evalCallBlock2, evalEditorBlock, scoreResolved, type ResolvedType } from "./eval"; import { GlobalContext } from "./GlobalContext"; @@ -10,14 +10,14 @@ import "./CallBlock.css"; export interface CallBlockState { kind: "call"; - fn: EditorState; - input: EditorState; + fn: ExprBlockState; + input: ExprBlockState; } interface CallBlockProps< - FnState=EditorState, - InputState=EditorState, -> extends State2Props {} + FnState=ExprBlockState, + InputState=ExprBlockState, +> extends State2Props {} function nestedFnProperties({state, setState, suggestionPriority}: CallBlockProps, env) { const setFn = (callback: SetStateFn) => { @@ -91,7 +91,7 @@ function FunctionHeader(props) { // end of recursion - draw function name return  𝑓𝑛  - + ; } } @@ -109,7 +109,7 @@ function InputParams({ depth, errorDepth, ...rest }) { errorDepth={errorDepth} />} {/* Our own input param */} - ; diff --git a/src/Editor.css b/src/ExprBlock.css similarity index 100% rename from src/Editor.css rename to src/ExprBlock.css diff --git a/src/Editor.tsx b/src/ExprBlock.tsx similarity index 90% rename from src/Editor.tsx rename to src/ExprBlock.tsx index b933d3d..83fc013 100644 --- a/src/Editor.tsx +++ b/src/ExprBlock.tsx @@ -3,24 +3,25 @@ import { useContext, useEffect, useRef, useState } from "react"; import { getSymbol, getType, symbolFunction } from "dope2"; import { CallBlock, type CallBlockState } from "./CallBlock"; -import { InputBlock, type InputBlockState, type SuggestionType } from "./InputBlock"; -import { Type } from "./Type"; -import { evalEditorBlock, type ResolvedType } from "./eval"; -import { GlobalContext } from "./GlobalContext"; -import "./Editor.css"; import { EnvContext } from "./EnvContext"; +import { GlobalContext } from "./GlobalContext"; +import { InputBlock, type InputBlockState } from "./InputBlock"; import { LambdaBlock, type LambdaBlockState } from "./LambdaBlock"; import { LetInBlock, type LetInBlockState } from "./LetInBlock"; +import { Type } from "./Type"; import { initialEditorState } from "./configurations"; +import { evalEditorBlock, type ResolvedType } from "./eval"; import { focusNextElement, focusPrevElement } from "./util/dom_trickery"; -export type EditorState = +import "./ExprBlock.css"; + +export type ExprBlockState = InputBlockState | CallBlockState | LetInBlockState | LambdaBlockState; -export type SetStateFn = (state: InType) => OutType; +export type SetStateFn = (state: InType) => OutType; export interface State2Props { state: InType; @@ -28,7 +29,7 @@ export interface State2Props { suggestionPriority: (suggestion: ResolvedType) => number; } -interface EditorProps extends State2Props { +interface ExprBlockProps extends State2Props { onCancel: () => void; } @@ -46,7 +47,7 @@ function getShortCommands(type) { return 'Tab|.'; } -function removeFocus(state: EditorState): EditorState { +function removeFocus(state: ExprBlockState): ExprBlockState { if (state.kind === "input") { return {...state, focus: false}; } @@ -59,7 +60,7 @@ function removeFocus(state: EditorState): EditorState { return state; } -export function Editor({state, setState, onCancel, suggestionPriority}: EditorProps) { +export function ExprBlock({state, setState, onCancel, suggestionPriority}: ExprBlockProps) { const env = useContext(EnvContext); const [needCommand, setNeedCommand] = useState(false); const commandInputRef = useRef(null); @@ -158,26 +159,26 @@ export function Editor({state, setState, onCancel, suggestionPriority}: EditorPr case "input": return EditorState)=>void} + setState={setState as (callback:(p:InputBlockState)=>ExprBlockState)=>void} suggestionPriority={suggestionPriority} onCancel={onCancel} />; case "call": return EditorState)=>void} + setState={setState as (callback:(p:CallBlockState)=>ExprBlockState)=>void} suggestionPriority={suggestionPriority} />; case "let": return EditorState)=>void} + setState={setState as (callback:(p:LetInBlockState)=>ExprBlockState)=>void} suggestionPriority={suggestionPriority} />; case "lambda": return EditorState)=>void} + setState={setState as (callback:(p:LambdaBlockState)=>ExprBlockState)=>void} suggestionPriority={suggestionPriority} />; } diff --git a/src/InputBlock.tsx b/src/InputBlock.tsx index 4e60747..3e82212 100644 --- a/src/InputBlock.tsx +++ b/src/InputBlock.tsx @@ -6,7 +6,7 @@ import { EnvContext } from "./EnvContext"; import type { Dynamic, ResolvedType } from "./eval"; import "./InputBlock.css"; import { Type } from "./Type"; -import type { State2Props } from "./Editor"; +import type { State2Props } from "./ExprBlock"; import { autoInputWidth, focusNextElement, focusPrevElement, setRightMostCaretPosition } from "./util/dom_trickery"; import { attemptParseLiteral } from "./eval"; diff --git a/src/LambdaBlock.tsx b/src/LambdaBlock.tsx index f3c4603..1db6261 100644 --- a/src/LambdaBlock.tsx +++ b/src/LambdaBlock.tsx @@ -2,25 +2,23 @@ import { useContext, useEffect, useRef } from "react"; import { growEnv } from "dope2"; -import { Editor, type EditorState, type State2Props } from "./Editor"; +import { ExprBlock, type ExprBlockState, type State2Props } from "./ExprBlock"; import { EnvContext } from "./EnvContext"; -import { evalEditorBlock, getUnusedTypeVar, type ResolvedType } from "./eval"; +import { getUnusedTypeVar } from "./eval"; import { autoInputWidth } from "./util/dom_trickery"; import "./LambdaBlock.css"; - - export interface LambdaBlockState { kind: "lambda"; paramName: string; - expr: EditorState; + expr: ExprBlockState; } interface LambdaBlockProps< - FnState=EditorState, - InputState=EditorState, -> extends State2Props {} + FnState=ExprBlockState, + InputState=ExprBlockState, +> extends State2Props {} export function LambdaBlock({state, setState, suggestionPriority}: LambdaBlockProps) { @@ -73,7 +71,7 @@ export function LambdaBlock({state, setState, suggestionPriority}: LambdaBlockPr  
- setState(state => state.expr)} diff --git a/src/LetInBlock.tsx b/src/LetInBlock.tsx index e5acf90..fb02080 100644 --- a/src/LetInBlock.tsx +++ b/src/LetInBlock.tsx @@ -1,9 +1,9 @@ import { useContext, useEffect, useRef } from "react"; -import { Editor, type EditorState } from "./Editor"; +import { ExprBlock, type ExprBlockState } from "./ExprBlock"; import { EnvContext } from "./EnvContext"; import { evalEditorBlock, makeInnerEnv, scoreResolved, type ResolvedType } from "./eval"; -import { type State2Props } from "./Editor"; +import { type State2Props } from "./ExprBlock"; import { autoInputWidth } from "./util/dom_trickery"; import { GlobalContext } from "./GlobalContext"; @@ -12,11 +12,11 @@ import "./LetInBlock.css"; export interface LetInBlockState { kind: "let"; name: string; - value: EditorState; - inner: EditorState; + value: ExprBlockState; + inner: ExprBlockState; } -interface LetInBlockProps extends State2Props {} +interface LetInBlockProps extends State2Props {} export function LetInBlock(props: LetInBlockProps) { return @@ -67,7 +67,7 @@ function DeclColumns({state: {name, value, inner}, setState, suggestionPriority}  =  - - ({ // the value of every block is either known (Dynamic), an error, or unknown export type ResolvedType = Dynamic | DeepError | Unknown; -export const evalEditorBlock = (s: EditorState, env): ResolvedType => { +export const evalEditorBlock = (s: ExprBlockState, env): ResolvedType => { if (s.kind === "input") { return evalInputBlock(s.text, s.value, env); } @@ -157,13 +157,13 @@ export function evalCallBlock2(fnResolved: ResolvedType, inputResolved: Resolved } } -export function evalCallBlock(fn: EditorState, input: EditorState, env): ResolvedType { +export function evalCallBlock(fn: ExprBlockState, input: ExprBlockState, env): ResolvedType { const fnResolved = evalEditorBlock(fn, env); const inputResolved = evalEditorBlock(input, env); return evalCallBlock2(fnResolved, inputResolved, env); } -export function evalLetInBlock(value: EditorState, name: string, inner: EditorState, env): ResolvedType { +export function evalLetInBlock(value: ExprBlockState, name: string, inner: ExprBlockState, env): ResolvedType { const valueResolved = evalEditorBlock(value, env); // console.log('eval', name, '...', valueResolved.kind, valueResolved.e); // const innerEnv = growEnv(env)(name)(valueResolved); @@ -183,7 +183,7 @@ export function getUnusedTypeVar(env) { return TYPE_VARS[getUnusedTypeVarIdx(env)]; } -export function evalLambdaBlock(paramName: string, expr: EditorState, env): ResolvedType { +export function evalLambdaBlock(paramName: string, expr: ExprBlockState, env): ResolvedType { const paramType = getUnusedTypeVar(env); // static env: we only know the name and the type const staticInnerEnv = growEnv(env)(paramName)({