Skip to content

Add unary function parsing and custom operator support#3

Open
psaegert wants to merge 42 commits into
lnogueir:masterfrom
psaegert:master
Open

Add unary function parsing and custom operator support#3
psaegert wants to merge 42 commits into
lnogueir:masterfrom
psaegert:master

Conversation

@psaegert

Copy link
Copy Markdown

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:

  • Added support for custom operators/functions (e.g., #pi, #add(a,b), #clamp(x,a,b)) with arity detection and validation in infixToPostfix.js, including robust tokenization and validation logic for both standard and custom functions. [1] [2] [3]
  • Improved error messaging and validation to inform users about supported functions and operators, and updated the error display to reflect new syntax options.

Expression tree construction and rendering:

  • Refactored tree.js to support nodes with arbitrary arity (not just binary), including changes to the Node class, tree construction (constructTree), coordinate assignment, and drawing logic. This enables correct visualization of custom functions/operators with 0–3 arguments. [1] [2] [3]
  • Updated the tree drawing code to dynamically size and position nodes and edges for n-ary trees, ensuring clarity for complex expressions. [1] [2]

UI and documentation updates:

  • Expanded the list of sample expressions in canvas.js and updated the input placeholder in index.html to showcase new syntax. [1] [2]
  • Updated the README.md with a detailed list of supported syntax and example expressions, providing clear guidance for users.

Other improvements:

  • Removed forced lowercasing of input expressions to allow for case-sensitive custom operators/functions.

These changes collectively make the expression tree generator more flexible, powerful, and user-friendly, supporting a broader range of mathematical expressions and custom functions.

Copilot AI and others added 9 commits April 21, 2026 08:39
…ary-functions

[WIP] Extend expression tree generator for unary functions support
Add `#`-prefixed custom operators with inferred arity (0–3) to parser and tree renderer
Copilot AI review requested due to automatic review settings April 21, 2026 09:33

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread infixToPostfix.js Outdated
var tokens = []
for (var i = 0; i < expression.length; i++) {
var current = expression[i]
if (current === ' ') {

Copilot AI Apr 21, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
if (current === ' ') {
if (/\s/.test(current)) {

Copilot uses AI. Check for mistakes.
Copilot AI and others added 18 commits April 21, 2026 09:41
…t-enter-animation

[WIP] Add UX improvements to expression tree generator
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
Drop mathjs validation path, center main controls, and add PNG/SVG export popover
Surface parser errors between input and canvas
…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>
psaegert and others added 15 commits April 21, 2026 16:10
…vas-resolution

Require `#\name` for LaTeX symbols, render canvas at device pixel ratio, and keep mobile keyboard from covering the tree
Fix mobile controls/tree overlap and italic glyph clipping in nodes
…-expression

Parser: numeric literals & `"..."`/`$...$` leaves; copy-to-clipboard for input and image
…-nodes

Support `"..."` and `$...$` literals as operator nodes
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants