caffeine_lang/types

Types

AcceptedTypes is a union of all the types that can be used as a “filter” over the set of all possible values. This allows us to type params and thus provide annotations that the compiler can leverage to be a more useful guide towards the pit of success.

pub type AcceptedTypes {
  PrimitiveType(PrimitiveTypes)
  CollectionType(CollectionTypes(AcceptedTypes))
  ModifierType(ModifierTypes(AcceptedTypes))
  RefinementType(RefinementTypes(AcceptedTypes))
  RecordType(dict.Dict(String, AcceptedTypes))
}

Constructors

Represents collection types that can contain accepted type values.

pub type CollectionTypes(accepted) {
  Dict(accepted, accepted)
  List(accepted)
}

Constructors

  • Dict(accepted, accepted)
  • List(accepted)

Modifier types are a special class of types that alter the value semantics of the attribute they are bound to.

pub type ModifierTypes(accepted) {
  Optional(accepted)
  Defaulted(accepted, String)
}

Constructors

  • Optional(accepted)
  • Defaulted(accepted, String)

    Defaulted type stores the inner type and its default value as a string e.g., Defaulted(Integer, “10”) means an optional integer with default 10

NumericTypes are just numbers which have a variety of representations.

pub type NumericTypes {
  Float
  Integer
  Percentage
}

Constructors

  • Float
  • Integer
  • Percentage

ParsedType is the frontend counterpart of AcceptedTypes that allows type alias references. It exists only in the parser → validator → formatter → lowering pipeline. After lowering resolves all aliases, downstream code works with pure AcceptedTypes.

pub type ParsedType {
  ParsedPrimitive(PrimitiveTypes)
  ParsedCollection(CollectionTypes(ParsedType))
  ParsedModifier(ModifierTypes(ParsedType))
  ParsedRefinement(RefinementTypes(ParsedType))
  ParsedTypeAliasRef(String)
  ParsedRecord(dict.Dict(String, ParsedType))
}

Constructors

PrimitiveTypes are the most atomic of types. I.E. the simple ones most folks think of: Boolean, Float, Integer, String.

pub type PrimitiveTypes {
  Boolean
  String
  NumericType(NumericTypes)
  SemanticType(SemanticStringTypes)
}

Constructors

Refinement types enforce additional compile-time validations.

pub type RefinementTypes(accepted) {
  OneOf(accepted, set.Set(String))
  InclusiveRange(accepted, String, String)
}

Constructors

  • OneOf(accepted, set.Set(String))

    Restricts values to a user-defined set. I.E. String { x | x in { pasta, pizza, salad } }

    At this time we only support:

    • Primitives: Integer, Float, String
    • Modifiers: Defaulted with Integer, Float, String
  • InclusiveRange(accepted, String, String)

    Restricts values to a user-defined range. I.E. Int { x | x in (0..100) }

    At this time we only support:

    • Primitives: Integer, Float

    Furthermore, we initially will only support an inclusive range, as noted in the type name here.

SemanticStringTypes are strings with semantic meaning and validation.

pub type SemanticStringTypes {
  URL
}

Constructors

  • URL

Type metadata for display purposes.

pub type TypeMeta {
  TypeMeta(
    name: String,
    description: String,
    syntax: String,
    example: String,
  )
}

Constructors

  • TypeMeta(
      name: String,
      description: String,
      syntax: String,
      example: String,
    )

Validation error with expected type, found value, and path context. Replaces decode.DecodeError to eliminate the gleam/dynamic/decode dependency.

pub type ValidationError {
  ValidationError(
    expected: String,
    found: String,
    path: List(String),
  )
}

Constructors

  • ValidationError(
      expected: String,
      found: String,
      path: List(String),
    )

Values

pub fn numeric_type_to_string(
  numeric_type: NumericTypes,
) -> String

Converts a NumericTypes to its string representation.

pub fn semantic_type_to_string(
  typ: SemanticStringTypes,
) -> String

Converts a SemanticStringTypes to its string representation.

Search Document