Skip to content

Turn /demo/ into RegexSolver Notebook - #1

Merged
alexvbrdn merged 23 commits into
mainfrom
notebook-demo
Nov 29, 2026
Merged

alexvbrdn merged 23 commits into
mainfrom
notebook-demo

Conversation

@alexvbrdn

Copy link
Copy Markdown
Member

/demo/ becomes RegexSolver Notebook: a notebook of regex terms, one per line, run in the browser by the regexsolver crate compiled to WebAssembly. It replaces the former one-operation demo; old ?op=…&a=… links still open, as a notebook.

alexvbrdn and others added 23 commits November 23, 2026 19:33
Each line names a term, made from a pattern or from the lines above it
(`others = email.difference(&gmail)`). Selecting a line opens an inspector:
Facts, Strings, Match, Compare and Convert. The notebook is shown as a Rust
program that follows the open tab, with its Cargo.toml.

The engine owns the grammar: wasm/src/notebook.rs parses the notebook (real
Rust too), runs it, writes each line's Rust statement, and lists its
operations for autocomplete. Every request carries the whole notebook; line
terms are cached by a key hashed from the line and its dependencies, so a
restarted worker only rebuilds. Lines run as the visitor types, an analysis
runs when its tab first shows it, Convert on its button.

The address bar carries the notebook (?nb=), and former ?op=…&a=… links open
as a notebook. The home page keeps the one-operation demo, with a link that
opens its inputs in the notebook.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The notebook fills the window under the bar: the editor (wrapping long lines)
on the left, the inspector on the right with Rust as its last pane. Stacked
on a phone. The title, intro and example picker are gone; the demo opens on
one notebook. Page, Header and Footer take `wide` for it.

Patterns are written between slashes (`\/` for a slash) and arguments are
plain: `others.intersection(tiny)`, `a.union(b, c)`, `a.repeat(2, 3)`,
`repeat(2)`, `repeat(2, _)`. The Rust export is unchanged.

The selected line follows the cursor once the engine has named the line, and
a line's chip stays inside its line when it wraps.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A line can be an expression without a name; it is named `_N` after its line
number, which other lines and the Rust program use.

The editor suggests the engine's operations after `term.` and the names of
the lines above elsewhere, never inside a pattern or a comment.

Inside a pattern, classes, escapes, quantifiers and alternation are told
apart, groups are coloured by depth, an unmatched `)` is marked, and the
parenthesis paired with the cursor's is shown. A pattern's syntax error is
underlined where it is (regex-syntax gives the span, mapped back through
`\/`), with its message on hover.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A `#` outside a pattern starts a comment, on its own line or after a term; a
`#` inside `/…/` is the pattern's. `//` is now an empty pattern.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A line ends with a tick once run, a spinner while a run or one of its
analyses is under way, an empty ring when its text, or a line it reads,
changed since the last run, and a cross on an error (the message on hover).
Blank and comment lines get none.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Automata of up to 65,536 states now build (under 0.4 s in the browser's
engine); 20,000 refused them.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The inspector is one plain-text column with no tabs: the line's summary
(how many strings, how long; no state count), Test with a tick or cross per
string, Strings within a length range and a character class, Compare with
the strings only in this line, in both and only in the other, and the
conversion, whose model options read "a pattern with model (name)". The
divider beside it resizes it. The engine's compare gives the strings in
both; its strings take minLength, maxLength and charset.

VIEW IN RUST and the automaton's ACTUAL SIZE open dialogs (ui/Dialog.tsx,
on the native <dialog>). CHEATSHEET, in the editor pane, opens the
notebook's syntax, the engine's operations, the pattern syntax and what is
refused. The demo has no footer.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Each theme sets color-scheme, so native controls (a select's list,
scrollbars) follow it. The notebook's inline selects get a list in the
site's look, with padded rows and the chosen option in ink A, where
customizable select (appearance: base-select) is supported; elsewhere the
list stays native.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Dialogs sit 8% down the window instead of centred, so one that grows (a
graph laying out, the code) keeps its title in place.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A count too large to give exactly reads "a lot of strings", an infinite one
"an infinite number of strings".

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Lines can now be checks: `assert [!]expr.check(…)` with the crate's
equivalent, subset, is_empty, is_total, is_finite and is_match. A failing
check shows the string that breaks it beside its line, and VIEW CODE
writes each one as an assert!.

The notebook opens on an example that asks whether swapping [0-9] for \d
changed a regex, and EXAMPLES lists six more. TRY offers lines built from
the notebook's own. SHARE copies the link, and the browser keeps the last
notebook for the next visit.

Strings are drawn at random by a seed (or listed shortest first) and a
click adds one to Test. Counts past u32 are estimated ("about 2.3 × 10³¹").
Convert defaults to state elimination, highlights its pattern and says how
much shorter a model's is. Errors say why and what to try, and a
computation past two seconds can be stopped.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The inspector's header now stays in view and names the line: its number,
name, kind and source, the lines it reads as links, ‹ › to step through
lines, and a flash when the line changes; the editor marks the inspected
line with a bar. An index jumps to each part and shows the one in view.

Each part asks a question and answers it first, with boxed controls and a
rule between parts. Compare states the relation as a sentence and keys
its colours; Test's crosses are muted. An assert line gets its own view:
its verdict, why, and how the two lines it reads compare. On a phone, a
button offers to scroll to the inspector after picking a line.

