Commit graph

101 commits

Author SHA1 Message Date
Ruud van Asseldonk
3e23f70b09 Record new tree-sitter-rcl v0.12.0 ref 2025-12-17 21:26:59 +01:00
Ruud van Asseldonk
c7267505c3 Bump version to 0.12.0 2025-12-17 21:01:13 +01:00
Ruud van Asseldonk
258f0e2384 Rename Set.{map,flat_map}, add _dedup suffix
The map function in particular is a footgun that hit me twice in two
weeks, in a case similar to this one:

    {"apple", "orange", "banana"}.map(x => x.len()).sum()

This looks like it sums the lengths of the strings. Except it doesn't,
it sums the *unique* lengths of the strings, so we get 11 instead of 17.
That's surprising, and I don't want that kind of surprise in RCL.

At first I thought to remove Set.map and Set.flat_map entirely. You
would just have to convert to a list first and map there, and if you
wanted the set, convert back with List.to_set_dedup, which makes it
explicit. That's why I added these conversion functions. Then I
implemented deletion ... and as I was writing the PR description and
changelog entry for how to handle the break, it dawned on me, if we
have the _dedup anyway in to_set_dedup, we might as well use it here.
We don't have to delete these methods, we can just call them _dedup.

    {"apple", "orange", "banana"}.map_dedup(x => x.len()).sum()

Now the snippet is no longer so sneaky! It's clear that there is
deduplication going on! So I'm fine keeping them in this form. At least
in the Nix transitive closure test, the map_dedup behavior is what I
want, which validates demand for at least map_dedup. But even then,
a changelog entry for a breaking change that says "renamed to X" is a
much better experience than "have been deleted here are some much longer
alternatives".

Also, this change is relatively safe to make: it will break existing
callers, but they will get an error message and there is a clear path
to fixing this. It doesn't silently change the output of something: it's
being called on sets, so there can't even be fields named 'map' or
'flat_map' because sets don't have fields. So I feel comfortable making
a small breaking change here.
2025-12-17 19:28:26 +01:00
Ruud van Asseldonk
0fca8c5056 Add List.{to_set_dedup,to_set_unique} methods
Naming these was a long bikeshed. Some considerations:

 * Symmetry with Set.to_list and String.to_uppercase, keep the to_.

 * Naming after an action is clearer than naming after a property,
   because for a property it's not clear whether that is a precondition
   rather than a postcondition. xs.dedup() makes it clear it removes
   duplicates, xs.unique(), does it assert it's unique? Does it test it?

 * In light of the above observation, List.sort is a good name, better
   than List.sorted.

 * The obvious one people will try is probably to_set. If it silently
   drops duplicates, that's an unsafe default. So let's make this the
   one that validates, and we can have to_set_dedup that drops
   duplicates.

 * Erroring on duplicates is always safe. We can even point the users to
   the version that drops duplicates.

 * If you read code and see xs.to_set() without any contrasting
   .to_set_dedup(), it's not so obvious that .to_set() does any
   validation, and if that is your intent, then you have to clarify
   that in a comment.

 * xs.to_set_assert_unique in that sense is clearer, but it's too
   verbose in practice. xs.to_set_nodup is a bit obscure, especially if
   you don't see the contrasting .to_set_dedup().

 * A method List.dedup that returns a list, and having to_set being the
   one that errors, also works, then you can do .dedup().to_set(), which
   is very explicit. It still does not clarify at the call site that
   to_set is validating though. It is also inefficient, but that's
   probably not a problem for RCL, and you can always use a
   comprehension if it matters.

So conclusion for now, to_set is the right prefix for symmetry and
discoverability. There is not going to be a "default" to set, you have
to explicitly choose whether you want to discard duplicates or not. The
to_set_dedup is clear for that. When reading code, to_set_unique is
maybe less obvious, but it gives more hint than to_set, and if you think
for a moment, set values are already unique, so why the _unique, and
then you find the contrast with _dedup. So far this seems like one of
the better directions.
2025-12-14 19:31:41 +01:00
Ruud van Asseldonk
8a45379cbf Add Set.to_list method
I plan to remove Set.map and Set.flat_map, and to make that slightly
more palatable, let's add Set.to_list, so you can at least replace all
the former calls with .to_list().map(...).
2025-12-14 19:31:41 +01:00
Ruud van Asseldonk
08a7299367 Improve handling of binop inside unop
It turns out, we can:

 * Allow more cases, including the common case of e.g. 'x > -1', without
   creating ambiguities.
 * Still make ambiguities such as 'a and not b or c' an error.
 * Improve the error message for that case, over my previous one!

