Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Possible bug or oversight with list values and indentation #41

Open
bena-nasa opened this issue Dec 16, 2021 · 5 comments
Open

Possible bug or oversight with list values and indentation #41

bena-nasa opened this issue Dec 16, 2021 · 5 comments
Assignees

Comments

@bena-nasa
Copy link
Collaborator

bena-nasa commented Dec 16, 2021

I've been working on a script to generate a yaml input file for a project from the old version in a different format. I ended up creating a python script and creating a dictionary which I dump to a file with the Python yaml modules "dump" function to take a dictionary and emits it as a yaml text.
In my first attempt I generated a Yaml file that looked like this:

Version: 3

Enabled:
- geosgcm_prog

Grids:
  PC96x49-DC:
     grid_type: LatLon
     im_world: 360
     jm_world: 180
     lm: 72
     dateline: DE
     pole: PE

Groups:
  geosgcm_prog_group:
    fields:
      AGCM:
        PHIS: {}

Collections:
  geosgcm_prog:
    frequency: '060000'
    groups:
    - geosgcm_prog_group
    output_grid: PC96x49-DC
    template: '%y4%m2%d2_%h2%n2z.nc4'

When this was being ingested by Yafyaml however it crashed and spit out this error:

illegal token encountered C

I stared at the file for quite a while and could not see what was wrong. Finally after much starting and comparing to a file a I knew that worked the only thing I would see is that the yaml file above has keys who have values that are lists that are not indented (the Enable: key for example, same with groups under collections).

So I indented the lists like so

Version: 3

Enabled:
  - geosgcm_prog

Grids:
  PC96x49-DC:
     grid_type: LatLon
     im_world: 360
     jm_world: 180
     lm: 72
     dateline: DE
     pole: PE

Groups:
  geosgcm_prog_group:
    fields:
      AGCM:
        PHIS: {}

Collections:
  geosgcm_prog:
    frequency: '060000'
    groups:
      - geosgcm_prog_group
    output_grid: PC96x49-DC
    template: '%y4%m2%d2_%h2%n2z.nc4'

and Yafyaml was happy. At least as far as python's yaml implementation was concerned it must think that is valid yaml as that is what it produced via the "dump" function of the yaml library. So I'm guessing (still looking) that the first is valid Yaml that is not support by Yafyaml?

@bena-nasa
Copy link
Collaborator Author

@tclune
Copy link
Member

tclune commented Jan 3, 2022

Yup - needs a unit test as well. The parsing bit is ugly code conversion from Python, so probably far from obvious just what needs to change. We may have to live with this and/or write a converter script to add spaces before leading hyphens in your scenario.

@bena-nasa
Copy link
Collaborator Author

Yeah, I tried to fix it for a little while but just ended up breaking other things and gave up. For now I can create a script to add spaces. I also tried with futility to see if the python yaml emitter has any sort of formatting options to do this.

@tclune
Copy link
Member

tclune commented Jan 3, 2022

By comparing with the python source for managing indentation, I did spot that the problem may be with this function:

yaFyaml/src/Lexer.F90

Lines 568 to 572 in 6b9a50e

logical function is_block_next_entry(this)
class(Lexer), intent(inout) :: this
is_block_next_entry = (scan(this%peek(offset=1),WHITESPACE_CHARS) > 0)
end function is_block_next_entry

You could try playing with the 1 and 0 to see if they produce the desired behavior. Might break some unit tests, but it is just as possible the unit tests are wrong, so just see what you get.

@tclune
Copy link
Member

tclune commented Mar 16, 2022

@bena-nasa Did you ever attempt the change suggested above? I'm about to do some other work in this layer, so would be a good time to get the fix in (if we know what the fix is)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants