Repository navigation
regexp: make Match a plain object with named captures - #95
Merged
Merged
Conversation
Deploying dang with
|
| Latest commit: |
2144654
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://e4d6b612.dang-3kk.pages.dev |
| Branch Preview URL: | https://refactor-match-plain-object.dang-3kk.pages.dev |
A regex match was a bespoke MatchValue type with its own Value impl and a dedicated case in Select.Eval, which is overkill for what is really just a record of fields. Now that Dang has a Map type, a Match can be an ordinary plain object: newMatch binds string/start/end and the positional captures list as fields, and named captures become a Map[String] keyed by group name. A named group that did not participate reads back as null, and an unknown name is an absent key, preserving the old capture(name) lookup semantics without a callable field. This deletes MatchValue and the special dispatch branch, so a Match now flows through normal object field access. MatchType stays, since Select.Infer requires a named TypeScope receiver to carry the field schemes; the Method(MatchType, ...) registrations remain as declaration-only members for the type checker and the stdlib reference. Signed-off-by: Alex Suraci <[email protected]>
vito
force-pushed
the
refactor-match-plain-object
branch
from
June 9, 2026 15:31
8de3e2c to
2144654
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
A regex match used to be a bespoke
MatchValue— its own Go struct with aValueimpl and a specialcase MatchValue:branch inSelect.Eval. That's overkill for what is really just a record of fields.Now that Dang has a first-class
Maptype, aMatchbecomes a truly plain object (newMatch) whose members are materialized as ordinary fields. It flows through the normalcase ValueScope:object path with no bespoke value type, no dispatch special-case, and no callable members.MatchValuestruct and itsValue/String/MarshalJSONimpls, and thecase MatchValue:dispatch inSelect.Eval.newMatch(re, src, indices) *Objectbindsstring/start/endand the positionalcaptureslist as plain fields.named: Map[String]keyed by group name, replacing the oldcapture(name)callable. A named group that did not participate reads back asnull, and an unknown name is an absent key (alsonull) — exactly the oldcapture(name)semantics, but as plain data you can index, iterate, and serialize.Why
MatchTypestaysSelect.Inferrequires the receiver to be a namedTypeScopeto carry its field schemes, which structural record types aren't — so a match still needs a named type.MatchTypeis now just the type of a plain object rather than backing a bespoke runtime value. TheMethod(MatchType, …)registrations are kept as declaration-only members so the fields still type-check and appear in the auto-generated stdlib reference; their impls simply return the bound field.API
Behavior changes vs. the previous
MatchValuecapture(name)is removed in favor ofnamed[name].module Match(every real use goes through.string/.captures/.named).{"captures":["","bar"],"end":3,"named":{"pre":null,"word":"bar"},"start":0,"string":"bar"}. No more bespokeMarshalJSON— and since there are no callable members, no special-casing is needed when marshaling the object.Testing
go test ./pkg/dang/ ./tests/passes (the language and error-golden suites, includingtests/test_regexp.dang). The only failures in the full tree are the neovim/zed editor-highlight tests, which require editor submodules and a lua/neovim runtime not present in the dev sandbox.