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

Key-value inside an array throws pyparsing exception if we use = instead of : #107

Open
israel-lugo opened this issue Dec 1, 2016 · 1 comment
Assignees
Labels

Comments

@israel-lugo
Copy link

israel-lugo commented Dec 1, 2016

This example:

foo = [
  bar = { baz=1 }
]

With this code:

import pyhocon
conf = pyhocon.ConfigFactory.parse_file("test.conf")

Causes:

pyparsing.ParseException: Expected "]" (at char 14), (line:2, col:7)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/capi/.local/lib64/python3.4/site-packages/pyhocon/config_parser.py", line 51, in parse_file
    return ConfigFactory.parse_string(content, os.path.dirname(filename), resolve)
  File "/home/capi/.local/lib64/python3.4/site-packages/pyhocon/config_parser.py", line 90, in parse_string
    return ConfigParser().parse(content, basedir, resolve)
  File "/home/capi/.local/lib64/python3.4/site-packages/pyhocon/config_parser.py", line 272, in parse
    config = config_expr.parseString(content, parseAll=True)[0]
  File "/usr/lib64/python3.4/site-packages/pyparsing.py", line 1613, in parseString
    raise exc
  File "/usr/lib64/python3.4/site-packages/pyparsing.py", line 1603, in parseString
    loc, tokens = self._parse( instring, 0 )
  File "/usr/lib64/python3.4/site-packages/pyparsing.py", line 1375, in _parseNoCache
    loc,tokens = self.parseImpl( instring, preloc, doActions )
  File "/usr/lib64/python3.4/site-packages/pyparsing.py", line 3283, in parseImpl                                                                                                                                                                                              
    loc, exprtokens = e._parse( instring, loc, doActions )                                                                                                                                                                                                                     
  File "/usr/lib64/python3.4/site-packages/pyparsing.py", line 1375, in _parseNoCache                                                                                                                                                                                          
    loc,tokens = self.parseImpl( instring, preloc, doActions )                                                                                                                                                                                                                 
  File "/usr/lib64/python3.4/site-packages/pyparsing.py", line 3418, in parseImpl                                                                                                                                                                                              
    ret = e._parse( instring, loc, doActions )                                                                                                                                                                                                                                 
  File "/usr/lib64/python3.4/site-packages/pyparsing.py", line 1375, in _parseNoCache                                                                                                                                                                                          
    loc,tokens = self.parseImpl( instring, preloc, doActions )                                                                                                                                                                                                                 
  File "/usr/lib64/python3.4/site-packages/pyparsing.py", line 3605, in parseImpl                                                                                                                                                                                              
    return self.expr._parse( instring, loc, doActions, callPreParse=False )                                                                                                                                                                                                    
  File "/usr/lib64/python3.4/site-packages/pyparsing.py", line 1375, in _parseNoCache                                                                                                                                                                                          
    loc,tokens = self.parseImpl( instring, preloc, doActions )                                                                                                                                                                                                                 
  File "/usr/lib64/python3.4/site-packages/pyparsing.py", line 3811, in parseImpl                                                                                                                                                                                              
    return super(ZeroOrMore, self).parseImpl(instring, loc, doActions)                                                                                                                                                                                                         
  File "/usr/lib64/python3.4/site-packages/pyparsing.py", line 3735, in parseImpl                                                                                                                                                                                              
    loc, tokens = self_expr_parse( instring, loc, doActions, callPreParse=False )                                                                                                                                                                                              
  File "/usr/lib64/python3.4/site-packages/pyparsing.py", line 1375, in _parseNoCache                                                                                                                                                                                          
    loc,tokens = self.parseImpl( instring, preloc, doActions )                                                                                                                                                                                                                 
  File "/usr/lib64/python3.4/site-packages/pyparsing.py", line 3418, in parseImpl                                                                                                                                                                                              
    ret = e._parse( instring, loc, doActions )                                                                                                                                                                                                                                 
  File "/usr/lib64/python3.4/site-packages/pyparsing.py", line 1375, in _parseNoCache                                                                                                                                                                                          
    loc,tokens = self.parseImpl( instring, preloc, doActions )                                                                                                                                                                                                                 
  File "/usr/lib64/python3.4/site-packages/pyparsing.py", line 3605, in parseImpl                                                                                                                                                                                              
    return self.expr._parse( instring, loc, doActions, callPreParse=False )                                                                                                                                                                                                    
  File "/usr/lib64/python3.4/site-packages/pyparsing.py", line 1375, in _parseNoCache                                                                                                                                                                                          
    loc,tokens = self.parseImpl( instring, preloc, doActions )                                                                                                                                                                                                                 
  File "/usr/lib64/python3.4/site-packages/pyparsing.py", line 3605, in parseImpl                                                                                                                                                                                              
    return self.expr._parse( instring, loc, doActions, callPreParse=False )                                                                                                                                                                                                    
  File "/usr/lib64/python3.4/site-packages/pyparsing.py", line 1375, in _parseNoCache                                                                                                                                                                                          
    loc,tokens = self.parseImpl( instring, preloc, doActions )                                                                                                                                                                                                                 
  File "/usr/lib64/python3.4/site-packages/pyparsing.py", line 3274, in parseImpl                                                                                                                                                                                              
    loc, exprtokens = e._parse( instring, loc, doActions )                                                                                                                                                                                                                     
  File "/usr/lib64/python3.4/site-packages/pyparsing.py", line 1375, in _parseNoCache                                                                                                                                                                                          
    loc,tokens = self.parseImpl( instring, preloc, doActions )                                                                                                                                                                                                                 
  File "/usr/lib64/python3.4/site-packages/pyparsing.py", line 3418, in parseImpl                                                                                                                                                                                              
    ret = e._parse( instring, loc, doActions )                                                                                                                                                                                                                                 
  File "/usr/lib64/python3.4/site-packages/pyparsing.py", line 1375, in _parseNoCache                                                                                                                                                                                          
    loc,tokens = self.parseImpl( instring, preloc, doActions )                                                                                                                                                                                                                 
  File "/usr/lib64/python3.4/site-packages/pyparsing.py", line 3274, in parseImpl                                                                                                                                                                                              
    loc, exprtokens = e._parse( instring, loc, doActions )                                                                                                                                                                                                                     
  File "/usr/lib64/python3.4/site-packages/pyparsing.py", line 1375, in _parseNoCache                                                                                                                                                                                          
    loc,tokens = self.parseImpl( instring, preloc, doActions )                                                                                                                                                                                                                 
  File "/usr/lib64/python3.4/site-packages/pyparsing.py", line 3605, in parseImpl                                                                                                                                                                                              
    return self.expr._parse( instring, loc, doActions, callPreParse=False )                                                                                                                                                                                                    
  File "/usr/lib64/python3.4/site-packages/pyparsing.py", line 1375, in _parseNoCache                                                                                                                                                                                          
    loc,tokens = self.parseImpl( instring, preloc, doActions )
  File "/usr/lib64/python3.4/site-packages/pyparsing.py", line 3811, in parseImpl
    return super(ZeroOrMore, self).parseImpl(instring, loc, doActions)
  File "/usr/lib64/python3.4/site-packages/pyparsing.py", line 3735, in parseImpl
    loc, tokens = self_expr_parse( instring, loc, doActions, callPreParse=False )
  File "/usr/lib64/python3.4/site-packages/pyparsing.py", line 1375, in _parseNoCache
    loc,tokens = self.parseImpl( instring, preloc, doActions )
  File "/usr/lib64/python3.4/site-packages/pyparsing.py", line 3418, in parseImpl
    ret = e._parse( instring, loc, doActions )
  File "/usr/lib64/python3.4/site-packages/pyparsing.py", line 1375, in _parseNoCache
    loc,tokens = self.parseImpl( instring, preloc, doActions )
  File "/usr/lib64/python3.4/site-packages/pyparsing.py", line 3605, in parseImpl
    return self.expr._parse( instring, loc, doActions, callPreParse=False )
  File "/usr/lib64/python3.4/site-packages/pyparsing.py", line 1375, in _parseNoCache
    loc,tokens = self.parseImpl( instring, preloc, doActions )
  File "/usr/lib64/python3.4/site-packages/pyparsing.py", line 3279, in parseImpl
    raise ParseSyntaxException._from_exception(pe)
