Sign in

    moonrockz/gleam-parser/fuel does not have a README file

    FuelExhausted

    pub(all) suberror FuelExhausted {
    FuelExhausted(budget~ : Budget, spent~ : Array[Spent])
    } derive(Eq,
    Debug
    )

    The budget ran out: spent is the stack at that moment, outermost first.

    InvalidBudget

    pub(all) suberror InvalidBudget {
    InvalidBudget(Int)
    } derive(Eq,
    Debug
    )

    A recursion budget must contain at least one unit.

    Budget

    pub struct Budget {
    // private fields
    } derive(Compare, Eq,
    Debug
    )

    Units of fuel, at least 1.

    test {
    debug_inspect(
    @fuel.Budget::from_int(100).map(b => b.units()),
    content="Some(100)",
    )
    debug_inspect(@fuel.Budget::from_int(0), content="None")
    }

    Budget::Budget

    fn Budget::Budget(units : Int) -> Budget raise InvalidBudget

    Create a recursion budget. Raise InvalidBudget below one unit. Use from_int to get Option.

    test {
    assert_eq(@fuel.Budget(100).units(), 100)
    }

    Budget::from_int

    #alias(new, deprecated="Use `Budget::from_int(...)` instead")
    fn Budget::from_int(units : Int) -> Budget?

    A budget of units; None below 1.

    Budget::units

    fn Budget::units(self : Budget) -> Int

    The number of units.

    Fuel

    pub struct Fuel {
    budget : Budget
    left : Int
    ops :
    List
    [Operation]
    } derive(Eq,
    Debug
    )

    An immutable fuel value: the budget, the units not yet spent, and the operations on the stack (innermost first). spend gives a new value; there is no restore: the enclosing operation keeps its own Fuel.

    test {
    let f = @fuel.Fuel(budget=@fuel.Budget::from_int(2).unwrap())
    let inner = f.spend(@fuel.Operation("expression"))
    inspect(inner.left(), content="1")
    inspect(f.left(), content="2")
    }

    Fuel::Fuel

    #alias(new, deprecated="Use `Fuel(...)` instead")
    fn Fuel::Fuel(budget? : Budget) -> Fuel

    A full budget (default_budget when none is given).

    Fuel::budget

    fn Fuel::budget(self : Fuel) -> Budget

    The budget this fuel started with.

    Fuel::left

    fn Fuel::left(self : Fuel) -> Int

    The units not yet spent.

    Fuel::spend

    fn Fuel::spend(self : Fuel, op : Operation) -> Fuel raise FuelExhausted

    Enter a nested operation: one unit less, op on the stack. Raises FuelExhausted with the budget and the stack when no unit is left.

    Fuel::spent

    fn Fuel::spent(self : Fuel) -> Array[Spent]

    The distinct operations on the stack, outermost first, each with the number of levels it holds.

    NestingLimit

    pub(all) enum NestingLimit {
    Unlimited
    Limited(Budget)
    } derive(Eq,
    Debug
    )

    An optional limit on syntax nesting. Unlimited is the parser default. A finite limit is a caller policy and is independent of machine stack size.

    test {
    let limit : @fuel.NestingLimit = Limited(@fuel.Budget(500))
    debug_inspect(limit.budget().map(b => b.units()), content="Some(500)")
    debug_inspect(@fuel.NestingLimit::Unlimited.budget(), content="None")
    }

    NestingLimit::budget

    fn NestingLimit::budget(self : NestingLimit) -> Budget?

    Return the finite budget, or None when nesting is unrestricted.

    Operation

    pub(all) struct Operation(String) derive(Eq, Hash,
    Debug
    )

    The name of a fuel-checked operation (expression, pattern, ...). Each package that spends fuel defines its operations as constants.

    Operation::name

    fn Operation::name(self : Operation) -> String

    The operation's name.

    Operation::new

    #deprecated("Use `Operation(name)` instead")
    fn Operation::new(name : String) -> Operation

    Use Operation(name) to name a fuel-checked operation.

    Spent

    pub(all) struct Spent {
    operation : Operation
    levels : Int
    } derive(Eq,
    Debug
    )

    One operation on the stack with the number of nested levels it holds.

    default_budget

    let default_budget : Budget

    The finite budget used by Fuel() when no budget is supplied: 100 units. Parser and formatter configurations default to Unlimited instead.

    Powered by MoonBit

    Site sourceReport issuePackagesBuild queueSkillsStatistics

    © 2026 mooncakes.io