pyhocon icon indicating copy to clipboard operation
pyhocon copied to clipboard

ConfigFactory can't parse single quoted string

Open alexey-terentiev opened this issue 9 years ago • 2 comments

Config:

foo = '-XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath='

Code:

from pyhocon import ConfigFactory

config = ConfigFactory.parse_file("test.conf", resolve=False)

Result:

Traceback (most recent call last):
  File "converter.py", line 5, in <module>
    config = ConfigFactory.parse_file("test.conf", resolve=False)
  File "C:\Python27\lib\site-packages\pyhocon\config_parser.py", line 48, in parse_file
    return ConfigFactory.parse_string(content, os.path.dirname(filename), resolve)
  File "C:\Python27\lib\site-packages\pyhocon\config_parser.py", line 87, in parse_string
    return ConfigParser().parse(content, basedir, resolve)
  File "C:\Python27\lib\site-packages\pyhocon\config_parser.py", line 255, in parse
    config = config_expr.parseString(content, parseAll=True)[0]
  File "C:\Python27\lib\site-packages\pyparsing.py", line 1172, in parseString
    raise exc
pyparsing.ParseException: Expected end of text (at char 6), (line:1, col:7)

alexey-terentiev avatar Apr 21 '16 15:04 alexey-terentiev

Hi @alexey-terentiev,

I just tried parsing this file in Scala but it doesn't support single quotes. I can implement this feature but it will have a different behavior than the Scala version.

import com.typesafe.config._
val c = ConfigFactory.load("test.conf", ConfigParseOptions.defaults().setAllowMissing(false), ConfigResolveOptions.defaults())

com.typesafe.config.ConfigException$Parse: test5.conf: 1: Expecting end of input or a comma, got ':' (if you intended ':' to be part of the value for 'foo', try enclosing the value in double quotes, or you may be able to rename the file .properties rather than .conf)
  at com.typesafe.config.impl.Parser$ParseContext.parseError(Parser.java:435)
  at com.typesafe.config.impl.Parser$ParseContext.parseError(Parser.java:431)
  at com.typesafe.config.impl.Parser$ParseContext.parseObject(Parser.java:887)
  at com.typesafe.config.impl.Parser$ParseContext.parse(Parser.java:993)
  at com.typesafe.config.impl.Parser.parse(Parser.java:34)
  at com.typesafe.config.impl.Parseable.rawParseValue(Parseable.java:222)
  at com.typesafe.config.impl.Parseable$ParseableResources.rawParseValue(Parseable.java:602)
  at com.typesafe.config.impl.Parseable$ParseableResources.rawParseValue(Parseable.java:554)
  at com.typesafe.config.impl.Parseable.parseValue(Parseable.java:176)
  at com.typesafe.config.impl.Parseable.parseValue(Parseable.java:170)
  at com.typesafe.config.impl.Parseable.parse(Parseable.java:148)
  at com.typesafe.config.impl.SimpleIncluder.fromBasename(SimpleIncluder.java:172)
  at com.typesafe.config.impl.ConfigImpl.parseResourcesAnySyntax(ConfigImpl.java:128)
  at com.typesafe.config.ConfigFactory.parseResourcesAnySyntax(ConfigFactory.java:811)
  at com.typesafe.config.ConfigFactory.load(ConfigFactory.java:113)
  ... 32 elided

darthbear avatar Apr 24 '16 01:04 darthbear

Hi, If it's designed without single quotes support then it's not a bug, I guess, and can be aborted. There could be usecases when you might want to totally ignore all special characters and substitutions so this issue could be a very low priority feature request. += and self reference are more important ones :-)

alexey-terentiev avatar Apr 26 '16 13:04 alexey-terentiev