Repository navigation
feat: add Map collection type - #98
Merged
Merged
Conversation
Deploying dang with
|
| Latest commit: |
d642769
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://03934fd3.dang-3kk.pages.dev |
| Branch Preview URL: | https://map-collection-type.dang-3kk.pages.dev |
Contributor
Adding non-null coercion becomes increasingly important: #53 (comment) |
Owner
Author
|
@sagikazarmark done in #100 |
Add a string-keyed Map collection type alongside List. Maps are written with `["key": value]` literals (and `[:]` for an empty map), typed as `Map[V]`, and indexed with `m["key"]`, returning null for missing keys. Values must be homogeneous and keys must be strings; both are enforced at type-check time with dedicated errors. Maps preserve insertion order and compare order-independently. The stdlib provides get, has, length, isEmpty, keys, values, with, without, merge, map, and each, all returning new maps rather than mutating in place. Includes parser grammar, regenerated peg and tree-sitter parsers, stdlib methods, completion, formatting, docs, and tests. Signed-off-by: Alex Suraci <[email protected]>
A new test on main requires every stdlib builtin to carry a runnable .Example(...) so the reference can render a REPL for each entry. Add examples for the Map methods, which also exercise each one through the parse/infer/eval path. Signed-off-by: Alex Suraci <[email protected]>
The initial `keys := m.Keys` was overwritten in both branches, which the ineffassign linter flagged. Copy the keys once up front and only append the new key when it isn't already present; behavior is unchanged. Signed-off-by: Alex Suraci <[email protected]>
Main's formatter drops the redundant `pub` keyword from type-annotated top-level declarations, which is now the canonical form. Reformat the map test files to match and refresh the affected error-message golden. Signed-off-by: Alex Suraci <[email protected]>
These map test declarations are local bindings for assertions, not module exports, so let reads better than the bare (formerly pub) form left by the formatter. Convert them throughout and refresh the affected golden files. Signed-off-by: Alex Suraci <[email protected]>
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.
Adds a string-keyed
Mapcollection type to Dang, alongside the existingList.Syntax
Maps are typed as
Map[V]. Keys must be strings and values must be homogeneous; both are enforced at type-check time with dedicated errors. Maps preserve insertion order and compare order-independently.Stdlib
get,has,length,isEmpty,keys,values,with,without,merge,map, andeach— all immutable (they return new maps rather than mutating in place).keys/valuespreserve insertion order.Implementation
Covers the type system, parser grammar (
dang.peg+ regenerated peg parser), the tree-sitter grammar/parser, AST literals, evaluation, completion, formatting, and docs. Includestests/test_maps.dang, error-case fixtures with golden files, a tree-sitter corpus, and runnable stdlib examples for each new method.Tests
go test ./pkg/dang/ ./tests/passes. The pre-existingpkg/lspneovim test (TestNeovimRename) flakes onmainindependently of this change.