omcg/module
Types
The data content of a case branch.
pub type CaseBranchData {
CaseBranchData(
expression: Node,
guard: option.Option(Node),
body: List(Node),
)
}
Constructors
-
CaseBranchData( expression: Node, guard: option.Option(Node), body: List(Node), )
The field of a type variant.
pub type Field {
Field(name: option.Option(String), type_: Node)
}
Constructors
-
Field(name: option.Option(String), type_: Node)
The parameters of a function call.
pub type FunctionCallParameter {
FunctionCallParameter(
alias: option.Option(String),
value: Node,
)
}
Constructors
-
FunctionCallParameter(alias: option.Option(String), value: Node)
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
-
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, )
The parameters of a function definition.
pub type FunctionDefinitionParameter {
FunctionDefinitionParameter(
alias: option.Option(String),
name: String,
type_: option.Option(Node),
)
}
Constructors
-
FunctionDefinitionParameter( alias: option.Option(String), name: String, type_: option.Option(Node), )
Represents a gleam import statement.
pub type Import {
Import(
path: List(String),
items: List(ImportItem),
alias: option.Option(String),
)
}
Constructors
-
Import( path: List(String), items: List(ImportItem), alias: option.Option(String), )
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
-
ImportType(name: String, alias: option.Option(String)) -
ImportItem(name: String, alias: option.Option(String))
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
TrueorFalse. -
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
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
-
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
-
AccessAccess a field or property using the dot operator
. -
AddAddition operator
+ -
SubtractSubtraction operator
- -
MultiplyMultiplication operator
* -
DivideDivision operator
/ -
FloatAddFloating-point addition operator
+. -
FloatSubtractFloating-point subtraction operator
-. -
FloatDivideFloating-point division operator
/. -
FloatMultiplyFloating-point multiplication operator
*. -
StringConcatString concatenation operator
<> -
PipePipe operator
|>
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
-
TypeVariantNS( create: fn(String) -> Module, field: fn(Module, option.Option(String), Module) -> Module, )
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 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 let_definition: LetDefinitionNS
Namespace for creating and manipulating let definition nodes.
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 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 use_expression: UseExpressionNS
Namespace for creating and manipulating use expression nodes.