Fixes the first click into the editor not selecting a line, and TRY
comparing a line with itself on an assert line.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Graphviz lays the automaton out on the page's main thread, and its time
grows steeply: 64 states take about a second, 128 about 17, and the
blow-up example's 8,192 states froze the tab. Converting to an automaton
now fails past 64 states or 200 transitions, saying so and pointing to a
pattern instead. The home page's demo shares the check.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The notebook's link carried it in the query (?nb=), which GitHub Pages
receives and refuses past about 8 KB (a 414, near 350 lines). It now
rides after the # (#nb=), which browsers never send to a server: no host
sees the patterns and the size limit is gone. Old ?nb= and ?op= links
still open, rewritten after the #; a link pasted into the tab opens too;
opening a link sets the visitor's own notebook aside first; and SHARE
warns past 2,000 characters, where some apps cut links. The home page's
OPEN IN THE NOTEBOOK links after the # as well.

PostHog recorded each page's full URL and the text of clicked buttons,
both of which could carry patterns. Its events now drop the query and
fragment of this site's URLs, and autocapture skips the notebook and the
home page's notebook link. The privacy policy says so.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Notebooks now sit in tabs above the editor, as in a code editor: a click
shows one, a double click renames it, × or a middle click closes it, and +
opens an empty one, whose inspector says how to start. Each tab keeps its
text, selected line, Compare line, Convert format and Test strings, and a
fresh undo history, so undo never brings back another tab's text. The tabs
are kept for the next visit; the notebooks kept before tabs become tabs.

Examples open in a tab of their own (or show the one holding them
unedited), and so do shared links, which no longer replace the visitor's
notebook. This replaces "Your notebook" in EXAMPLES.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Watching an automaton outgrow the demo's limit answered no question a
visitor has about their own patterns. In its place, a common date
pattern: an assert line finds that it accepts November 31, and a line
takes the days that do not exist out of it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
"The same strings as fixed" read like a tautology or a warning. Under a
converted pattern, the inspector now says what it means: "Matches exactly
the strings fixed matches: a regex you can use in its place."

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The page is titled "Notebook - Combine, compare and test regexes |
RegexSolver", and once open the browser tab names the notebook on screen
("Notebook - Dates | RegexSolver"). The header's link reads Notebook;
/demo/ stays, so links keep working.

The heading and line of text over the tabs go (the h1, "RegexSolver
Notebook", stays for screen readers), and EXAMPLES, SHARE and CHEATSHEET
move to the tab row's right end, icons alone on a phone.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Ctrl+F (Cmd+F) anywhere on the page opens a search bar over the
notebook's lines, as in a code editor: find with next, previous and all,
match case, regexp and by word, replace and replace all, in the site's
look. It is @codemirror/search, locked at 6.7.2.

A line's mark floats at its right edge, and positions beside it took its
place: at the end of a line, the suggestion list and tooltips opened by
the mark. The mark now reports where its line's text ends.

Also: the browser tab keeps the notebook's title after Next rewrites the
head, and TRY no longer pairs a line with itself when the selected line
has an error.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
TRY offered the same handful of operations whatever the notebook held,
and built on lines named after their number (_2_and_x = _2.union(x)).
It now works from the notebook (lib/suggestions.ts): a name for an
unnamed line first (✎, which renames it and the lines that read it), a
line with what breaks each failing check, a check that keeps what
Compare found, a check that keeps a Test string the line matches, then
the operations that would show something new. Each is drawn in the
editor's colours.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Generated strings can hold characters no font draws. A "show as \u{…}"
checkbox on Strings' settings row writes every character outside
printable ASCII as \u{hex}, as Rust and the patterns do, in the strings
Strings and Compare list; the escapes are muted, and a click still adds
the string itself to Test.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Cases that could break:
- a crafted link could inflate to gigabytes and fill the tab's memory:
  a link's notebook now inflates to 1 MB at most;
- a line named after a Rust keyword (type, match, _) made the Rust
  program fail to compile: the program now renames it (type_);
- the program's own variables could clash with line names, and a
  failing assert! stopped it before anything it prints: they are renamed,
  and a failing check is left in as a comment;
- two windows of the notebook undid each other's tabs: each now merges
  the tabs the other saves;
- a link could set a format the select does not offer, and the answer
  cache grew for the whole visit (it now keeps the latest 400).

Text: shorter engine messages ("too large to draw: 8,192 states, past
64"), a shorter empty notebook, and no "very" in the cheatsheet.

Search engines and AI assistants: the static page said "Nothing to
inspect yet" and little else. It now holds what the notebook is and the
questions it answers (About.tsx), a WebApplication JSON-LD, a share
title that makes the click ("RegexSolver Notebook: find the string that
breaks your regex"), and /llms.txt.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A notebook's link previewed with the site's card ("Set algebra for
regex."). /demo/ now has its own, generated by gen_og.py: "Find the string
that breaks your regex." beside a notebook drawn as the editor draws it,
the Routes example's lines with its failing check and the string that
breaks it, "/users/me", all real notebook output. sync-brand copies it to
the site as /og-notebook.png, and the page's og:image and twitter:image
point to it. The other cards come out unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@alexvbrdn alexvbrdn self-assigned this Nov 29, 2026
@alexvbrdn
alexvbrdn merged commit d097a2d into main Nov 29, 2026
2 checks passed
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.

1 participant