kowainik / tomland

🏝 Bidirectional TOML serialization
https://kowainik.github.io/posts/2019-01-14-tomland
Mozilla Public License 2.0
120 stars 39 forks source link

[RFC] Track position in file after parsing in TOML AST to produce better error messages #303

Open chshersh opened 4 years ago

chshersh commented 4 years ago

We have two stages for converting TOML to Haskell types:

  1. Parsing
  2. Decoding

Decoding works with a generic TOML representation. But this representation doesn't record the source positions of TOML entries from file. If we can come up with a way to track positions of TOML entries in files, we can improve the quality of error messages and instead of:

tomland decode error:  Type for key name doesn't match.
  Expected: Text
  Actual:   Integer

we can output something like this

tomland decode error:  Type for key name doesn't match.
  Expected: Text
  Actual:   Integer

example.toml
  3 |
  4 | name = 42
  5 | ^^^^^^^^^