(module string (export len concat parse_i32_result parse_i32_option parse_u32_result parse_u32_option parse_i64_result parse_i64_option parse_u64_result parse_u64_option parse_f64_result parse_f64_option parse_bool_result parse_bool_option parse_i32_or_zero parse_u32_or_zero parse_i64_or_zero parse_u64_or_zero parse_f64_or_zero parse_bool_or_false parse_i32_or parse_u32_or parse_i64_or parse_u64_or parse_f64_or parse_bool_or))

(import std.result (ok_or_none_i32 ok_or_none_u32 ok_or_none_i64 ok_or_none_u64 ok_or_none_f64 ok_or_none_bool))

(fn len ((value string)) -> i32
  (std.string.len value))

(fn concat ((left string) (right string)) -> string
  (std.string.concat left right))

(fn parse_i32_result ((value string)) -> (result i32 i32)
  (std.string.parse_i32_result value))

(fn parse_i32_option ((value string)) -> (option i32)
  (ok_or_none_i32 (parse_i32_result value)))

(fn parse_u32_result ((value string)) -> (result u32 i32)
  (std.string.parse_u32_result value))

(fn parse_u32_option ((value string)) -> (option u32)
  (ok_or_none_u32 (parse_u32_result value)))

(fn parse_i64_result ((value string)) -> (result i64 i32)
  (std.string.parse_i64_result value))

(fn parse_i64_option ((value string)) -> (option i64)
  (ok_or_none_i64 (parse_i64_result value)))

(fn parse_u64_result ((value string)) -> (result u64 i32)
  (std.string.parse_u64_result value))

(fn parse_u64_option ((value string)) -> (option u64)
  (ok_or_none_u64 (parse_u64_result value)))

(fn parse_f64_result ((value string)) -> (result f64 i32)
  (std.string.parse_f64_result value))

(fn parse_f64_option ((value string)) -> (option f64)
  (ok_or_none_f64 (parse_f64_result value)))

(fn parse_bool_result ((value string)) -> (result bool i32)
  (std.string.parse_bool_result value))

(fn parse_bool_option ((value string)) -> (option bool)
  (ok_or_none_bool (parse_bool_result value)))

(fn parse_i32_or_zero ((value string)) -> i32
  (match (parse_i32_result value)
    ((ok payload)
      payload)
    ((err code)
      0)))

(fn parse_u32_or_zero ((value string)) -> u32
  (match (parse_u32_result value)
    ((ok payload)
      payload)
    ((err code)
      0u32)))

(fn parse_i64_or_zero ((value string)) -> i64
  (match (parse_i64_result value)
    ((ok payload)
      payload)
    ((err code)
      0i64)))

(fn parse_u64_or_zero ((value string)) -> u64
  (match (parse_u64_result value)
    ((ok payload)
      payload)
    ((err code)
      0u64)))

(fn parse_f64_or_zero ((value string)) -> f64
  (match (parse_f64_result value)
    ((ok payload)
      payload)
    ((err code)
      0.0)))

(fn parse_bool_or_false ((value string)) -> bool
  (match (parse_bool_result value)
    ((ok payload)
      payload)
    ((err code)
      false)))

(fn parse_i32_or ((value string) (fallback i32)) -> i32
  (match (parse_i32_result value)
    ((ok payload)
      payload)
    ((err code)
      fallback)))

(fn parse_u32_or ((value string) (fallback u32)) -> u32
  (match (parse_u32_result value)
    ((ok payload)
      payload)
    ((err code)
      fallback)))

(fn parse_i64_or ((value string) (fallback i64)) -> i64
  (match (parse_i64_result value)
    ((ok payload)
      payload)
    ((err code)
      fallback)))

(fn parse_u64_or ((value string) (fallback u64)) -> u64
  (match (parse_u64_result value)
    ((ok payload)
      payload)
    ((err code)
      fallback)))

(fn parse_f64_or ((value string) (fallback f64)) -> f64
  (match (parse_f64_result value)
    ((ok payload)
      payload)
    ((err code)
      fallback)))

(fn parse_bool_or ((value string) (fallback bool)) -> bool
  (match (parse_bool_result value)
    ((ok payload)
      payload)
    ((err code)
      fallback)))
