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

end commas when patching #105

Open
2wyck3d opened this issue Jul 16, 2019 · 5 comments
Open

end commas when patching #105

2wyck3d opened this issue Jul 16, 2019 · 5 comments

Comments

@2wyck3d
Copy link

2wyck3d commented Jul 16, 2019

When patching a existing namelist with trailing commas, the commas are not preserved.

I tried a similar technique to #79 and it did not work

patch = {
    'data': {
        'a': 1,
        'b'': 2
    },
    '_end_comma': True
}

f90nml.patch('input_file.inp', patch, 'output_file.out')

I've also tried patching with a Namelist object, which also does not work.

nml = f90nml.namelist.Namelist()
nml.end_comma = True
nml['data'] = {'a': 1, 'b': 2}

parser = f90nml.Parser()
parser.read('input_file.inp', patch, 'output_file.out')

Is there something perhaps I'm missing or is this feature not available yet?

Thanks!

@marshallward
Copy link
Owner

I'm pretty sure it's just never been implemented. It would not be too difficult to add it, though. I'll have a look tonight.

@2wyck3d
Copy link
Author

2wyck3d commented Jul 16, 2019

Sweet. Thank you!

@marshallward
Copy link
Owner

I've just realized that this is not a simple change. This is because patch is not creating a new data output. Rather, it's catching the input stream, modifying the values, and then streaming that data to the output.

To do this correctly, we'd also have to know that we're at the end of a record, which may not be possible since the current patch may have already written its output.

This is a limitation of patch that I was hoping to address with more aggressive lookahead and a new parser, but that project has been stalled for a long time.

I'll have a bit deeper look and see if this one is easy enough to catch, but just a heads up that it may not be simple, if even possible.

@2wyck3d
Copy link
Author

2wyck3d commented Jul 17, 2019

Thanks for the update. Appreciate you looking into this. Would be awesome if this could be implemented but I understand if the amount of work involved to get there isn't worth it.

@marshallward
Copy link
Owner

No worries, I will keep the issue open as a feature request.

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

No branches or pull requests

2 participants