Open Panzerschrek opened 1 year ago
Approach with _makearray and _maketuple as separate operators seems to be interesting. It doesn't require type name specifying - exact type will be evaluated based on actual argument count and types.
It may be possible to always parse postfix [
as sequence initializer. Later in CodeBuilder its processing will depend on kind of name before [
. If it is variable - process it as indexation operator. If it is type name - process it as sequence initializer.
Suggestions for initialization invocation syntax:
->
- it's now used only in switch
operator branches. [ i32, 4 ] -> [ 5, 55, 555, 5555 ]
.@
- is now used only in reference notation for functions. It's possible to use it for initializer invocation, but it seems to be confusing.init
. [ i32, 4 ] init [ 5, 55, 555, 5555 ]
. It looks nice only with syntax highlighting enabled.#
isn't used by the language at all, so, it's possible to start using it for initialization. But again, it may be confused, because in other languages it is used for preprocessor detectives or comments.It's better to avoid lexems like =>
, because it may be confused with >=
and <=>
- which both mean comparison.
https://github.com/Panzerschrek/U-00DC-Sprache/commit/4dc627289da1d56ca1c6d8542a75d5cd4fbb9bb4
Now it's possible to create structs in expression context with {}
initializer.
Right now it is possible to construct temp variable in expression context by using type name and
()
operator (for constructor call). It works fine, but works only for cases where constructor initializer is applicable - for fundamental types, classes, for copying of arrays/tuples. It might be good to introduce some syntax for construction of temp variable with arbitrary initializer - sequence initializer (arrays, tuples), struct named initializer, zero initializer uninitialized initializer.For structs it may my possible to allow struct named initializer as expression postfix operator. For now introducing
{}
in expression context doesn't break something.Sequence initializer "as is" is not possible to use in expression context. It starts with
[
- exactly like indexation operator.Alternative way to simplify temp variables construction for arrays and tuples is to introduce some special operators for this. Right now there are _makearray and _maketuple standard library functions. They work somehow, but it may be better to implement same functionality inside language core - at least compilation may be faster.
Yet another way - to add some proxy syntax operator. Like some lexem or sequence of lexems that triggers parsing of initializer. For example (with
@)
: