Sign in

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

    ProfileError

    pub(all) suberror ProfileError {
    InvalidIdentity(String)
    DuplicateProfile(String)
    MissingProfile(String)
    TargetConflict(name~ : String, existing~ : String, incoming~ : String)
    } derive(Eq,
    Debug
    )

    A profile cannot be registered or composed. Conflicts identify both providers. A missing profile names the identity requested by configuration.

    Dialect

    pub(all) struct Dialect {
    name : String
    keywords : ArrayView[
    Keyword
    ]
    attributes : ArrayView[String]
    targets :
    Registry

    profiles : ArrayView[Profile]
    deprecations : ArrayView[Rule]
    } derive(Eq,
    Debug
    )

    What the parser accepts: the reserved words, the attribute names (@external, …), the target names, and the deprecated syntax it warns about. Dialect::gleam_1_19() is the default and the only built-in.

    test {
    let d = @dialect.Dialect::gleam_1_19()
    inspect(d.knows_attribute("deprecated"), content="true")
    inspect(d.warns(DeprecatedListPrepend), content="true")
    }

    Dialect::from_version

    fn Dialect::from_version(version : String) -> Dialect?

    The built-in dialect for a Gleam version ("1.19"), or None.

    test {
    debug_inspect(
    @dialect.Dialect::from_version("1.19").map(d => d.version()),
    content="Some(\"1.19\")",
    )
    }

    Dialect::gleam_1_19

    fn Dialect::gleam_1_19() -> Dialect

    Gleam 1.19: the compiler's 22 reserved words, the four attributes, the two targets, and every deprecation warning on.

    Dialect::known_versions

    fn Dialect::known_versions() -> Array[String]

    The Gleam versions with a built-in dialect, as from_version reads them.

    Dialect::knows_attribute

    fn Dialect::knows_attribute(self : Dialect, name : String) -> Bool

    Whether this dialect accepts an attribute name without its @ prefix.

    Dialect::knows_target

    fn Dialect::knows_target(self : Dialect, name : String) -> Bool

    Whether this dialect accepts the canonical name of a target. Use targets.resolve(name, aliases=true) to include standard shorthands.

    Dialect::register_target

    Register an extension target in a new dialect. All other language rules stay the same. Raise RegistrationError::Conflict for a repeated identity.

    test {
    let orbit = @target.Target::extension("orbit")
    let dialect = @dialect.Dialect::gleam_1_19().register_target(orbit)
    assert_eq(dialect.knows_target("orbit"), true)
    }

    Dialect::reserves

    fn Dialect::reserves(self : Dialect, keyword :
    Keyword
    ) -> Bool

    Whether the parser treats a scanner keyword as reserved. Omitted keywords parse as names; scanner output remains unchanged.

    test {
    assert_eq(
    @dialect.Dialect::gleam_1_19().reserves(@scanner.Keyword::Echo),
    true,
    )
    }

    Dialect::version

    fn Dialect::version(self : Dialect) -> String

    The Gleam version this dialect follows ("1.19" for gleam-1.19).

    Dialect::warns

    fn Dialect::warns(self : Dialect, rule : Rule) -> Bool

    Whether this dialect emits warnings for the specified deprecation rule.

    Dialect::with_profile

    fn Dialect::with_profile(self : Dialect, profile : Profile) -> Dialect raise ProfileError

    Compose this dialect with a profile. Preserve the original dialect on success and failure. Compatible profiles commute; a repeated profile or target fails explicitly, with no override and no registration-order winner.

    Profile

    pub struct Profile {
    identity : String
    targets : ArrayView[
    Target
    ]
    } derive(Eq,
    Debug
    )

    A reusable, named set of extension target registrations. Profile modules construct this value through the same API as applications. Use a module-qualified identity with a version, such as example/orbit@1. No profile is installed or activated by constructing it.

    Profile::Profile

    fn Profile::Profile(identity : String, targets : ArrayView[
    Target
    ]) -> Profile raise ProfileError

    Validate a profile and copy its target list. Reject an empty identity, duplicate registrations, and attempts to register either standard identity. Standard aliases cannot be constructed as extension identities.

    test {
    let profile = @dialect.Profile(
    "example/orbit@1",
    [@target.Target::extension("orbit")][:],
    )
    let dialect = @dialect.Dialect::gleam_1_19().with_profile(profile)
    assert_eq(dialect.knows_target("orbit"), true)
    assert_eq(dialect.knows_target("unregistered"), false)
    }

    Profiles

    pub struct Profiles {
    available : ArrayView[Profile]
    } derive(Eq,
    Debug
    )

    An application-supplied registry of available profiles. It contains values, not module loaders. Standard parsing needs no profile registry.

    Profiles::Profiles

    fn Profiles::Profiles(available : ArrayView[Profile]) -> Profiles raise ProfileError

    Copy and validate the available profiles. Reject duplicate identities even when their registrations are identical, so lookup never depends on order.

    Profiles::apply

    fn Profiles::apply(self : Profiles, base : Dialect, identities : ArrayView[String]) -> Dialect raise ProfileError

    Apply named profiles in order to the supplied base dialect. Conflicts and missing identities raise ProfileError. The base remains unchanged.

    Profiles::empty

    fn Profiles::empty() -> Profiles

    No optional profiles are available. Lookup of any identity fails explicitly.

    Profiles::get

    fn Profiles::get(self : Profiles, identity : String) -> Profile raise ProfileError

    Find an available profile by its exact identity. Raise MissingProfile instead of loading code, consulting a global registry, or using a fallback.

    Rule

    pub(all) enum Rule {
    DeprecatedListPrepend
    DeprecatedListPattern
    DeprecatedListCatchAllPattern
    DeprecatedListSpreadAsVariablePattern
    DeprecatedRecordSpreadPattern
    DeprecatedEmptyClauseGuard
    DeprecatedTargetShorthand
    } derive(Eq, Hash,
    Debug
    )

    A deprecated-syntax rule the parser warns about: one per kind of the compiler's DeprecatedSyntaxWarning.

    Rule::all

    fn Rule::all() -> Array[Rule]

    Every supported deprecation rule in declaration order.

    Rule::name

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

    The rule's name, as a diagnostic names it.