Skip to content

Support explicit type suffixes and inference for quoted typed literals #993

Description

@Seddryck

Purpose

Define a consistent syntax and resolution rule for quoted typed literals: #"representation":type. When the suffix is omitted, infer the type using registered literal parsers.

This issue focuses on literal parsing, resolution, diagnostics, and serialization. Runtime library loading, extension API compatibility, operator registration, coercion extensibility, and collection semantics are outside its scope.

Explicit type suffix

Support built-in types through the same syntax:

#"2025-12-16":date
#"2025-12-16T14:30:00":datetime
#"14:30:00":time
#"P2D":duration
  • Parse the quoted representation and optional :type suffix.
  • Resolve the suffix using the same type names as type inspection and coercion.
  • An explicit suffix selects the literal parser before interpreting the content; it is not a cast of an already inferred value.
  • Invoke only the selected type's literal parser. Report unknown types, types without quoted-literal support, and invalid representations without falling back to another type.
  • Use registered literal parsers so the resolution mechanism can accommodate additional types later. This does not require implementing runtime library loading.

For example, #94 will use #"1.25.0+abc":semver once that type is available. Implementing SemVer is not an acceptance criterion for this issue.

Inference without a suffix

For #"representation", try the registered literal parsers:

  • Exactly one accepting parser: return that typed value.
  • No accepting parser: report an invalid literal.
  • Multiple accepting parsers: report ambiguity, identify the matching types, and require an explicit suffix.
  • Registration order must never determine the result.
  • Use strict literal representation rules, independently of potentially more permissive runtime coercion.
  • Preserve existing unsuffixed temporal literal forms through inference. Ordinary quoted text remains text.

Adding a registered parser may make an unsuffixed literal ambiguous; document the explicit suffix as the remedy.

Serialization and failure behavior

  • Use #"representation":type as canonical serialization for quoted typed literals.
  • Preserve the intended type and value on round-trip when its literal parser is registered.
  • Match existing date-literal failure conventions at equivalent entry points.
  • Leave runtime coercion behavior unchanged.

Validation

  • Cover explicit built-in typed literals and existing unsuffixed temporal literals.
  • Cover zero, one, and multiple accepting parsers, using test parsers where needed.
  • Cover explicit disambiguation, unknown types, types without literal support, and invalid representations.
  • Verify inference is independent of registration order.
  • Verify canonical serialization round-trips even when another registered parser accepts the same representation.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    new-featureRequest for a new feature in the tool

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions