Skip to content

Standard library: a TOML subset reader and printer #388

Open

Description

@afflom

Pinned at 387735155da3; origin/main (71defb4c6) and origin/release/v0.5 (ed549c24f) read. A feature request; nothing was run for it.

Problem

stdlib/src has no TOML member on either line. A LexLean program that reads a project's configuration, a lock, or a register must write its own codec.

afflom/rule30 is doing that: a module of about 440 lines, reading only, with no printer. It is not pushed yet.

Why here

#276 lists what the self-hosted compiler needs: canonical JSON, sorting, hex and decimal, maps and sets. #274 moves config.rs and lock.rs to language 1.2, and those call toml::from_str today (config.rs:458, lock.rs:292). lexlean.toml and lexlean.lock are TOML, so the driver needs a reader, and it needs a canonical writer for lexlean lock. Neither issue names this, unless it is implied by #274. So this may belong as a member of #276.

Proposal

A module LexLeanStd.Toml, in the shape of the #276 members:

The subset rule30 uses:

  • one key = value per line, with a bare key (A-Z a-z 0-9 _ -);
  • a value is a basic string on one line with the escapes \", \\, \n, \t; a one-line array of such strings, with a trailing comma allowed; or a decimal integer without sign, underscore or leading zero;
  • [[name]] opens a new table of the array name, and keys before the first header belong to the root table;
  • comments from #, blank lines, spaces and tabs around tokens, LF or CRLF line ends;
  • UTF-8 text; anything else is refused.

lexlean.toml also has a [limits] table, which this subset lacks, so the compiler's subset is at least that much wider. The committed locks I read use only [[...]] headers. I did not check config.rs and lock.rs in detail.

Open questions

  1. Should the subset be defined by what the compiler's own files use, or wider?
  2. Should this build on the Numeral member (#276 member 1 (SL-09): hexadecimal and decimal in the standard library (LexLeanStd.Numeral) — draft #326, merged to release/v0.4) and the Order member (#276 member 2 (SL-10): sorting and order in the standard library (LexLeanStd.Order) — draft #328, open)? Printing sorted keys and decimals would reuse them.

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

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions