Sign in

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

    ConfigError

    pub(all) suberror ConfigError {
    ConfigError(source~ : Source, message~ : String)
    } derive(Eq,
    Debug
    )

    A configuration value that cannot be used. Nothing falls back silently.

    Config

    The dialect and optional nesting policy for parsing and formatting. fuel: Unlimited accepts any depth that fits in available memory. Use Limited(Budget(...)) to impose a caller-selected depth limit.

    test {
    let c = @config.Config::default()
    debug_inspect(c.fuel, content="Unlimited")
    inspect(c.dialect.name, content="gleam-1.19")
    }

    Config::default

    fn Config::default() -> Config

    Dialect::gleam_1_19() with unlimited nesting.

    Config::from_env

    fn Config::from_env(env : Environment) -> Partial raise ConfigError

    GLEAM_PARSER_GLEAM and GLEAM_PARSER_FUEL from env. An unset variable leaves the field unset; an empty or bad value is a ConfigError that names the variable. GLEAM_PARSER_FUEL=unlimited clears a fallback's finite limit.

    Config::from_toml

    fn Config::from_toml(text : String) -> Partial raise ConfigError

    The [parser] table of a gleam-parser.toml text: gleam = "1.19", fuel = 100 or fuel = "unlimited". Every key is optional. An omitted fuel key inherits the fallback. The default is unlimited. A syntax error, an unknown table or key, a value of the wrong type, a fuel below 1 or an unknown Gleam version is a ConfigError that names its source.

    test {
    let p = @config.Config::from_toml("[parser]\nfuel = 550\n")
    debug_inspect(
    p.fuel.bind(limit => limit.budget()).map(b => b.units()),
    content="Some(550)",
    )
    inspect(p.dialect is None, content="true")
    }

    Config::load

    fn Config::load(path? : String, env? : Environment) -> Config raise ConfigError

    The configuration from the environment over the TOML file over the defaults. path is gleam-parser.toml by default; a missing file contributes nothing, a file that cannot be read is a ConfigError with File(path) and the system's text, and a TOML error from the file names the file in front of its message. The only function of this package with I/O.

    fn parse_with_config(text : String) -> @gleam.ParseResult raise {
    let config = @gleam.Config::load()
    @gleam.parse_text(text, config~)
    }

    Config::to_partial

    fn Config::to_partial(self : Config) -> Partial

    Every field set.

    Config::with_fallback

    fn Config::with_fallback(self : Config, over : Partial) -> Config

    over's set fields replace this config's fields.

    Environment

    pub struct Environment((String) -> String?)

    The variables a configuration reads: the process environment, or a map (for tests and for callers that bring their own).

    Environment::get

    fn Environment::get(self : Environment, name : String) -> String?

    The value of the variable name, or None when it is not set.

    Environment::of

    fn Environment::of(vars : Map[String, String]) -> Environment

    A fixed set of variables.

    Environment::system

    fn Environment::system() -> Environment

    The process environment (@env.get_env_var), on every target.

    Partial

    A layer of configuration: each field set or unset. Some(Unlimited) clears a fallback's limit; None inherits it.

    Partial::empty

    fn Partial::empty() -> Partial

    No field set.

    Partial::to_config

    fn Partial::to_config(self : Partial, fallback : Config) -> Config

    A full config: unset fields come from fallback.

    Partial::with_fallback

    fn Partial::with_fallback(self : Partial, fallback : Partial) -> Partial

    This layer's set fields win; unset fields come from fallback.

    test {
    let file : @config.Partial = {
    dialect: None,
    fuel: @fuel.Budget::from_int(500).map(b => Limited(b)),
    }
    let env : @config.Partial = {
    dialect: None,
    fuel: @fuel.Budget::from_int(2000).map(b => Limited(b)),
    }
    let c = env.with_fallback(file).to_config(@config.Config::default())
    debug_inspect(c.fuel.budget().map(b => b.units()), content="Some(2000)")
    }

    Source

    pub(all) enum Source {
    Default
    TomlKey(String)
    TomlSyntax
    EnvVar(String)
    File(String)
    Caller
    } derive(Eq,
    Debug
    )

    Where a configuration value came from; an error names it.

    Powered by MoonBit

    Site sourceReport issuePackagesBuild queueSkillsStatistics

    © 2026 mooncakes.io