Packages
WebAssembly is a web DSL for Elixir. You create html structure straight using do blocks. Means, you can intermix html-building blocks with full Elixir syntax. DSL output is an iolist, which you can flatten to string, but better use is to just feed it to the socket (via Plug & Cowboy). WebAssem...
Current section
Files
Jump to
Current section
Files
lib/core.ex
alias WebAssembly.Core
defmodule Core do
@moduledoc """
Module encapsulating assembly state `WebAssembly.Core.St` and tools around it.
"""
defmodule St do
@moduledoc """
State of markup assembly in the current scope.
"""
require WebAssembly.Types, as: T
defstruct stack: []
@opaque t :: %St{stack: [T.content]}
@doc """
Creates new empty state.
"""
@spec new() :: t
def new, do: %__MODULE__{}
@doc """
Pushes `value` into the `state`.
"""
@spec push(t, T.content) :: t
def push(%{stack: s} = state, value) do
%{state | stack: [value|s]}
end
@doc """
Releases the `state`, returning values in the order of pushing.
"""
@spec release(t) :: [T.content]
def release(%{stack: s} = _state), do: Enum.reverse(s)
end
end