gen_gleam/statements

For generating Gleam statements

Types

pub opaque type Argument
pub opaque type Clause
pub type ComparisonOperator {
  Lt
  Lte
  Eq
  Neq
  Gt
  Gte
}

Constructors

  • Lt
  • Lte
  • Eq
  • Neq
  • Gt
  • Gte

Might become opaque. Do use the functions to generate the constructors/variants.

pub type GleamStatement {
  NilVal
  IntVal(value: Int)
  ListVal(items: List(GleamStatement))
  StringVal(string: String)
  TupleVal(items: List(GleamStatement))
  VariantVal(name: String, fields: List(GleamStatement))
  VarPrimitive(name: String)
  Comparison(GleamStatement, ComparisonOperator, GleamStatement)
  CaseStatement(
    guards: List(GleamStatement),
    clauses: List(Clause),
  )
  Function(
    name: String,
    arguments: List(Argument),
    statements: List(GleamStatement),
  )
  FunctionCall(name: String, arguments: List(GleamStatement))
  UseArg(arg: GleamStatement)
  LetVar(pattern: Pattern, statement: GleamStatement)
  LetArray(patterns: List(Pattern), array: GleamStatement)
  LetTuple(patterns: List(Pattern), tuple: GleamStatement)
  Multiply(terms: List(GleamStatement))
  Direct(string: String)
}

Constructors

  • NilVal
  • IntVal(value: Int)
  • ListVal(items: List(GleamStatement))
  • StringVal(string: String)
  • TupleVal(items: List(GleamStatement))
  • VariantVal(name: String, fields: List(GleamStatement))
  • VarPrimitive(name: String)
  • Comparison(GleamStatement, ComparisonOperator, GleamStatement)
  • CaseStatement(
      guards: List(GleamStatement),
      clauses: List(Clause),
    )
  • Function(
      name: String,
      arguments: List(Argument),
      statements: List(GleamStatement),
    )
  • FunctionCall(name: String, arguments: List(GleamStatement))
  • UseArg(arg: GleamStatement)
  • LetVar(pattern: Pattern, statement: GleamStatement)
  • LetArray(patterns: List(Pattern), array: GleamStatement)
  • LetTuple(patterns: List(Pattern), tuple: GleamStatement)
  • Multiply(terms: List(GleamStatement))
  • Direct(string: String)
pub opaque type Pattern

Functions

pub fn arg_typed(name: String, arg_type: GleamType) -> Argument
pub fn arg_untyped(name: String) -> Argument
pub fn call(
  name: String,
  arguments: List(GleamStatement),
) -> GleamStatement
pub fn case_stmt(
  guards: List(GleamStatement),
  clauses: List(Clause),
) -> GleamStatement
pub fn clause(
  patterns: List(Pattern),
  stmt: GleamStatement,
) -> Clause
pub fn compare(
  stmt1: GleamStatement,
  comp_op: ComparisonOperator,
  stmt2: GleamStatement,
) -> GleamStatement
pub fn direct(string: String) -> GleamStatement

@deprecated

pub fn function(
  name: String,
  arguments: List(Argument),
  statements: List(GleamStatement),
) -> GleamStatement
pub fn generate(stmt: GleamStatement) -> String
pub fn int(value: Int) -> GleamStatement
pub fn let_array(
  patterns: List(Pattern),
  array: GleamStatement,
) -> GleamStatement

TODO: Needs middle argument Option(Pattern) for ..tail

pub fn let_tuple(
  patterns: List(Pattern),
  tuple: GleamStatement,
) -> GleamStatement
pub fn let_var(
  pattern: Pattern,
  statement: GleamStatement,
) -> GleamStatement
pub fn list(values: List(GleamStatement)) -> GleamStatement
pub fn literal(lit: String) -> Pattern

a constant pattern, such as True or 42 (represented as a string, for now) TODO make actual patterns for these constants

pub fn multiply(terms: List(GleamStatement)) -> GleamStatement
pub fn name_of_var(var: GleamStatement) -> String
pub fn nil() -> GleamStatement
pub fn underscore() -> Pattern
pub fn unused_var(name: String) -> Pattern

name: variable name without the underscore, it will be prepended when generating code

pub fn use_arg(arg: Argument) -> GleamStatement
pub fn var_pattern(var: String) -> Pattern
pub fn variable(name: String) -> GleamStatement
pub fn variant(
  name: String,
  field_values: List(GleamStatement),
) -> GleamStatement
Search Document