Closed stigrj closed 4 years ago
@bast and I agree that the parser should indeed stop. First step is to provide a test.
I poked a bit around in the code and it is asDict()
which swallows duplicates and keeps the last insert:
https://github.com/dev-cafe/parselglossy/blob/76fbecbf9479fd67b380bedd01ceeb85a7176a23/parselglossy/grammars/lexer.py#L74
What we would like to do is to detect duplicates and stop and duplicates are preserved when replacing asDict()
by asList()
.
But then one needs to recursively traverse a nested list to look for duplicate keys at the same level and this is where I got stuck: since with a nested list I did not know how to distinguish a key from a value (is ['foo', 'bar']
a foo: bar
key-value pair or is it a value ['foo', 'bar']
?)
One thing we could do is to flatten the list and flatten the dictionary and count the number of elements and if they are different, something was repeated but we would not be able to tell what.
I have this counting solution almost ready. PR coming up in not too long.
Description
Currently the following is allowed
and the last definition takes precedence. This should probably not be allowed.