pyparsing.ParseSyntaxException: Expected "]" (at char 14), (line:2, col:7)

Whereas if we use : instead:

foo = [
  bar: { baz=1 }
]

With the same code, we get a different outcome:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/capi/.local/lib64/python3.4/site-packages/pyhocon/config_parser.py", line 51, in parse_file
    return ConfigFactory.parse_string(content, os.path.dirname(filename), resolve)
  File "/home/capi/.local/lib64/python3.4/site-packages/pyhocon/config_parser.py", line 90, in parse_string
    return ConfigParser().parse(content, basedir, resolve)
  File "/home/capi/.local/lib64/python3.4/site-packages/pyhocon/config_parser.py", line 272, in parse
    config = config_expr.parseString(content, parseAll=True)[0]
  File "/usr/lib64/python3.4/site-packages/pyparsing.py", line 1603, in parseString
    loc, tokens = self._parse( instring, 0 )
  File "/usr/lib64/python3.4/site-packages/pyparsing.py", line 1375, in _parseNoCache
    loc,tokens = self.parseImpl( instring, preloc, doActions )
  File "/usr/lib64/python3.4/site-packages/pyparsing.py", line 3283, in parseImpl
    loc, exprtokens = e._parse( instring, loc, doActions )
  File "/usr/lib64/python3.4/site-packages/pyparsing.py", line 1375, in _parseNoCache
    loc,tokens = self.parseImpl( instring, preloc, doActions )
  File "/usr/lib64/python3.4/site-packages/pyparsing.py", line 3418, in parseImpl
    ret = e._parse( instring, loc, doActions )
  File "/usr/lib64/python3.4/site-packages/pyparsing.py", line 1375, in _parseNoCache
    loc,tokens = self.parseImpl( instring, preloc, doActions )
  File "/usr/lib64/python3.4/site-packages/pyparsing.py", line 3605, in parseImpl
    return self.expr._parse( instring, loc, doActions, callPreParse=False )
  File "/usr/lib64/python3.4/site-packages/pyparsing.py", line 1375, in _parseNoCache
    loc,tokens = self.parseImpl( instring, preloc, doActions )
  File "/usr/lib64/python3.4/site-packages/pyparsing.py", line 3811, in parseImpl
    return super(ZeroOrMore, self).parseImpl(instring, loc, doActions)
  File "/usr/lib64/python3.4/site-packages/pyparsing.py", line 3735, in parseImpl
    loc, tokens = self_expr_parse( instring, loc, doActions, callPreParse=False )
  File "/usr/lib64/python3.4/site-packages/pyparsing.py", line 1375, in _parseNoCache
    loc,tokens = self.parseImpl( instring, preloc, doActions )
  File "/usr/lib64/python3.4/site-packages/pyparsing.py", line 3418, in parseImpl
    ret = e._parse( instring, loc, doActions )
  File "/usr/lib64/python3.4/site-packages/pyparsing.py", line 1375, in _parseNoCache
    loc,tokens = self.parseImpl( instring, preloc, doActions )
  File "/usr/lib64/python3.4/site-packages/pyparsing.py", line 3605, in parseImpl
    return self.expr._parse( instring, loc, doActions, callPreParse=False )
  File "/usr/lib64/python3.4/site-packages/pyparsing.py", line 1375, in _parseNoCache
    loc,tokens = self.parseImpl( instring, preloc, doActions )
  File "/usr/lib64/python3.4/site-packages/pyparsing.py", line 3605, in parseImpl
    return self.expr._parse( instring, loc, doActions, callPreParse=False )
  File "/usr/lib64/python3.4/site-packages/pyparsing.py", line 1375, in _parseNoCache
    loc,tokens = self.parseImpl( instring, preloc, doActions )
  File "/usr/lib64/python3.4/site-packages/pyparsing.py", line 3274, in parseImpl
    loc, exprtokens = e._parse( instring, loc, doActions )
  File "/usr/lib64/python3.4/site-packages/pyparsing.py", line 1375, in _parseNoCache
    loc,tokens = self.parseImpl( instring, preloc, doActions )
  File "/usr/lib64/python3.4/site-packages/pyparsing.py", line 3418, in parseImpl
    ret = e._parse( instring, loc, doActions )
  File "/usr/lib64/python3.4/site-packages/pyparsing.py", line 1375, in _parseNoCache
    loc,tokens = self.parseImpl( instring, preloc, doActions )
  File "/usr/lib64/python3.4/site-packages/pyparsing.py", line 3274, in parseImpl
    loc, exprtokens = e._parse( instring, loc, doActions )
  File "/usr/lib64/python3.4/site-packages/pyparsing.py", line 1375, in _parseNoCache
    loc,tokens = self.parseImpl( instring, preloc, doActions )
  File "/usr/lib64/python3.4/site-packages/pyparsing.py", line 3605, in parseImpl
    return self.expr._parse( instring, loc, doActions, callPreParse=False )
  File "/usr/lib64/python3.4/site-packages/pyparsing.py", line 1375, in _parseNoCache
    loc,tokens = self.parseImpl( instring, preloc, doActions )
  File "/usr/lib64/python3.4/site-packages/pyparsing.py", line 3811, in parseImpl
    return super(ZeroOrMore, self).parseImpl(instring, loc, doActions)
  File "/usr/lib64/python3.4/site-packages/pyparsing.py", line 3735, in parseImpl
    loc, tokens = self_expr_parse( instring, loc, doActions, callPreParse=False )
  File "/usr/lib64/python3.4/site-packages/pyparsing.py", line 1375, in _parseNoCache
    loc,tokens = self.parseImpl( instring, preloc, doActions )
  File "/usr/lib64/python3.4/site-packages/pyparsing.py", line 3418, in parseImpl
    ret = e._parse( instring, loc, doActions )
  File "/usr/lib64/python3.4/site-packages/pyparsing.py", line 1375, in _parseNoCache
    loc,tokens = self.parseImpl( instring, preloc, doActions )
  File "/usr/lib64/python3.4/site-packages/pyparsing.py", line 3605, in parseImpl
    return self.expr._parse( instring, loc, doActions, callPreParse=False )
  File "/usr/lib64/python3.4/site-packages/pyparsing.py", line 1375, in _parseNoCache
    loc,tokens = self.parseImpl( instring, preloc, doActions )
  File "/usr/lib64/python3.4/site-packages/pyparsing.py", line 3266, in parseImpl
    loc, resultlist = self.exprs[0]._parse( instring, loc, doActions, callPreParse=False )
  File "/usr/lib64/python3.4/site-packages/pyparsing.py", line 1375, in _parseNoCache
    loc,tokens = self.parseImpl( instring, preloc, doActions )
  File "/usr/lib64/python3.4/site-packages/pyparsing.py", line 3274, in parseImpl
    loc, exprtokens = e._parse( instring, loc, doActions )
  File "/usr/lib64/python3.4/site-packages/pyparsing.py", line 1375, in _parseNoCache
    loc,tokens = self.parseImpl( instring, preloc, doActions )
  File "/usr/lib64/python3.4/site-packages/pyparsing.py", line 3605, in parseImpl
    return self.expr._parse( instring, loc, doActions, callPreParse=False )
  File "/usr/lib64/python3.4/site-packages/pyparsing.py", line 1375, in _parseNoCache
    loc,tokens = self.parseImpl( instring, preloc, doActions )
  File "/usr/lib64/python3.4/site-packages/pyparsing.py", line 3274, in parseImpl
    loc, exprtokens = e._parse( instring, loc, doActions )
  File "/usr/lib64/python3.4/site-packages/pyparsing.py", line 1375, in _parseNoCache
    loc,tokens = self.parseImpl( instring, preloc, doActions )
  File "/usr/lib64/python3.4/site-packages/pyparsing.py", line 3811, in parseImpl
    return super(ZeroOrMore, self).parseImpl(instring, loc, doActions)
  File "/usr/lib64/python3.4/site-packages/pyparsing.py", line 3735, in parseImpl
    loc, tokens = self_expr_parse( instring, loc, doActions, callPreParse=False )
  File "/usr/lib64/python3.4/site-packages/pyparsing.py", line 1375, in _parseNoCache
    loc,tokens = self.parseImpl( instring, preloc, doActions )
  File "/usr/lib64/python3.4/site-packages/pyparsing.py", line 3274, in parseImpl
    loc, exprtokens = e._parse( instring, loc, doActions )
  File "/usr/lib64/python3.4/site-packages/pyparsing.py", line 1381, in _parseNoCache
    tokens = self.postParse( instring, loc, tokens )
  File "/home/capi/.local/lib64/python3.4/site-packages/pyhocon/config_parser.py", line 474, in postParse
    return [config_values.transform()]
  File "/home/capi/.local/lib64/python3.4/site-packages/pyhocon/config_tree.py", line 411, in transform
    col=col(self._loc, self._instring)))
pyhocon.exceptions.ConfigWrongTypeException: Token 'ConfigTree([('baz', 1)])' of type ConfigTree (index 1) must be of type str (line: 2, col: 1)

Granted, both are errors. I am still learning HOCON, so I'm assuming you just can't place a key-value pair inside an array, which actually makes sense. However, the pyparsing exception leaking out makes it harder for someone that uses pyhocon, since we have to catch not only pyhocon.exceptions.ConfigException, but also pyparsing stuff (which means we have to import pyparsing in our own code).

@israel-lugo israel-lugo changed the title Dict inside an array throws pyparsing exception if we use = instead of : Key-value inside an array throws pyparsing exception if we use = instead of : Dec 1, 2016
@israel-lugo
Copy link
Author

Incidentally, I actually understood the error message from pyparsing better (in the first example) than the error message from ConfigWrongTypeException ;)

@darthbear darthbear added the bug label Dec 2, 2016
@darthbear darthbear self-assigned this Dec 3, 2016
israel-lugo added a commit to israel-lugo/pyhocon that referenced this issue May 3, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants