omcg/module

Types

The type representing the binary operation sub-module namespace.

pub type BinaryOperationNS {
  BinaryOperationNS(
    create: fn(Module, Operator, Module) -> Module,
    access: fn(Module, Module) -> Module,
    pipe: fn(Module, Module) -> Module,
    string_concat: fn(Module, Module) -> Module,
  )
}

Constructors

The type representing the builtin types sub-module namespace.

pub type BuiltinTypesNS {
  BuiltinTypesNS(
    string: fn() -> Module,
    int: fn() -> Module,
    float: fn() -> Module,
    bool: fn() -> Module,
  )
}

Constructors

The data content of a case branch.

pub type CaseBranchData {
  CaseBranchData(
    expression: Node,
    guard: option.Option(Node),
    body: List(Node),
  )
}

Constructors

The type representing the namespace for creating and manipulating case branch nodes.

pub type CaseBranchNS {
  CaseBranchNS(
    create: fn(Module) -> Module,
    create_default: fn() -> Module,
    add: fn(Module, Module) -> Module,
  )
}

Constructors

The type representing the namespace for creating and manipulating case expression nodes.

pub type CaseExpressionNS {
  CaseExpressionNS(
    create: fn(Module) -> Module,
    add: fn(Module, Module) -> Module,
  )
}

Constructors

The type representing the namespace for creating and manipulating const definition nodes.

pub type ConstDefinitionNS {
  ConstDefinitionNS(
    create: fn(String, Module) -> Module,
    public: fn(Module) -> Module,
    as_type: fn(Module) -> Module,
  )
}

Constructors

The field of a type variant.

pub type Field {
  Field(name: option.Option(String), type_: Node)
}

Constructors

The type representing the function call sub-module namespace.

pub type FunctionCallNS {
  FunctionCallNS(
    create: fn(Module) -> Module,
    add: fn(Module, Module) -> Module,
    add_with_alias: fn(Module, String, Module) -> Module,
  )
}

Constructors

The parameters of a function call.

pub type FunctionCallParameter {
  FunctionCallParameter(
    alias: option.Option(String),
    value: Node,
  )
}

Constructors

The type representing the function definition sub-module namespace.

pub type FunctionDefinitionNS {
  FunctionDefinitionNS(
    create: fn() -> Module,
    public: fn(Module) -> Module,
    with_name: fn(Module, String) -> Module,
    add_parameter: fn(Module, String, Module) -> Module,
    add_untyped_parameter: fn(Module, String) -> Module,
    add_aliased_parameter: fn(Module, String, String, Module) -> Module,
    with_return_type: fn(Module, Module) -> Module,
    add: fn(Module, Module) -> Module,
  )
}

Constructors

The parameters of a function definition.

pub type FunctionDefinitionParameter {
  FunctionDefinitionParameter(
    alias: option.Option(String),
    name: String,
    type_: option.Option(Node),
  )
}

Constructors

The type representing the identifier sub-module namespace.

pub type IdentifierNS {
  IdentifierNS(create: fn(String) -> Module, discard: Module)
}

Constructors

  • IdentifierNS(create: fn(String) -> Module, discard: Module)

Represents a gleam import statement.

pub type Import {
  Import(
    path: List(String),
    items: List(ImportItem),
    alias: option.Option(String),
  )
}

Constructors

Represents an item within a gleam import statement.

pub type ImportItem {
  ImportType(name: String, alias: option.Option(String))
  ImportItem(name: String, alias: option.Option(String))
}

Constructors

The type representing the namespace for creating and manipulating let definition nodes.

pub type LetDefinitionNS {
  LetDefinitionNS(
    create: fn(Module, Module) -> Module,
    type_: fn(Module, Module) -> Module,
  )
}

Constructors

The different types of literals.

pub type Literal {
  String(value: String)
  Int(value: Int)
  Float(value: Float)
  Bool(value: Bool)
  Tuple(value: List(Node))
  List(value: List(Node))
}

Constructors

  • String(value: String)

    A string literal "Hello, world!".

  • Int(value: Int)

    An integer literal 42.

  • Float(value: Float)

    A floating-point literal 3.14.

  • Bool(value: Bool)

    A boolean literal True or False.

  • Tuple(value: List(Node))

    A tuple literal #("a", 1, False).

  • List(value: List(Node))

    A list literal [1, 2, 3].

