Explorer

core.type-expression-to-type-ast

description
Convert a type expression to core.type-ast. A variable that is a type parameter (in `parameters`) becomes `parameter(name)`, a call of a part that returns a type becomes `apply`, and a function (a part that takes types and returns a type) becomes its body with the parameters in scope
type
Fn(expr: @core.expression, parameters: List<Record{parameter_id: Number, parameter_name: String}>) -> Union{#none, #some(@core.type-ast)}
expression
fn(expr$0, parameters$2000) =>
  match $0 {
    #type_number(_) =>
      #some(#number),
    #type_float(_) =>
      #some(#float),
    #type_string(_) =>
      #some(#string),
    #type_boolean(_) =>
      #some(#boolean),
    #type_list(list_e$10) =>
      match @core.type-expression-to-type-ast(expr: $10.item_type, parameters: $2000) {
        #none(_) =>
          #none,
        #some(item$11) =>
          #some(#list({item_type: $11}))
      },
    #type_code(list_e$10) =>
      match @core.type-expression-to-type-ast(expr: $10.value_type, parameters: $2000) {
        #none(_) =>
          #none,
        #some(item$11) =>
          #some(#code($11))
      },
    #type_function(fn_e$12) =>
      match @core.type-declaration-parameters-to-type-ast(items: $12.parameters, index: 0, accum: [], parameters: $2000) {
        #none(_) =>
          #none,
        #some(params$13) =>
          match @core.type-expression-to-type-ast(expr: $12.return_type, parameters: $2000) {
            #none(_) =>
              #none,
            #some(ret$14) =>
              #some(#function({parameters: $13, return_type: $14}))
          }
      },
    #type_record(fields_e$15) =>
      match @core.type-declaration-fields-to-type-ast(items: $15, index: 0, accum: [], parameters: $2000) {
        #none(_) =>
          #none,
        #some(fields$16) =>
          #some(#record($16))
      },
    #type_union(variants_e$17) =>
      match @core.type-declaration-variants-to-type-ast(items: $17, index: 0, accum: [], parameters: $2000) {
        #none(_) =>
          #none,
        #some(variants$18) =>
          #some(#union($18))
      },
    #part_reference(pr$19) =>
      #some(#reference({part_hash: $19.part_definition_event_hash})),
    #type_type(_) =>
      #some(#type),
    #type_parameter(name$3000) =>
      #some(#parameter($3000)),
    #type_secret(_) =>
      #some(#secret),
    #variable(variable$2001) =>
      match @core.type-parameter-name(parameters: $2000, id: $2001.variable_id, index: 0) {
        #none(_) =>
          #none,
        #some(name$2002) =>
          #some(#parameter($2002))
      },
    #call(call_e$2003) =>
      match $2003.function {
        #part_reference(reference$2004) =>
          match @core.type-expression-arguments-to-type-ast(items: $2003.arguments, parameters: $2000, index: 0, accum: []) {
            #none(_) =>
              #none,
            #some(arguments$2005) =>
              #some(#apply({part_hash: $2004.part_definition_event_hash, arguments: $2005}))
          },
        _ =>
          #none
      },
    #function(function_e$2006) =>
      @core.type-expression-to-type-ast(expr: $2006.body, parameters: @core.list-concat(left: $2000, right: $2006.parameters)),
    #builtin(name$3001) =>
      #some(#builtin($3001)),
    _$99 =>
      #none
  }
visibility
public
core.type-expression-to-type-ast (project definy, branch compiled-tests, snapshot i6TqClmqVS9FK8rKOvJ43l6Tevx8pvYJ5-zaQqNwemc)
id: flRpOibOe71SLUURogsVBmMYctMs075Rr2Z0OJ5fc4M
content hash: qHKRDJwkA-SPc4dlMDe5afrdXJWN1gJdHQHYigcBv9U