Add unary function parsing and custom operator support#3
Conversation
Agent-Logs-Url: https://github.com/psaegert/expression-tree-gen/sessions/1b9ad718-258f-4142-ba5d-146b7d889d15 Co-authored-by: psaegert <36567814+psaegert@users.noreply.github.com>
Agent-Logs-Url: https://github.com/psaegert/expression-tree-gen/sessions/1b9ad718-258f-4142-ba5d-146b7d889d15 Co-authored-by: psaegert <36567814+psaegert@users.noreply.github.com>
…ary-functions [WIP] Extend expression tree generator for unary functions support
Agent-Logs-Url: https://github.com/psaegert/expression-tree-gen/sessions/b0a59eb7-ed41-437f-beb7-60d427c204bd Co-authored-by: psaegert <36567814+psaegert@users.noreply.github.com>
Agent-Logs-Url: https://github.com/psaegert/expression-tree-gen/sessions/b0a59eb7-ed41-437f-beb7-60d427c204bd Co-authored-by: psaegert <36567814+psaegert@users.noreply.github.com>
Agent-Logs-Url: https://github.com/psaegert/expression-tree-gen/sessions/9641a83b-5b89-4e77-8331-bbb358b7a92e Co-authored-by: psaegert <36567814+psaegert@users.noreply.github.com>
Add `#`-prefixed custom operators with inferred arity (0–3) to parser and tree renderer
There was a problem hiding this comment.
Pull request overview
Expands the expression parser and tree renderer to support unary functions and custom #name(...) operators (variable arity), enabling visualization of n-ary expression trees in the existing canvas UI.
Changes:
- Added tokenization + validation for custom
#...operators/functions (arity inferred from commas, max 3) and integrated them into infix→postfix conversion. - Refactored tree construction/rendering from binary-only nodes to n-ary nodes with dynamic layout/drawing.
- Updated UI samples/placeholder and README to document and demonstrate the new syntax.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
infixToPostfix.js |
Adds tokenizer, custom-function validation, and shunting-yard support for unary/custom function tokens. |
tree.js |
Updates Node model and algorithms (construction, layout, drawing) to support arbitrary arity. |
canvas.js |
Removes forced lowercasing and adds sample expressions + updated validation help text. |
index.html |
Updates input placeholder to show new syntax. |
README.md |
Documents supported syntax and provides examples for unary/custom operators. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| var tokens = [] | ||
| for (var i = 0; i < expression.length; i++) { | ||
| var current = expression[i] | ||
| if (current === ' ') { |
There was a problem hiding this comment.
tokenize() only skips literal spaces (current === ' '), but isValidExpression allows all whitespace via ALLOWED_CHARACTERS_REGEX (\s). As a result, tabs/newlines can pass the allowed-characters check but still fail tokenization. Consider skipping all whitespace in tokenize (e.g., /\s/), or tightening ALLOWED_CHARACTERS_REGEX to only allow spaces so validation is consistent.
| if (current === ' ') { | |
| if (/\s/.test(current)) { |
Agent-Logs-Url: https://github.com/psaegert/expression-tree-gen/sessions/9d244446-6338-4b90-b8b0-d1dc770c4140 Co-authored-by: psaegert <36567814+psaegert@users.noreply.github.com>
…t-enter-animation [WIP] Add UX improvements to expression tree generator
…ering Agent-Logs-Url: https://github.com/psaegert/expression-tree-gen/sessions/e008f843-b6be-49f2-867a-0a32bd59bc0a Co-authored-by: psaegert <36567814+psaegert@users.noreply.github.com>
Agent-Logs-Url: https://github.com/psaegert/expression-tree-gen/sessions/e008f843-b6be-49f2-867a-0a32bd59bc0a Co-authored-by: psaegert <36567814+psaegert@users.noreply.github.com>
Overhaul UI to minimal real-time expression tree visualizer with dark mode and synchronous rendering
Agent-Logs-Url: https://github.com/psaegert/expression-tree-gen/sessions/83c7ae30-dbfc-4592-97f7-63dc5bddc7f3 Co-authored-by: psaegert <36567814+psaegert@users.noreply.github.com>
Agent-Logs-Url: https://github.com/psaegert/expression-tree-gen/sessions/83c7ae30-dbfc-4592-97f7-63dc5bddc7f3 Co-authored-by: psaegert <36567814+psaegert@users.noreply.github.com>
Drop mathjs validation path, center main controls, and add PNG/SVG export popover
Agent-Logs-Url: https://github.com/psaegert/expression-tree-gen/sessions/b76f2e13-c151-4ff7-b4e5-11c4f21e04aa Co-authored-by: psaegert <36567814+psaegert@users.noreply.github.com>
Agent-Logs-Url: https://github.com/psaegert/expression-tree-gen/sessions/b76f2e13-c151-4ff7-b4e5-11c4f21e04aa Co-authored-by: psaegert <36567814+psaegert@users.noreply.github.com>
Surface parser errors between input and canvas
Agent-Logs-Url: https://github.com/psaegert/expression-tree-gen/sessions/ee4d85e1-eab5-46a5-8afd-e949b3a8f90a Co-authored-by: psaegert <36567814+psaegert@users.noreply.github.com>
Agent-Logs-Url: https://github.com/psaegert/expression-tree-gen/sessions/ee4d85e1-eab5-46a5-8afd-e949b3a8f90a Co-authored-by: psaegert <36567814+psaegert@users.noreply.github.com>
Render node labels as LaTeX via KaTeX
…rols to top on mobile Agent-Logs-Url: https://github.com/psaegert/expression-tree-gen/sessions/48759929-9b18-4e12-aafe-9360db561da6 Co-authored-by: psaegert <36567814+psaegert@users.noreply.github.com>
…vas-resolution Require `#\name` for LaTeX symbols, render canvas at device pixel ratio, and keep mobile keyboard from covering the tree
Agent-Logs-Url: https://github.com/psaegert/expression-tree-gen/sessions/2ae42d60-06c7-45b9-af73-f09300c717e5 Co-authored-by: psaegert <36567814+psaegert@users.noreply.github.com>
Fix mobile controls/tree overlap and italic glyph clipping in nodes
Agent-Logs-Url: https://github.com/psaegert/expression-tree-gen/sessions/5b75eb54-6f1c-48ba-9bf7-aaf9694c9e14 Co-authored-by: psaegert <36567814+psaegert@users.noreply.github.com>
…mand deprecation Agent-Logs-Url: https://github.com/psaegert/expression-tree-gen/sessions/5b75eb54-6f1c-48ba-9bf7-aaf9694c9e14 Co-authored-by: psaegert <36567814+psaegert@users.noreply.github.com>
…-expression Parser: numeric literals & `"..."`/`$...$` leaves; copy-to-clipboard for input and image
Agent-Logs-Url: https://github.com/psaegert/expression-tree-gen/sessions/6a07f6e3-f15c-48fd-9a87-599e008970de Co-authored-by: psaegert <36567814+psaegert@users.noreply.github.com>
Agent-Logs-Url: https://github.com/psaegert/expression-tree-gen/sessions/6a07f6e3-f15c-48fd-9a87-599e008970de Co-authored-by: psaegert <36567814+psaegert@users.noreply.github.com>
…-nodes Support `"..."` and `$...$` literals as operator nodes
Agent-Logs-Url: https://github.com/psaegert/expression-tree-gen/sessions/c9e2989e-e474-4379-be4a-3c23f5510fce Co-authored-by: psaegert <36567814+psaegert@users.noreply.github.com>
Agent-Logs-Url: https://github.com/psaegert/expression-tree-gen/sessions/c9e2989e-e474-4379-be4a-3c23f5510fce Co-authored-by: psaegert <36567814+psaegert@users.noreply.github.com>
Agent-Logs-Url: https://github.com/psaegert/expression-tree-gen/sessions/c9e2989e-e474-4379-be4a-3c23f5510fce Co-authored-by: psaegert <36567814+psaegert@users.noreply.github.com>
Crop PNG/SVG exports to tree bounds with uniform padding
- Rewrite README to reflect the current app (KaTeX labels, numbers, text/
LaTeX literals, PNG/SVG export with scale + copy, live render, dark mode).
- Point primary links to this fork's site/repo; credit Lucas Nogueira's
original (lnogueir/expression-tree-gen) and link it.
- Fix dead Georgia Tech shunting-yard credit link -> runestone (pythonds3);
add a no-license attribution note.
- Footer now links to BOTH this fork (GitHub icon) and the original
("Fork of lnogueir/expression-tree-gen" text link); wrap/width guard so
the floating bar does not overflow on narrow screens.
- Add light/dark screenshots (docs/) and embed them near the top.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Asked copilot to add support for unary and custom operators. The following is auto-generated. Still needs human review.
~ psaegert
This pull request significantly expands the supported syntax of the expression tree generator to include custom operators/functions (with variable arity), improves the parsing and validation of expressions, and refactors the tree construction and rendering logic to handle arbitrary arity nodes. The UI and documentation are also updated to reflect these new capabilities.
Major parser and validation enhancements:
#pi,#add(a,b),#clamp(x,a,b)) with arity detection and validation ininfixToPostfix.js, including robust tokenization and validation logic for both standard and custom functions. [1] [2] [3]Expression tree construction and rendering:
tree.jsto support nodes with arbitrary arity (not just binary), including changes to theNodeclass, tree construction (constructTree), coordinate assignment, and drawing logic. This enables correct visualization of custom functions/operators with 0–3 arguments. [1] [2] [3]UI and documentation updates:
canvas.jsand updated the input placeholder inindex.htmlto showcase new syntax. [1] [2]README.mdwith a detailed list of supported syntax and example expressions, providing clear guidance for users.Other improvements:
These changes collectively make the expression tree generator more flexible, powerful, and user-friendly, supporting a broader range of mathematical expressions and custom functions.