And this is a tiny change to the grammar and parser, yay! It feels like
one of those times where I discover the *right* way to do it. Discover,
in the platonic sense.
2025-12-13 15:16:40 +01:00
Ruud van Asseldonk
d9a1eaa77c Add transitive_closure builtin to dictionaraies 2025-12-09 22:30:22 +01:00
Ruud van Asseldonk
31db3a01d3 Record new tree-sitter-rcl v0.11.0 ref 2025-11-23 20:27:21 +01:00
Ruud van Asseldonk
44d43a64dc Bump version to 0.11.0 2025-11-23 19:26:00 +01:00
Ruud van Asseldonk
a189fd9bbf Document unpack in the Bison grammar 2025-11-22 22:06:50 +01:00
Ruud van Asseldonk
c2362ff1cb Add unpack to the Tree-sitter grammar 2025-11-22 21:33:24 +01:00
Ruud van Asseldonk
036dead934 Dogfood dict unpack syntax in Cargo.rcl files
This does look more pleasant, yay! I do notice that I find '...' tedious
to write though, and maybe a bit too verbose. Maybe I want to change
that to '..' after all, even for dicts. But we can do that later, let's
see how this goes.
2025-11-22 21:33:24 +01:00
Ruud van Asseldonk
7137cd5a91 Use ':' in assertions rather than ','
Initially I used a comma after assertions, like Python. It was always
a bit weird (even in Python), it's a statement but it has arguments.
This made formatting akward too. I justified it for myself by saying
"it's just a function call, but without the parens". That's how we
currently format it.

Then yesterday I was skimming through the Jsonnet docs, and they use
a colon rather than comma, and that looks much more pleasant! I should
steal the good ideas; if RCL can fix list comprehension order w.r.t
Python, then it can also fix this one.

For compatibility, accept the comma as well (for now), but make the
formatter emit the colon. Similar to the colon after 'else', it does
not have to be a breaking change.
2025-09-29 20:28:15 +02:00
Ruud van Asseldonk
908e6db900 Update Zed extension TS pin to RCL 0.10.0
Because the repositories reference each other, this changes after I
publish a new commit in the tree-sitter-rcl repository.
2025-08-30 21:42:21 +02:00
Ruud van Asseldonk
c124bd7ce8 Bump version to 0.10.0 2025-08-30 21:28:19 +02:00
Ruud van Asseldonk
9cde796903 Record #! rule in Vim plugin template
I should have put it in there in the first place. I would make a fixup
and fix the original commit, but it's so deep in the history now that I
better not rewrite it.
2025-08-30 21:28:19 +02:00
Ruud van Asseldonk
8ccd47871b Make repo update script fill in the latest TS commit
I want to publish a new version of the Zed plugin, and it points to the
Tree-sitter grammar by commit. This is what got the whole "rcl patch"
thing started!

So now, upon export of the Zed extension, we'll pin it to the HEAD of
the adjacent tree-sitter-rcl repository.
2025-08-30 21:28:19 +02:00
Ruud van Asseldonk
0726f76928 Add idea for 'rcl patch' command
When some data in a big configuration needs to come from other sources,
you can already dump it as json and then import it into RCL. But that
does spread your configuration over multiple files, and it makes Git
diffs harder to interpret, when context is missing.

I encountered a similar case at work a while back, where we had some
human-written config, but we wanted a script to edit it, while
preserving formatting and comments etc. Of course what you can always do
in that case is fall back to 'sed', and even though it might match false
positives, or create syntactically invalid files in theory, in practice
it works very well, especially if you add some marker comment.

