Nadrieril / dhall-rust

Maintainable configuration files, for Rust users
Other
303 stars 27 forks source link

parse records with keywords as keys #163

Closed amesgen closed 4 years ago

amesgen commented 4 years ago
{ if : Text }
dhall-rust error message ```rust Err( Error( Dhall( Error { kind: Parse( Error { variant: ParsingError { positives: [ empty_record_literal, non_empty_record_type_or_literal, ], negatives: [], }, location: Pos( 2, ), line_col: Pos( ( 1, 3, ), ), path: None, line: "{ if : Text }", continued_line: None, }, ), }, ), ), ) ```

dhall-haskell allows this, and to my understanding the standard allows this too.

amesgen commented 4 years ago

Also see travisbrown/dhallj#17, I think I am wrong about standard conformance.

Nadrieril commented 4 years ago

I think the Haskell impl is not standard-compliant on this, see https://github.com/dhall-lang/dhall-lang/blob/master/standard/dhall.abnf#L227 . The reason is that even though keywords are not ambiguous when defining records, they might be when accessing fields like foo.if

Nadrieril commented 4 years ago

Hmm, dhall-rust also fails to parse this (with a slightly weird error message):

I recommend you format the error using its Display impl rather than Debug, then it gets pretty.

amesgen commented 4 years ago

Yes, then it gets prettier, but I should have clarified that I found it "slightly weird" that it is not mentioned that the if key is the reason for the parsing failure (but this is entirely unrelated to this issue, and it would fit in #40 at most).

 --> 1:3
  |
1 | { if : Text }
  |   ^---
  |
  = expected empty_record_literal or non_empty_record_type_or_literal

(this is extreme nitpicking, sry)

amesgen commented 4 years ago

Closing this, as this is a bug in dhall-haskell.

Nadrieril commented 4 years ago

Ah yeah, error messages are terrible, and in particular parse error messages are abysmal. Sadly short of writing the parser from scratch by hand I don' tknow how to make that better