Saturday, March 23, 2024

Re: Nested Classes — thoughts and workarounds

On 2024-03-22, Igbanam Ogbuluijah <xigbanam@gmail.com> wrote:
> Hello community,
>
> I've been playing with some idea which has brought me to needing Nested
> Classes in Vim. I am curious what you think about this? Would this be too
> much for Vimscript? If not, what current workarounds would you suggest?

I don't think Vim 9 script needs or would gain anything for such
extensions.

> Context: I'm taking a stab at parsing protobuf definitions into Vim 9
> classes. Nested messages in the protobuf demands
><https://arc.net/l/quote/qfcssecm> nested structs/classes.

Something like:

message SearchResponse {
message Result {
string url = 1;
string title = 2;
repeated string snippets = 3;
}
repeated Result results = 1;
}

becomes two classes/structs `SearchResponse` and `SearchResponse_Result`
in the target languages I've looked at. In Vim, you could do the same:

interface Message
endinterface

class SearchResponseResult implements Message
var url: string
var title: string
var snippets: list<string>
endclass

class SearchResponse implements Message
var results: list<SearchResponseResult>
endclass

That seems the most straightforward approach to me.

If you don't care about typing (but wouldn't that defeat the purpose of
protobuf?), you may simply use dictionaries, which can be arbitrarily
nested.

If your problem is parsing, libparser might help:

https://github.com/lifepillar/vim-devel

Protobuf's grammar seems simple enough. You might even go fancy and
generate parsers from messages, which would be able to parse the
corresponding messages.

I don't see any reason to keep using Vim legacy script for new Vim
scripts.

Hope this helps,
Life.

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/utmm5o%2412c1%241%40ciao.gmane.io.

No comments:

Post a Comment