[Rpm-maint] [rpm-software-management/rpm] RFE: macros as arrays/sets/dicts (Issue #1825)
Michael Schroeder
notifications at github.com
Wed Nov 10 16:29:28 UTC 2021
I had an idea about (mis)-using the argument splitting code to implement arrays/sets/dicts in rpm. My proof-of-concept implementation can do this:
```
%defineobject aaa(array)
%aaa push foo
%aaa push bar
%aaa push %aaa
%aaa push %{quote:hello world}
%aaa push %{quote:}
%aaa push %{quote:hello world ''}
%{foreach aaa - %{shescape:%1}
}
%defineobject sss(set)
%sss add foo
%sss add bar
%sss add foo
%{foreach sss - set %{shescape:%1}
}
%sss contains bar
%defineobject ddd(dict)
%ddd add foo valfoo
%ddd add bar valbar
%ddd add foo valbaz
%{foreach ddd - dict %{shescape:%1} => %{shescape:%2}
}
```
Output (empty lines stripped):
```
- 'foo'
- 'bar'
- 'foo'
- 'bar'
- 'hello world'
- ''
- 'hello world '\'''\'''
- set 'foo'
- set 'bar'
1
- dict 'foo' => 'valbaz'
- dict 'bar' => 'valbar'
```
The datatypes itself are implemented in lua, there are just the following new builtins:
```
%defineobject name(type) - define a new macro object
%globalobject name(type) - same with global context
%getobjectbody name(type) - return the body of a macro object
%setobjectbody name(type) body - change the body of a macro object
```
There is also `%foreach name loopbody` that iterates over a macro and also knows that a dict has a key and a value.
I implemented some syntactic sugar so that you can call methods on an object:
```
%{object methodname methodargs}
```
is syntactic sugar for
```
%{_<objecttype>_methodname objectname(objecttype) objectargs}
```
This might have been a bit too much, maybe `%{object aaa push foo}` is clearer than `%{aaa push foo}`.
Anyway, it's nothing we really need, I'm just opening this issue so that you know it's there.
--
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/rpm-software-management/rpm/issues/1825
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.rpm.org/pipermail/rpm-maint/attachments/20211110/f39068e1/attachment.html>
More information about the Rpm-maint
mailing list