diff --git a/trains/utilities/pyhocon/config_parser.py b/trains/utilities/pyhocon/config_parser.py index 3817f7d7..a9b95efc 100755 --- a/trains/utilities/pyhocon/config_parser.py +++ b/trains/utilities/pyhocon/config_parser.py @@ -365,16 +365,17 @@ class ConfigParser(object): false_expr = Keyword("false", caseless=True).setParseAction(replaceWith(False)) null_expr = Keyword("null", caseless=True).setParseAction(replaceWith(NoneValue())) # key = QuotedString('"', escChar='\\', unquoteResults=False) | Word(alphanums + alphas8bit + '._- /') + regexp_numbers = r'[+-]?(\d*\.\d+|\d+(\.\d+)?)([eE][+\-]?\d+)?(?=$|[ \t]*([\$\}\],#\n\r]|//))' key = QuotedString('"', escChar='\\', unquoteResults=False) | \ - Word("0123456789.").setParseAction(safe_convert_number) | Word(alphanums + alphas8bit + '._- /') + Regex(regexp_numbers, re.DOTALL).setParseAction(safe_convert_number) | \ + Word(alphanums + alphas8bit + '._- /') eol = Word('\n\r').suppress() eol_comma = Word('\n\r,').suppress() comment = (Literal('#') | Literal('//')) - SkipTo(eol | StringEnd()) comment_eol = Suppress(Optional(eol_comma) + comment) comment_no_comma_eol = (comment | eol).suppress() - number_expr = Regex(r'[+-]?(\d*\.\d+|\d+(\.\d+)?)([eE][+\-]?\d+)?(?=$|[ \t]*([\$\}\],#\n\r]|//))', - re.DOTALL).setParseAction(convert_number) + number_expr = Regex(regexp_numbers, re.DOTALL).setParseAction(convert_number) period_types = itertools.chain.from_iterable(cls.get_supported_period_type_map().values()) period_expr = Regex(r'(?P\d+)\s*(?P' + '|'.join(period_types) + ')$' diff --git a/trains/utilities/pyhocon/converter.py b/trains/utilities/pyhocon/converter.py index 4b73bb53..ba258fa7 100755 --- a/trains/utilities/pyhocon/converter.py +++ b/trains/utilities/pyhocon/converter.py @@ -111,9 +111,10 @@ class HOCONConverter(object): else: full_key = key - if isinstance(full_key, (basestring, unicode)) and cls._number_re_matcher.match(full_key): + if isinstance(full_key, float) or \ + (isinstance(full_key, (basestring, unicode)) and cls._number_re_matcher.match(full_key)): # if key can be casted to float, and it is a string, make sure we quote it - full_key = '\"' + full_key + '\"' + full_key = '\"{}\"'.format(full_key) bet_line = ('{indent}{key}{assign_sign} '.format( indent=''.rjust(level * indent, ' '),