dhall-haskell icon indicating copy to clipboard operation
dhall-haskell copied to clipboard

dhall-to-yaml faulty output corner cases?

Open jonathn opened this issue 4 years ago • 5 comments

  1. dhall-to-yaml doesn't quote string scalars ending in : (breaks some yaml parsers).
  2. dhall-to-yaml doesn't quote string keys or string scalars ending in space.
  3. dhall-to-yaml unnecessarily quotes keys consisting of one or more letter e.

I don't think the --quoted option should be required to avoid the weirdness.

$ dhall-to-yaml --version
1.7.0

$ dhall-to-yaml <<< '{ pp = "one:", qq = "one: ", rr = ":two", ss = "one:two", tt = "one two", uu = "1", vv = 1 }'
pp: one:
qq: one:
rr: ":two"
ss: one:two
tt: one two
uu: '1'
vv: 1
$ dhall-to-yaml <<< '{ pp = "one:", qq = "one: ", rr = ":two", ss = "one:two", tt = "one two", uu = "1", vv = 1 }' | python -c 'import sys; import yaml; print(yaml.safe_load(sys.stdin))'
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/nix/store/bbqm4vg2jaiyq8p8hscjjq0hgw1cwcvf-python3.7-pyyaml-5.3.1/lib/python3.7/site-packages/yaml/__init__.py", line 162, in safe_load
    return load(stream, SafeLoader)
  File "/nix/store/bbqm4vg2jaiyq8p8hscjjq0hgw1cwcvf-python3.7-pyyaml-5.3.1/lib/python3.7/site-packages/yaml/__init__.py", line 114, in load
    return loader.get_single_data()
  File "/nix/store/bbqm4vg2jaiyq8p8hscjjq0hgw1cwcvf-python3.7-pyyaml-5.3.1/lib/python3.7/site-packages/yaml/constructor.py", line 49, in get_single_data
    node = self.get_single_node()
  File "/nix/store/bbqm4vg2jaiyq8p8hscjjq0hgw1cwcvf-python3.7-pyyaml-5.3.1/lib/python3.7/site-packages/yaml/composer.py", line 36, in get_single_node
    document = self.compose_document()
  File "/nix/store/bbqm4vg2jaiyq8p8hscjjq0hgw1cwcvf-python3.7-pyyaml-5.3.1/lib/python3.7/site-packages/yaml/composer.py", line 55, in compose_document
    node = self.compose_node(None, None)
  File "/nix/store/bbqm4vg2jaiyq8p8hscjjq0hgw1cwcvf-python3.7-pyyaml-5.3.1/lib/python3.7/site-packages/yaml/composer.py", line 84, in compose_node
    node = self.compose_mapping_node(anchor)
  File "/nix/store/bbqm4vg2jaiyq8p8hscjjq0hgw1cwcvf-python3.7-pyyaml-5.3.1/lib/python3.7/site-packages/yaml/composer.py", line 127, in compose_mapping_node
    while not self.check_event(MappingEndEvent):
  File "/nix/store/bbqm4vg2jaiyq8p8hscjjq0hgw1cwcvf-python3.7-pyyaml-5.3.1/lib/python3.7/site-packages/yaml/parser.py", line 98, in check_event
    self.current_event = self.state()
  File "/nix/store/bbqm4vg2jaiyq8p8hscjjq0hgw1cwcvf-python3.7-pyyaml-5.3.1/lib/python3.7/site-packages/yaml/parser.py", line 428, in parse_block_mapping_key
    if self.check_token(KeyToken):
  File "/nix/store/bbqm4vg2jaiyq8p8hscjjq0hgw1cwcvf-python3.7-pyyaml-5.3.1/lib/python3.7/site-packages/yaml/scanner.py", line 116, in check_token
    self.fetch_more_tokens()
  File "/nix/store/bbqm4vg2jaiyq8p8hscjjq0hgw1cwcvf-python3.7-pyyaml-5.3.1/lib/python3.7/site-packages/yaml/scanner.py", line 223, in fetch_more_tokens
    return self.fetch_value()
  File "/nix/store/bbqm4vg2jaiyq8p8hscjjq0hgw1cwcvf-python3.7-pyyaml-5.3.1/lib/python3.7/site-packages/yaml/scanner.py", line 579, in fetch_value
    self.get_mark())
yaml.scanner.ScannerError: mapping values are not allowed here
  in "<stdin>", line 1, column 8

$ dhall-to-yaml <<< '{ `pp ` = "one " }'
pp : one
$ dhall-to-yaml <<< '{ `pp ` = "one " }' | python -c 'import sys; import yaml; print(yaml.safe_load(sys.stdin))'
{'pp': 'one'}

$ dhall-to-yaml <<< '{ d = 1, dd = 1, e = 1, ee = 1, eee = 1, f = 1, ff = 1 }'
d: 1
dd: 1
'e': 1
'ee': 1
'eee': 1
f: 1
ff: 1

jonathn avatar Jul 22 '20 19:07 jonathn

Thanks for the report! I think all of these issues stem from the YAML renderer used in dhall-to-yaml, which is aeson-yaml. Could you pass this on?

As a workaround, you could try using an alternative Dhall to YAML converter, dhall-to-yaml-ng from the dhall-yaml package, that might handle these cases better.

sjakobi avatar Jul 22 '20 19:07 sjakobi

I have a pull request up to fix aeson-yaml here: https://github.com/clovyr/aeson-yaml/pull/9

Gabriella439 avatar Jul 23 '20 01:07 Gabriella439

Edit: moved the comment to https://github.com/clovyr/aeson-yaml/issues/12

paulrbr-fl avatar Aug 14 '20 16:08 paulrbr-fl