ProtoDef-io/protodefc

Way to represent repetition until terminator

hansihe opened this issue · 6 comments

Way to represent repetition until terminator

ProtoDef-io/ProtoDef#8

@type binary("utf8")
def_native("delimited_string") {
    argument("terminator", match: "\x00");
};

Or maybe match: "0" or match: 0, but accept different constant types?

I think you misunderstand what argument for native types does.

It declares a slot where you can pass an argument when using the type.

Is this thing needed? May be cstring should be implemented in native instead of defining it?

@creeplays Sure, cstring would probably be implemented as a native type.

The reason we need this is mainly because of other things. An example of this is the NBT format, where a compound tag is a list of named values until a terminator tag.

What about implementing new syntax for this?
Like this:

array(terminator: "0") => container {};

That would work for that one specific case, but it's not a general solution, and it doesn't scale to other things.

For it to be a truly general solution, it would need to compose well with the other parts of the language.