Closed schungx closed 2 years ago
Thanks! There are some decisions we'll have to make regarding types, I left some comments about those, otherwise LGTM.
@tamasfe I've changed all &str
to String
for the time being, and INT
to i64
.
Also, a couple of additions for ??
and ?.
to the syntax highlighting.
@tamasfe If you're ok with this, then I'll press the "Merge" button. :-)
Or maybe better you do it!
@schungx Sorry, sure, looks good. There are 2 things I'm concerned about, none of which block this PR:
?
annotations, because there are still some decisions to be made regarding them:
?
the correct way to represent an unknown/any type? In typescript it's called either any
or unknown
, but I'm concerned that it can conflict with actual type names, whereas ?
is not a valid type name.?
or should it be an error?...
is implemented right now, but we'll have to implement it anyway.Agree on both counts. As for ?
, I guess it is as good as anything else. In the actual docs generated in JSON, the catch-all type will be Dynamic
, which is a mouthful. It is a much better syntax to use ?
.
As for ...
, that is because Rhai has no variable-parameter functions (all functions have fixed number of parameters). However, a number of built-in functions do take variable number of parameters (such as curry
and call
). Thus, it sort of needs a way to document this fact... or we can leave off the signature for curry
and call
.
Thus, a solution is to have syntax for marking types and var-args that is not supported by Rhai itself - in that case using ?
to replace Dynamic
would be ok. Also the spread operator can be used for func definitions, but not supported by Rhai itself.
Thus, it sort of needs a way to document this fact... or we can leave off the signature for curry and call.
They should be a part of the definitions for sure, I'll implement the spread syntax and we can restrict it to some blessed built-in functions on the HIR level.
I added the missing ?
for the time being since the parser expects a type. I'll have to also change the function return syntax from :
to ->
as well.
@tamasfe These are definitions for all the built-in functions.