The type representing the literal sub-module namespace.

pub type LiteralNS {
  LiteralNS(
    string: fn(String) -> Module,
    int: fn(Int) -> Module,
    float: fn(Float) -> Module,
    bool: fn(Bool) -> Module,
    tuple: fn(List(Module)) -> Module,
    nested_tuple: fn(List(Module)) -> Module,
    list: fn(List(Module)) -> Module,
    nil: Module,
  )
}

Constructors

A module represents a node with associated (scoped) imports.

pub type Module {
  Module(node: Node, imports: List(Import))
}

Constructors

The different types of nodes in the abstract syntax tree.

pub type Node {
  Root(body: List(Node))
  FunctionDefinition(
    public: Bool,
    name: option.Option(String),
    parameters: List(FunctionDefinitionParameter),
    return_type: option.Option(Node),
    body: List(Node),
  )
  BinaryOperation(lhs: Node, operator: Operator, rhs: Node)
  Identifier(name: String)
  FunctionCall(
    lhs: Node,
    parameters: List(FunctionCallParameter),
  )
  TypeVariant(data: TypeVariantData)
  TypeDefinition(
    public: Bool,
    name: String,
    generics: List(String),
    variants: List(TypeVariantData),
  )
  ConstDefinition(
    public: Bool,
    as_type: Bool,
    name: String,
    value: Node,
  )
  CaseBranch(data: CaseBranchData)
  CaseExpression(
    expression: Node,
    branches: List(CaseBranchData),
  )
  UseExpression(parameters: List(String), rhs: Node)
  Literal(literal: Literal)
  SectionComment(comment: String)
  LetDefinition(
    pattern: Node,
    type_: option.Option(Node),
    value: Node,
  )
}

Constructors

  • Root(body: List(Node))

    A root node containing the entire body of the program.

  • FunctionDefinition(
      public: Bool,
      name: option.Option(String),
      parameters: List(FunctionDefinitionParameter),
      return_type: option.Option(Node),
      body: List(Node),
    )

    A function definition node

  • BinaryOperation(lhs: Node, operator: Operator, rhs: Node)

    A binary operation

  • Identifier(name: String)

    An identifier node representing a variable, function, type or module.

  • FunctionCall(lhs: Node, parameters: List(FunctionCallParameter))

    A function call node.

  • TypeVariant(data: TypeVariantData)

    The variant of a type definition.

  • TypeDefinition(
      public: Bool,
      name: String,
      generics: List(String),
      variants: List(TypeVariantData),
    )

    A type definition node

  • ConstDefinition(
      public: Bool,
      as_type: Bool,
      name: String,
      value: Node,
    )

    Definition of a constant.

  • CaseBranch(data: CaseBranchData)

    The branch of a case expression.

  • CaseExpression(expression: Node, branches: List(CaseBranchData))

    A case expression node.

  • UseExpression(parameters: List(String), rhs: Node)

    A use expression node.

  • Literal(literal: Literal)

    A literal node.

  • SectionComment(comment: String)

    A section comment node. (Non-idiomatic gleam)

  • LetDefinition(
      pattern: Node,
      type_: option.Option(Node),
      value: Node,
    )

    The definition of a let-variable.

The different operators that can be used in binary operations.

pub type Operator {
  Access
  Add
  Subtract
  Multiply
  Divide
  FloatAdd
  FloatSubtract
  FloatDivide
  FloatMultiply
  StringConcat
  Pipe
}

Constructors

  • Access

    Access a field or property using the dot operator .

  • Add

    Addition operator +

  • Subtract

    Subtraction operator -

  • Multiply

    Multiplication operator *

  • Divide

    Division operator /

  • FloatAdd

    Floating-point addition operator +.

  • FloatSubtract

    Floating-point subtraction operator -.

  • FloatDivide

    Floating-point division operator /.

  • FloatMultiply

    Floating-point multiplication operator *.

  • StringConcat

    String concatenation operator <>

  • Pipe

    Pipe operator |>

The type representing the root sub-module namespace.

pub type RootNS {
  RootNS(
    create: fn() -> Module,
    add: fn(Module, Module) -> Module,
  )
}

Constructors

The type representing the type definition sub-module namespace.

pub type TypeDefinitionNS {
  TypeDefinitionNS(
    create: fn(String) -> Module,
    public: fn(Module) -> Module,
    add: fn(Module, Module) -> Module,
  )
}

Constructors

The data content of a type variant.

pub type TypeVariantData {
  TypeVariantData(name: String, fields: List(Field))
}

Constructors

  • TypeVariantData(name: String, fields: List(Field))

The type representing the type variant sub-module namespace.

pub type TypeVariantNS {
  TypeVariantNS(
    create: fn(String) -> Module,
    field: fn(Module, option.Option(String), Module) -> Module,
  )
}

Constructors

The type representing the namespace for creating and manipulating use expression nodes.

pub type UseExpressionNS {
  UseExpressionNS(
    create: fn(Module) -> Module,
    add: fn(Module, String) -> Module,
  )
}

Constructors

Values

pub fn add_aliased_import(
  module module: Module,
  path path: List(String),
  alias alias: String,
) -> Module

Adds a new aliased import to the module.

add_aliased_import(
  module:, 
  path: ["gleam", "option"], 
  alias: "opt"
)
// –––––––––––– Becomes –––––––––––– //
import gleam/option as opt
pub fn add_aliased_item_import(
  module module: Module,
  path path: List(String),
  name name: String,
  alias alias: String,
) -> Module

Adds a new aliased item import to the module.

add_aliased_item_import(
  module:, 
  path: ["gleam", "option"], 
  name: "Some", 
  alias: "S"
)
// –––––––––––– Becomes –––––––––––– //
import gleam/option.{Some as S}
pub fn add_aliased_type_import(
  module module: Module,
  path path: List(String),
  name name: String,
  alias alias: String,
) -> Module

Adds a new aliased type import to the module.

add_aliased_type_import(
  module:, 
  path: ["gleam", "option"], 
  name: "Option", 
  alias: "Opt"
)
// –––––––––––– Becomes –––––––––––– //
import gleam/option.{type Option as Opt}
pub fn add_import(
  module module: Module,
  path path: List(String),
) -> Module

Adds a new import statement to the module.

add_import(module, ["some", "module"])
// –––––––––––– Becomes –––––––––––– //
import some/module
pub fn add_item_import(
  module module: Module,
  path path: List(String),
  name name: String,
) -> Module

Adds a new item import to the module.

add_item_import(module, ["gleam", "option"], "Some")
// –––––––––––– Becomes –––––––––––– //
import gleam/option.{Some}
pub fn add_type_import(
  module module: Module,
  path path: List(String),
  name name: String,
) -> Module

Adds a new type import to the module.

add_type_import(module, ["gleam", "option"], "Option")
// –––––––––––– Becomes –––––––––––– //
import gleam/option.{type Option}
pub const binop: BinaryOperationNS

The namespace for the binary operation sub-module.

pub const case_branch: CaseBranchNS

Namespace for creating and manipulating case branch nodes.

pub const case_expression: CaseExpressionNS

Namespace for creating and manipulating case expression nodes.

pub const const_definition: ConstDefinitionNS

Namespace for creating and manipulating const definition nodes.

pub const function_call: FunctionCallNS

The namespace for the function call sub-module.

pub const function_definition: FunctionDefinitionNS

The namespace for the function definition sub-module.

pub const identifier: IdentifierNS

The namespace for the identifier sub-module.

pub const let_definition: LetDefinitionNS

Namespace for creating and manipulating let definition nodes.

pub const literal: LiteralNS

The namespace for the literal sub-module.

pub fn module_imports_to_string(module: Module) -> String

Converts a module’s imports to a string. Does not include the module’s node.

pub fn module_node_to_string(module: Module) -> String

Converts a module’s node to a string. Does not include imports.

pub fn node_to_string(node: Node, indent: Int) -> String

Converts a node to its string representation with the given indentation.

pub const root: RootNS

The namespace for the root sub-module.

pub fn section_comment(comment: String) -> Module

Creates a new section comment node with the given comment.

pub fn to_string(module: Module) -> String

Converts a module to a string, including both its imports and its node.

pub const type_definition: TypeDefinitionNS

The namespace for the type definition sub-module.

pub const type_variant: TypeVariantNS

The namespace for the type variant sub-module.

pub const types: BuiltinTypesNS

The namespace for the builtin types sub-module.

pub const use_expression: UseExpressionNS

Namespace for creating and manipulating use expression nodes.

✨ Search Document