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

Support to list of dicts? #12

Open
timonwong opened this issue Jun 29, 2016 · 3 comments
Open

Support to list of dicts? #12

timonwong opened this issue Jun 29, 2016 · 3 comments
Labels
bug Bugs and problems with poyo help wanted Tasks to be picked up by contributors

Comments

@timonwong
Copy link

It seems currently poyo doesn't support list of dicts, for example:

list_val:
  - key: key1
  - key: key2

Will be parsed intto:

{'list_val': ['key: key1', 'key: key2']}

And:

list_val:
  - key: key1
    value: value1
  - key: key2
    value: value2

Will just throw ValueError while parsing:

ValueError: Parent of ChildMixin instance needs to be a Container.

Is there any plan to support them?

I'm using poyo v0.4.0

@hackebrot
Copy link
Owner

Hi @timonwong, thank you for raising this issue! 🙇

I am currently very busy with working on pytest related things, so I'm not sure if or when I'll get to this. I'd love to see a PR from you on this though. So please feel free to give it a go and let me know if you need help.

Raphael

@hackebrot hackebrot added bug Bugs and problems with poyo help wanted Tasks to be picked up by contributors labels Jun 29, 2016
@mixmastamyk
Copy link

Also related, it does not support a list at the root of the document:

>>> parse_string('''
... - one
... - two
... - three
... ''')
Traceback (most recent call last):
  File "<stdin>", line 5, in <module>
  File "/usr/local/lib/python3.5/dist-packages/poyo/parser.py", line 241, in parse_string
    return parser()
  File "/usr/local/lib/python3.5/dist-packages/poyo/parser.py", line 234, in __call__
    match = self.find_match()
  File "/usr/local/lib/python3.5/dist-packages/poyo/parser.py", line 224, in find_match
    ''.format(self.source[self.pos:])
poyo.exceptions.NoMatchException: None of the known patterns match for …

PyYaml:

>>> from yaml import safe_load
>>> safe_load('''
... - one
... - two
... - three
... ''')
['one', 'two', 'three']

@tolidano
Copy link

tolidano commented Jul 3, 2023

I know this is very late, but I'm interested in using a single-file 0-dependency version of this library (which I will happily contribute back). One of the only issues preventing me from using it is this issue where a list item cannot be a section.

I would appreciate any pointers you can provide to help allow this modification. I started by looking here:

_LIST_VALUE = (
     _BLANK
     + r"-"
     + _BLANK
     + r"('.*?'|\".*?\"|[^#\n]+?)"
     + _INLINE_COMMENT
     + _OPT_NEWLINE
 )
 _LIST_ITEM = _BLANK_LINE + r"|" + _COMMENT + r"|" + _LIST_VALUE

 _LIST = _SECTION + r"(?P<items>(?:" + _LIST_ITEM + r")*" + _LIST_VALUE + r")"

I believe that what I'll want to do is modify the _LIST_VALUE definition in some way, so I tried various iterations on:

     _BLANK
     + r"-"
     + _BLANK
     + _MULTILINE_SECTION
     #+ r"('.*?'|\".*?\"|[^#\n]+?)"
     #+ _INLINE_COMMENT
     + _OPT_NEWLINE

Using _MULTILINE_STR or _MULTILINE_SECTION but always running into duplicate group definition errors.

Do you have any quick and dirty ideas how I might capture this properly?
Even if I can just get the entire representation after the dash and space as a single string, I would be able to just feed that back into parse_string and get that part of the dictionary, which I would be happy to do (even outside the initial parser run).

I will continue to tinker, but any assistance greatly appreciated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Bugs and problems with poyo help wanted Tasks to be picked up by contributors
Projects
None yet
Development

No branches or pull requests

4 participants