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

How hard would it be to include support for { } and [ ]? #3

Open
Nicholaswogan opened this issue Apr 21, 2021 · 7 comments
Open

How hard would it be to include support for { } and [ ]? #3

Nicholaswogan opened this issue Apr 21, 2021 · 7 comments

Comments

@Nicholaswogan
Copy link

Really useful package. Thanks. I'm considering trying to add support for flow style dictionaries and lists using {} and [] . I'm just wondering how hard this would be?

@jornbr
Copy link
Member

jornbr commented Apr 21, 2021

Thanks for considering this - it has been on our wish list for a while. The starting point would be the read_value routine in yaml.F90, where you would determine whether the next character in the stream is a [ or {. That's similar to how block lists are detected and handled there:

if (file%line(1:2)=='- ') then

(it then repeatedly calls "read_value" to read list elements).

However, the read_value routine will likely need to be updated then to (optionally) operate in flow (rather than block) mode, and stop reading a new value when a , is encountered. Doable but not entirely trivial. If you'd like to give it a go, great! We probably should also look into putting together a test suite of yaml files then, and verify for instance whether they survive read-dump-read round-tripping.

Cheers,

Jorn

@Nicholaswogan
Copy link
Author

Thanks for the information! I might try to do this at some point in the next few weeks as I'm working on a project that depends on fortran-yaml.

@Nicholaswogan
Copy link
Author

I gave it a try. I was able to do almost any nested list in flow style, but had some problems with the very end of the last nested list. I did not try to do dictionaries. My attempt is attached.

Overall, I just added two if statements to read_value. The first if statement was to identify "[", the beginning of a new list, and the second is to read the values within a list. I added attributes to type_file, for keeping track of where you are in nested lists, as the parsing occurs.

I don't love what I have done, but maybe the overall approach is along the right lines.

yaml.F90.zip

@Nicholaswogan
Copy link
Author

@jornbr I used your type system with the parser in yaml-cpp to make a new package fortran-yaml-cpp. The API is nearly identical to fortran-yaml. But now it can deal with a flow style yaml.

@jornbr
Copy link
Member

jornbr commented Oct 8, 2021

That seems a great way to get more robust yaml parsing while still preserving compatibility with the fortran-yaml interfaces. That could be useful for my own applications too, particularly if the underlying C++ code is not too particular about compilers. I'll hope to take a close look soon.

@Nicholaswogan
Copy link
Author

I've tested the following two C++ and Fortran compiler combinations on MacOS. They both seem to work. I'll get around to testing other compiler combinations and OSs at some point.

  • Fortran compiler = GNU 11.2.0 and C++ compiler = AppleClang 12.0.5.12050022
  • Fortran compiler = GNU 11.2.0 and C++ compiler = GNU 11.2.0

@Nicholaswogan
Copy link
Author

@jornbr I am new to Licenses. What license should I put on fortran-yaml-cpp, so it does not violate fortran-yaml license. I also have another project which depend on fortran-yaml which I'm going to publish really soon. I want to use the proper license.

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