[Repo Assist] Add TOML type provider (TomlProvider)#1652
[Repo Assist] Add TOML type provider (TomlProvider)#1652github-actions[bot] wants to merge 7 commits intomainfrom
Conversation
Implements a new TomlProvider type provider for FSharp.Data that parses
TOML documents and provides strongly-typed access to their contents.
Architecture:
- FSharp.Data.Toml.Core: new runtime library containing
- TomlValue: discriminated union representing all TOML value types
(String, Integer, Float, Boolean, OffsetDateTime, LocalDateTime,
LocalDate, LocalTime, Array, Table)
- A hand-written recursive-descent TOML parser supporting:
- All TOML value types including dates, times and datetime offsets
- Tables [header] and arrays-of-tables [[header]]
- Dotted keys (a.b.c = value)
- Inline tables { key = value }
- Multiline basic strings and literal strings
- Hex/octal/binary integer literals
- Special float values (inf, -inf, nan)
- TomlDocument: wraps TomlValue and implements IJsonDocument by
converting TOML values to JSON values, enabling reuse of the
existing JSON type inference and runtime infrastructure
- FSharp.Data.DesignTime: new TomlProvider type provider
that uses the TOML parser for sample loading and the existing
JSON generator for code generation
TOML date/time values are serialized to ISO 8601 strings before
JSON inference, allowing the inference engine to correctly detect
them as DateTimeOffset, DateTime, or TimeSpan types.
Closes #1650
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
/repo-assist We need a new assembly of tests FSharp.Data.Toml.Core.Tests testing everything in src/FSharp.Data.Toml.Core thoroughly especially parsing |
…ix parser bugs (local date/time detection, uppercase hex integers) - New test project tests/FSharp.Data.Toml.Core.Tests/ with thorough coverage of: - All TomlValue union cases and ToJsonValue conversions - String parsing: basic, literal, multiline, escape sequences, unicode escapes - Numeric parsing: integers (decimal/hex/octal/binary/underscores), floats (inf/nan/exponent) - Date/time parsing: OffsetDateTime, LocalDateTime, LocalDate, LocalTime - Array parsing: empty, typed, trailing comma, multiline, nested, comments - Inline table parsing - Table headers [key] and [[array-of-tables]] - Dotted keys (a.b.c = value) - Error cases: duplicate keys, unterminated strings/arrays, invalid escapes - TryParse, Load from Stream/TextReader - TomlDocument.Create - _Print formatting - Fix parser bugs discovered by tests: - isDateLike condition now handles date-only (YYYY-MM-DD) and time-only (HH:MM:SS) values - Uppercase hex characters (A-F) now collected during token scanning - TimeSpan format strings corrected for TryParseExact (use hh\:mm\:ss not HH:mm:ss) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
Commit pushed:
|
|
🤖 This is an automated response from Repo Assist. Done! I've added the new What was addedNew project: Test coverage
Parser bugs fixed (discovered by tests)
All 95 tests pass. ✅
|
…r-cb9fc3e6dabf0af2
|
/repo-assist fix the build and test failures |
…erType The JsonInference.inferType function gained a new 'allowEmptyValues' bool parameter between 'cultureInfo' and 'parentName'. Update the call in TomlProvider.fs to pass 'true' (equivalent to 'not preferOptionals' default). Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
Commit pushed:
|
🤖 This is an automated pull request from Repo Assist.
Implements the feature requested in #1650 — a new
TomlProvidertype provider for FSharp.Data.What this adds
FSharp.Data.TomlProviderlets you write code like:Architecture
New project:
FSharp.Data.Toml.CoreTomlValue— a discriminated union representing all TOML value types:String,Integer,Float,Boolean,OffsetDateTime,LocalDateTime,LocalDate,LocalTime,Array,Table[header]and arrays-of-tables[[header]]a.b.c = value) and inline tables{ key = value }"""...""") and multiline literal strings ('''...''')0x), octal (0o), binary (0b) integer literalsinf,-inf,nan)TomlDocument— wrapsTomlValueand implementsIJsonDocumentby converting TOML values to their JSON equivalents (dates → ISO 8601 strings), enabling the existing JSON type inference and runtime code to be reusedModified:
FSharp.Data.DesignTimeTomlProvider— new type provider that parses TOML samples and calls into the JSON generator for type generation. SupportsSample,RootName,Culture,Encoding,ResolutionFolder,EmbeddedResource,InferenceMode,PreferDateOnly,UseOriginalNamesstatic parameters.Design decisions
The key insight is that TOML maps naturally onto JSON's type system. By converting
TomlValue→JsonValueat the boundary, we can reuse all of the existing JSON inference, code generation, and runtime infrastructure. TOML's first-class date/time types are serialized to ISO 8601 strings so the inference engine correctly detects them asDateTimeOffset,DateTime,DateOnly, orTimeOnly.Test Status
FSharp.Data.Toml.Corebuilds (bothnetstandard2.0andnet8.0)FSharp.Data.DesignTimebuilds with the newTomlProviderowner.dobinferred asSystem.DateTimeOffset✓products(from[[products]]) inferred as an array ✓colorfield (present in only some items) inferred asstring option✓Known limitations / future work
TOML spec compliance: the parser handles the common cases but edge cases (e.g. surrogate pair unicode escapes in multiline strings, all corner cases of the TOML 1.0 spec) may need additional work
No inline TOML schema support (unlike the JSON provider's
typeof<>syntax)TomlValuedoes not yet have a serializer (write-back to TOML text)No dedicated
FSharp.Data.TomlNuGet package metadata — would need a new.nuspec/ packaging projectFixes Add a TOML type provider #1650