But there *is* a proper way to do this. Parse into a concrete syntax
tree, and then do some surgery on the tree to splice in the new value.
And hey, what do you know, in RCL we happen to have a parser that builds
concrete syntax trees. And a pretty-printer for them. I thought at
first it would be difficult, because how do you navigate expressions?
But we can start with dicts that use record syntax, and including let
bindings is not too difficult either. Then we just walk the AST trying
to match identifier by identifier.
2025-08-09 23:34:53 +02:00
Ruud van Asseldonk
500b006497 Tweak the bracket and indent queries for Zed
Bracket matching works nicely now. Indents mostly work, but there are
some bad cases. After a 'let' or opening bracket, Zed correctly indents,
but then when you type 'if ...:' in there, it suddenly dedents that. I
don't understand why, so I don't know how to fix it. But for now, this
is already better than the previous version of the plugin, which had
neither.
2025-08-09 22:54:19 +02:00
Ruud van Asseldonk
2b70e78eae Add indents and backet queries for Zed
The documentation for these is extremely sparse. I thought at firast
that this replaces the "brackets" section of the config.toml, especially
because that section is not documented, but in the upstream repo it does
still exist for the first-party plugins, so let's keep it here too. I
can experiment later and see what happens if we delete it.

First let's try and see if these new files do anything.
2025-08-09 21:54:11 +02:00
Ruud van Asseldonk
cc0c1d91aa Improve Zed scope, add link to Zed highlighting docs
Woohoo, they documented them now. Nice.
2025-08-09 20:33:09 +02:00
Ruud van Asseldonk
1d4d9ceb02 Highlight #!-lines in themes
Also improve the documentation around these themes, where to find the
names that can be used, and the structure of the docs about the grammar
directory in general.
2025-08-09 20:30:01 +02:00
Ruud van Asseldonk
c89a61efc3 Add parse_number builtin to keywords 2025-08-07 21:42:42 +02:00
Ruud van Asseldonk
fef65ad12f Bump version to 0.9.0 2025-07-10 22:13:33 +02:00
Ruud van Asseldonk
2015fefbec Add std.format_json to fuzzers and grammars 2025-06-28 21:50:20 +02:00
Ruud van Asseldonk
a34aec267b Autoformat Python sources, make Mypy happy
The module name and path hack throws off Mypy, in different ways
depending on how you run it (outside Nix shell, inside Nix develop
shell, or as part of the flake check ...). Let's just forward-declare
it and sidestep problems.

Maybe I should make this script the source of truth and generate the
Pygments grammar from it. We could do that later, for now this works.
2025-03-15 20:54:25 +01:00
Ruud van Asseldonk
789c89b520 Generate the Vim plugin from builtins
This corrects one bug in the plugin there that went unnoticed: the
'enumerate' builtin was not highlighted previously. So that's a win
for generating things!
2025-03-15 20:43:21 +01:00
Ruud van Asseldonk
34e347a387 Generate fuzz dictionary from Pygments grammar
I regularly add new methods, and it's becoming tedious to have to
remember to update all the places that reference these, so let's
generate them and automate the process. For now, I'm choosing the
Pygments grammar as the source of truth, and the first target to
generate is the fuzz dictionary.
2025-03-03 22:14:27 +01:00
Ruud van Asseldonk
7292a22404 Update Zed extension to latest Tree-sitter grammar 2025-03-02 21:19:41 +01:00
Ruud van Asseldonk
59be133128 Bump version to 0.8.0
I'm leaving the Zed extension pointing to the older commit of the
Tree-sitter grammar, I'll update that after this version bump. It's
a bit awkward to do it this way around, but there are circular
dependencies that can't be avoided. Maybe with an attack on SHA1 it
can be done in theory, but let's not go there.
2025-03-02 21:15:33 +01:00
Ruud van Asseldonk
f0e4cd13b5 Add Number.round method
At first I also wanted to support rounding to a negative number of
decimals (so rounding to a positive power of 10), but scope creep,
complications ... I don't need it, and we can always add that later.
2025-03-02 18:32:21 +01:00
Ruud van Asseldonk
27f91ac012 Remove various final references to Int 2025-02-24 21:08:49 +01:00
Ruud van Asseldonk
3dafed4571 Rename Num type to Number, add highlighting for it
RCL aims to be obvious to understand. Num might be cryptic for new users,
and although we also have "Int" rather than "Integer", that one is very
established, "Num" may be a bit too obscure. (We also have "String"
rather than "Str", consistency ...). It's a type that I expect has
little use for end-users, but it shows up in the negation error message,
so let's make it unambiguous and call it "Number".
2025-02-24 20:42:59 +01:00
Ruud van Asseldonk
6c0734148f Add List.sort_by and Set.sort_by methods
I realized today that I want this. In particular, the API of my music
player Musium returns albums with a numeric playcount and discovery
score, and I want to sort on that. Finally that is possible now that I
am adding support for floats. But I need a way to sort on one field of
a dict! Arguably this is more important than the bare sort itself.

While I do this for lists, we can do the same for sets.
2025-02-24 19:44:04 +01:00
Ruud van Asseldonk
9dc5092279 Bump version to 0.7.0 2024-12-31 13:34:37 +01:00
Ruud van Asseldonk
503dfbfd85 Generate Zed's extension.toml too
I think this is the last place where I manually had to sync the version
number!
2024-12-08 16:03:05 +01:00
Ruud van Asseldonk
7fab95954e Dogfood-generate tree-sitter-rcl Cargo.toml 2024-12-08 15:42:28 +01:00
Ruud van Asseldonk
409e6b9eb3 Highlight new List and Set methods 2024-12-07 20:57:26 +01:00
Ruud van Asseldonk
2601582abe Add std.empty_set constant
It started to get annoying to have to define it myself every time, so
let's just add it properly now. This also resolves the longstanding
issue in the RCL pretty-printer that we have no good way to print the
empty set -- now we do!
2024-12-07 20:26:40 +01:00
Ruud van Asseldonk
dff50984d9 Document and highlight new List.sort method 2024-12-01 13:15:28 +01:00
Ruud van Asseldonk
1bac59668e Bump version to 0.6.0
See docs/changelog.md for a summary of the changes in this release.
2024-12-01 11:52:49 +01:00
Ruud van Asseldonk
d6a4b48bee Point Zed extension at the newly published grammar
This is a bit annoying now, I have to dump them one by one and update
the repository url. But the format forces that. I could automate it
further, but for now it's okay to do by hand.
2024-08-02 23:20:28 +02:00
Ruud van Asseldonk
08725c60b0 Point Zed extension url at external repo 2024-08-02 23:12:53 +02:00
Ruud van Asseldonk
82cf536c6f Add documentation about the grammars and testing 2024-08-02 23:12:18 +02:00
Ruud van Asseldonk
9105bb9f17 Add Tree-sitter highlights for Zed
Documentation is quite absent for Zed, but that is not stopping people
from developing extensions apparently.
2024-08-02 21:33:05 +02:00
Ruud van Asseldonk
8b4cadc0d3 Add an initial Zed extension
This has not been tested yet. Also, I may need to move it into a
separate repository, but we can do that in the same way as with the
Tree-sitter repo that I just extracted.
2024-08-02 21:33:05 +02:00
Ruud van Asseldonk
816a00745f Optionally allow a colon after "else" in grammar
When I initially converted from the "if-then-else" keyword syntax to the
colon-based one, during development I put the colon in, then later I
removed it again, but I was still unsure. Now, after having used the
syntax for some time, my feeling is that there should be a colon after
all. Nim got it right. So put it back.

Because it's easy to stay backwards compatible here, make the colon
optional. We can make it mandatory at some point in the future, but even
making the autoformatter put it there is probably a strong enough push.
2024-07-31 21:46:23 +02:00
Ruud van Asseldonk
28d920e4ac Bump version to 0.5.0 2024-07-28 21:43:29 +02:00
Ruud van Asseldonk
2967267622 Bump version to 0.4.0 2024-07-13 10:37:59 +02:00
Ruud van Asseldonk
a95959146f Add List.sum and Set.sum methods 2024-07-12 23:10:11 +02:00