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 parser's configuration.

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

    Config::default

    fn Config::default() -> Config

    Dialect::gleam_1_19() and @fuel.default_budget.

    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.

    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. Every key is optional. 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.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.

    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::new(500), }
    let env : @config.Partial = { dialect: None, fuel: @fuel.Budget::new(2000), }
    let c = env.with_fallback(file).to_config(@config.Config::default())
    inspect(c.fuel.units(), content="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