Support table parameters and record types (#37) #38

Merged
Aire-One merged 7 commits from feat/#37 into master 2022-11-06 19:23:20 +01:00
1 changed files with 22 additions and 17 deletions
Showing only changes of commit fc9e26b9c9 - Show all commits

View File

@ -15,6 +15,7 @@ local record Module
render_enum: function(name: string, values: List<string>): string
render_record_properties: function(items: List<Variable_Info.Variable_Info>): string
render_record: function(name: string, items: List<Variable_Info.Variable_Info>): string
render_records_from_Parameters: function(items: List<Function_Info.Parameter>): string
end
@ -52,27 +53,31 @@ function snippets.render_anonymous_function_signature(item: Function_Info.Functi
return utils.do_or_fail(template.substitute, tmpl, tmpl_args)
end
function snippets.render_records_from_Parameters(items: List<Function_Info.Parameter>): string
return items:map(function(param: Function_Info.Parameter): string
if #param.types == 0 then
return ""
end
return param.types:map(function(t: Type_Info.Type_Info): string
if t.record_entries and (t.record_entries as Map<string, List<Type_Info.Type_Info>>):len() > 0 then
local properties: List<Variable_Info.Variable_Info> = List()
for name, types in (t.record_entries as Map<string, List<Type_Info.Type_Info>>):iter() do
properties:append(Variable_Info(name, types))
end
return snippets.render_record(t.name, properties)
end
return ""
end):filter(function(p: string): boolean return #p > 0 end):concat("\n")
end):filter(function(p: string): boolean return #p > 0 end):concat("\n")
end
function snippets.render_record_functions(items: List<Function_Info.Function_Info>): string
return items:map(function(item: Function_Info.Function_Info): string
return string.format(
"%s%s",
item.parameters:map(function(param: Function_Info.Parameter): string
if #param.types == 0 then
return ""
end
return param.types:map(function(t: Type_Info.Type_Info): string
if t.record_entries and (t.record_entries as Map<string, List<Type_Info.Type_Info>>):len() > 0 then
local properties: List<Variable_Info.Variable_Info> = List()
for name, types in (t.record_entries as Map<string, List<Type_Info.Type_Info>>):iter() do
properties:append(Variable_Info(name, types))
end
return snippets.render_record(t.name, properties)
end
return ""
end):concat("\n")
end):concat("\n"),
snippets.render_records_from_Parameters(item.parameters),
snippets.render_anonymous_function_signature(item))
end):concat("\n")
end