hocon 0.0.7 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (92) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +4 -2
  3. data/lib/hocon.rb +2 -0
  4. data/lib/hocon/config.rb +1010 -0
  5. data/lib/hocon/config_error.rb +32 -2
  6. data/lib/hocon/config_factory.rb +46 -0
  7. data/lib/hocon/config_include_context.rb +49 -0
  8. data/lib/hocon/config_includer_file.rb +27 -0
  9. data/lib/hocon/config_list.rb +49 -0
  10. data/lib/hocon/config_mergeable.rb +74 -0
  11. data/lib/hocon/config_object.rb +144 -1
  12. data/lib/hocon/config_parse_options.rb +33 -9
  13. data/lib/hocon/config_parseable.rb +51 -0
  14. data/lib/hocon/config_render_options.rb +4 -2
  15. data/lib/hocon/config_resolve_options.rb +31 -0
  16. data/lib/hocon/config_syntax.rb +5 -2
  17. data/lib/hocon/config_util.rb +73 -0
  18. data/lib/hocon/config_value.rb +122 -0
  19. data/lib/hocon/config_value_factory.rb +66 -2
  20. data/lib/hocon/config_value_type.rb +5 -2
  21. data/lib/hocon/impl.rb +2 -0
  22. data/lib/hocon/impl/abstract_config_node.rb +29 -0
  23. data/lib/hocon/impl/abstract_config_node_value.rb +11 -0
  24. data/lib/hocon/impl/abstract_config_object.rb +148 -42
  25. data/lib/hocon/impl/abstract_config_value.rb +251 -11
  26. data/lib/hocon/impl/array_iterator.rb +19 -0
  27. data/lib/hocon/impl/config_boolean.rb +7 -1
  28. data/lib/hocon/impl/config_concatenation.rb +177 -28
  29. data/lib/hocon/impl/config_delayed_merge.rb +329 -0
  30. data/lib/hocon/impl/config_delayed_merge_object.rb +274 -0
  31. data/lib/hocon/impl/config_document_parser.rb +647 -0
  32. data/lib/hocon/impl/config_double.rb +44 -0
  33. data/lib/hocon/impl/config_impl.rb +143 -19
  34. data/lib/hocon/impl/config_impl_util.rb +18 -0
  35. data/lib/hocon/impl/config_include_kind.rb +10 -0
  36. data/lib/hocon/impl/config_int.rb +13 -1
  37. data/lib/hocon/impl/config_node_array.rb +11 -0
  38. data/lib/hocon/impl/config_node_comment.rb +19 -0
  39. data/lib/hocon/impl/config_node_complex_value.rb +54 -0
  40. data/lib/hocon/impl/config_node_concatenation.rb +11 -0
  41. data/lib/hocon/impl/config_node_field.rb +81 -0
  42. data/lib/hocon/impl/config_node_include.rb +33 -0
  43. data/lib/hocon/impl/config_node_object.rb +276 -0
  44. data/lib/hocon/impl/config_node_path.rb +48 -0
  45. data/lib/hocon/impl/config_node_root.rb +60 -0
  46. data/lib/hocon/impl/config_node_simple_value.rb +42 -0
  47. data/lib/hocon/impl/config_node_single_token.rb +17 -0
  48. data/lib/hocon/impl/config_null.rb +15 -7
  49. data/lib/hocon/impl/config_number.rb +43 -4
  50. data/lib/hocon/impl/config_parser.rb +403 -0
  51. data/lib/hocon/impl/config_reference.rb +142 -0
  52. data/lib/hocon/impl/config_string.rb +55 -7
  53. data/lib/hocon/impl/container.rb +29 -0
  54. data/lib/hocon/impl/default_transformer.rb +24 -15
  55. data/lib/hocon/impl/from_map_mode.rb +3 -1
  56. data/lib/hocon/impl/full_includer.rb +2 -0
  57. data/lib/hocon/impl/memo_key.rb +42 -0
  58. data/lib/hocon/impl/mergeable_value.rb +8 -0
  59. data/lib/hocon/impl/origin_type.rb +8 -2
  60. data/lib/hocon/impl/parseable.rb +455 -91
  61. data/lib/hocon/impl/path.rb +181 -59
  62. data/lib/hocon/impl/path_builder.rb +24 -3
  63. data/lib/hocon/impl/path_parser.rb +280 -0
  64. data/lib/hocon/impl/replaceable_merge_stack.rb +22 -0
  65. data/lib/hocon/impl/resolve_context.rb +254 -0
  66. data/lib/hocon/impl/resolve_memos.rb +21 -0
  67. data/lib/hocon/impl/resolve_result.rb +39 -0
  68. data/lib/hocon/impl/resolve_source.rb +354 -0
  69. data/lib/hocon/impl/resolve_status.rb +3 -1
  70. data/lib/hocon/impl/simple_config.rb +264 -10
  71. data/lib/hocon/impl/simple_config_document.rb +48 -0
  72. data/lib/hocon/impl/simple_config_list.rb +282 -8
  73. data/lib/hocon/impl/simple_config_object.rb +424 -88
  74. data/lib/hocon/impl/simple_config_origin.rb +263 -71
  75. data/lib/hocon/impl/simple_include_context.rb +31 -1
  76. data/lib/hocon/impl/simple_includer.rb +196 -1
  77. data/lib/hocon/impl/substitution_expression.rb +38 -0
  78. data/lib/hocon/impl/token.rb +17 -4
  79. data/lib/hocon/impl/token_type.rb +6 -2
  80. data/lib/hocon/impl/tokenizer.rb +339 -109
  81. data/lib/hocon/impl/tokens.rb +330 -79
  82. data/lib/hocon/impl/unmergeable.rb +14 -1
  83. data/lib/hocon/impl/unsupported_operation_error.rb +6 -0
  84. data/lib/hocon/impl/url.rb +37 -0
  85. data/lib/hocon/parser.rb +7 -0
  86. data/lib/hocon/parser/config_document.rb +92 -0
  87. data/lib/hocon/parser/config_document_factory.rb +36 -0
  88. data/lib/hocon/parser/config_node.rb +30 -0
  89. metadata +67 -43
  90. data/lib/hocon/impl/config_float.rb +0 -13
  91. data/lib/hocon/impl/parser.rb +0 -977
  92. data/lib/hocon/impl/properties_parser.rb +0 -83
@@ -1,3 +1,5 @@
1
+ # encoding: utf-8
2
+
1
3
  require 'hocon'
2
4
 
3
5
  class Hocon::ConfigParseOptions
@@ -14,11 +16,7 @@ class Hocon::ConfigParseOptions
14
16
  @includer = includer
15
17
  end
16
18
 
17
- def allow_missing?
18
- @allow_missing
19
- end
20
-
21
- def with_syntax(syntax)
19
+ def set_syntax(syntax)
22
20
  if @syntax == syntax
23
21
  self
24
22
  else
@@ -29,7 +27,33 @@ class Hocon::ConfigParseOptions
29
27
  end
30
28
  end
31
29
 
32
- def with_includer(includer)
30
+ def set_origin_description(origin_description)
31
+ if @origin_description == origin_description
32
+ self
33
+ else
34
+ Hocon::ConfigParseOptions.new(@syntax,
35
+ origin_description,
36
+ @allow_missing,
37
+ @includer)
38
+ end
39
+ end
40
+
41
+ def set_allow_missing(allow_missing)
42
+ if allow_missing? == allow_missing
43
+ self
44
+ else
45
+ Hocon::ConfigParseOptions.new(@syntax,
46
+ @origin_description,
47
+ allow_missing,
48
+ @includer)
49
+ end
50
+ end
51
+
52
+ def allow_missing?
53
+ @allow_missing
54
+ end
55
+
56
+ def set_includer(includer)
33
57
  if @includer == includer
34
58
  self
35
59
  else
@@ -44,10 +68,10 @@ class Hocon::ConfigParseOptions
44
68
  if @includer == includer
45
69
  self
46
70
  elsif @includer
47
- with_includer(@includer.with_fallback(includer))
71
+ set_includer(@includer.with_fallback(includer))
48
72
  else
49
- with_includer(includer)
73
+ set_includer(includer)
50
74
  end
51
75
  end
52
76
 
53
- end
77
+ end
@@ -0,0 +1,51 @@
1
+ # encoding: utf-8
2
+
3
+ require 'hocon'
4
+ require 'hocon/config_error'
5
+
6
+ #
7
+ # An opaque handle to something that can be parsed, obtained from
8
+ # {@link ConfigIncludeContext}.
9
+ #
10
+ # <p>
11
+ # <em>Do not implement this interface</em>; it should only be implemented by
12
+ # the config library. Arbitrary implementations will not work because the
13
+ # library internals assume a specific concrete implementation. Also, this
14
+ # interface is likely to grow new methods over time, so third-party
15
+ # implementations will break.
16
+ #
17
+ module Hocon::ConfigParseable
18
+ #
19
+ # Parse whatever it is. The options should come from
20
+ # {@link ConfigParseable#options options()} but you could tweak them if you
21
+ # like.
22
+ #
23
+ # @param options
24
+ # parse options, should be based on the ones from
25
+ # {@link ConfigParseable#options options()}
26
+ # @return the parsed object
27
+ #
28
+ def parse(options)
29
+ raise Hocon::ConfigError::ConfigBugOrBrokenError, "subclasses of `ConfigParseable` must implement `parse` (#{self.class})"
30
+ end
31
+
32
+ #
33
+ # Returns a {@link ConfigOrigin} describing the origin of the parseable
34
+ # item.
35
+ # @return the origin of the parseable item
36
+ #
37
+ def origin
38
+ raise Hocon::ConfigError::ConfigBugOrBrokenError, "subclasses of `ConfigParseable` must implement `origin` (#{self.class})"
39
+ end
40
+
41
+ #
42
+ # Get the initial options, which can be modified then passed to parse().
43
+ # These options will have the right description, includer, and other
44
+ # parameters already set up.
45
+ # @return the initial options
46
+ #
47
+ def options
48
+ raise Hocon::ConfigError::ConfigBugOrBrokenError, "subclasses of `ConfigParseable` must implement `options` (#{self.class})"
49
+ end
50
+
51
+ end
@@ -1,3 +1,5 @@
1
+ # encoding: utf-8
2
+
1
3
  require 'hocon'
2
4
 
3
5
  class Hocon::ConfigRenderOptions
@@ -8,7 +10,7 @@ class Hocon::ConfigRenderOptions
8
10
  @json = json
9
11
  end
10
12
 
11
- attr_writer :origin_comments, :comments, :formatted, :json
13
+ attr_accessor :origin_comments, :comments, :formatted, :json
12
14
 
13
15
  def origin_comments?
14
16
  @origin_comments
@@ -43,4 +45,4 @@ class Hocon::ConfigRenderOptions
43
45
  def self.concise
44
46
  Hocon::ConfigRenderOptions.new(false, false, false, true)
45
47
  end
46
- end
48
+ end
@@ -0,0 +1,31 @@
1
+ # encoding: utf-8
2
+
3
+ require 'hocon'
4
+
5
+ class Hocon::ConfigResolveOptions
6
+ attr_reader :use_system_environment, :allow_unresolved
7
+
8
+ def initialize(use_system_environment, allow_unresolved)
9
+ @use_system_environment = use_system_environment
10
+ @allow_unresolved = allow_unresolved
11
+ end
12
+
13
+ def set_use_system_environment(value)
14
+ self.class.new(value, @allow_unresolved)
15
+ end
16
+
17
+ def set_allow_unresolved(value)
18
+ self.class.new(@use_system_environment, value)
19
+ end
20
+
21
+ class << self
22
+
23
+ def defaults
24
+ self.new(true, false)
25
+ end
26
+
27
+ def no_system
28
+ defaults.set_use_system_environment(false)
29
+ end
30
+ end
31
+ end
@@ -1,7 +1,10 @@
1
+ # encoding: utf-8
2
+
1
3
  require 'hocon'
2
4
 
3
5
  module Hocon::ConfigSyntax
4
6
  JSON = 0
5
7
  CONF = 1
6
- PROPERTIES = 2
7
- end
8
+ # we're not going to try to support .properties files any time soon :)
9
+ #PROPERTIES = 2
10
+ end
@@ -0,0 +1,73 @@
1
+ require 'hocon/impl/config_impl_util'
2
+
3
+
4
+ # Contains static utility methods
5
+ class Hocon::ConfigUtil
6
+ #
7
+ # Quotes and escapes a string, as in the JSON specification.
8
+ #
9
+ # @param string
10
+ # a string
11
+ # @return the string quoted and escaped
12
+ #
13
+ def self.quote_string(string)
14
+ Hocon::Impl::ConfigImplUtil.render_json_string(string)
15
+ end
16
+
17
+ #
18
+ # Converts a list of keys to a path expression, by quoting the path
19
+ # elements as needed and then joining them separated by a period. A path
20
+ # expression is usable with a {@link Config}, while individual path
21
+ # elements are usable with a {@link ConfigObject}.
22
+ # <p>
23
+ # See the overview documentation for {@link Config} for more detail on path
24
+ # expressions vs. keys.
25
+ #
26
+ # @param elements
27
+ # the keys in the path
28
+ # @return a path expression
29
+ # @throws ConfigException
30
+ # if there are no elements
31
+ #
32
+ def self.join_path(*elements)
33
+ Hocon::Impl::ConfigImplUtil.join_path(*elements)
34
+ end
35
+
36
+ #
37
+ # Converts a list of strings to a path expression, by quoting the path
38
+ # elements as needed and then joining them separated by a period. A path
39
+ # expression is usable with a {@link Config}, while individual path
40
+ # elements are usable with a {@link ConfigObject}.
41
+ # <p>
42
+ # See the overview documentation for {@link Config} for more detail on path
43
+ # expressions vs. keys.
44
+ #
45
+ # @param elements
46
+ # the keys in the path
47
+ # @return a path expression
48
+ # @throws ConfigException
49
+ # if the list is empty
50
+ #
51
+ def self.join_path_from_list(elements)
52
+ self.join_path(*elements)
53
+ end
54
+
55
+ #
56
+ # Converts a path expression into a list of keys, by splitting on period
57
+ # and unquoting the individual path elements. A path expression is usable
58
+ # with a {@link Config}, while individual path elements are usable with a
59
+ # {@link ConfigObject}.
60
+ # <p>
61
+ # See the overview documentation for {@link Config} for more detail on path
62
+ # expressions vs. keys.
63
+ #
64
+ # @param path
65
+ # a path expression
66
+ # @return the individual keys in the path
67
+ # @throws ConfigException
68
+ # if the path expression is invalid
69
+ #
70
+ def self.split_path(path)
71
+ Hocon::Impl::ConfigImplUtil.split_path(path)
72
+ end
73
+ end
@@ -0,0 +1,122 @@
1
+ # encoding: utf-8
2
+
3
+ require 'hocon'
4
+ require 'hocon/config_mergeable'
5
+
6
+ #
7
+ # An immutable value, following the <a href="http://json.org">JSON</a> type
8
+ # schema.
9
+ #
10
+ # <p>
11
+ # Because this object is immutable, it is safe to use from multiple threads and
12
+ # there's no need for "defensive copies."
13
+ #
14
+ # <p>
15
+ # <em>Do not implement interface {@code ConfigValue}</em>; it should only be
16
+ # implemented by the config library. Arbitrary implementations will not work
17
+ # because the library internals assume a specific concrete implementation.
18
+ # Also, this interface is likely to grow new methods over time, so third-party
19
+ # implementations will break.
20
+ #
21
+ module Hocon::ConfigValue
22
+ include Hocon::ConfigMergeable
23
+
24
+ #
25
+ # The origin of the value (file, line number, etc.), for debugging and
26
+ # error messages.
27
+ #
28
+ # @return where the value came from
29
+ #
30
+ def origin
31
+ raise Hocon::ConfigError::ConfigBugOrBrokenError, "subclasses of `ConfigValue` must implement `origin` (#{self.class})"
32
+ end
33
+
34
+
35
+ #
36
+ # The {@link ConfigValueType} of the value; matches the JSON type schema.
37
+ #
38
+ # @return value's type
39
+ #
40
+ def value_type
41
+ raise Hocon::ConfigError::ConfigBugOrBrokenError, "subclasses of `ConfigValue` must implement `value_type` (#{self.class})"
42
+ end
43
+
44
+ #
45
+ # Returns the value as a plain Java boxed value, that is, a {@code String},
46
+ # {@code Number}, {@code Boolean}, {@code Map<String,Object>},
47
+ # {@code List<Object>}, or {@code null}, matching the {@link #valueType()}
48
+ # of this {@code ConfigValue}. If the value is a {@link ConfigObject} or
49
+ # {@link ConfigList}, it is recursively unwrapped.
50
+ # @return a plain Java value corresponding to this ConfigValue
51
+ #
52
+ def unwrapped
53
+ raise Hocon::ConfigError::ConfigBugOrBrokenError, "subclasses of `ConfigValue` must implement `unwrapped` (#{self.class})"
54
+ end
55
+
56
+ #
57
+ # Renders the config value to a string, using the provided options.
58
+ #
59
+ # <p>
60
+ # If the config value has not been resolved (see {@link Config#resolve}),
61
+ # it's possible that it can't be rendered as valid HOCON. In that case the
62
+ # rendering should still be useful for debugging but you might not be able
63
+ # to parse it. If the value has been resolved, it will always be parseable.
64
+ #
65
+ # <p>
66
+ # If the config value has been resolved and the options disable all
67
+ # HOCON-specific features (such as comments), the rendering will be valid
68
+ # JSON. If you enable HOCON-only features such as comments, the rendering
69
+ # will not be valid JSON.
70
+ #
71
+ # @param options
72
+ # the rendering options
73
+ # @return the rendered value
74
+ #
75
+ def render(options)
76
+ raise Hocon::ConfigError::ConfigBugOrBrokenError, "subclasses of `ConfigValue` must implement `render` (#{self.class})"
77
+ end
78
+
79
+ def with_fallback(other)
80
+ raise Hocon::ConfigError::ConfigBugOrBrokenError, "subclasses of `ConfigValue` must implement `with_fallback` (#{self.class})"
81
+ end
82
+
83
+ #
84
+ # Places the value inside a {@link Config} at the given path. See also
85
+ # {@link ConfigValue#atKey(String)}.
86
+ #
87
+ # @param path
88
+ # path to store this value at.
89
+ # @return a {@code Config} instance containing this value at the given
90
+ # path.
91
+ #
92
+ def at_path(path)
93
+ raise Hocon::ConfigError::ConfigBugOrBrokenError, "subclasses of `ConfigValue` must implement `at_path` (#{self.class})"
94
+ end
95
+
96
+ #
97
+ # Places the value inside a {@link Config} at the given key. See also
98
+ # {@link ConfigValue#atPath(String)}.
99
+ #
100
+ # @param key
101
+ # key to store this value at.
102
+ # @return a {@code Config} instance containing this value at the given key.
103
+ #
104
+ def at_key(key)
105
+ raise Hocon::ConfigError::ConfigBugOrBrokenError, "subclasses of `ConfigValue` must implement `at_key` (#{self.class})"
106
+ end
107
+
108
+ #
109
+ # Returns a {@code ConfigValue} based on this one, but with the given
110
+ # origin. This is useful when you are parsing a new format of file or setting
111
+ # comments for a single ConfigValue.
112
+ #
113
+ # @since 1.3.0
114
+ #
115
+ # @param origin the origin set on the returned value
116
+ # @return the new ConfigValue with the given origin
117
+ #
118
+ def with_origin(origin)
119
+ raise Hocon::ConfigError::ConfigBugOrBrokenError, "subclasses of `ConfigValue` must implement `with_origin` (#{self.class})"
120
+ end
121
+
122
+ end
@@ -1,10 +1,74 @@
1
+ # encoding: utf-8
2
+
1
3
  require 'hocon'
2
4
  require 'hocon/impl/config_impl'
3
5
 
4
6
  class Hocon::ConfigValueFactory
5
7
  ConfigImpl = Hocon::Impl::ConfigImpl
6
8
 
7
- def self.from_any_ref(object, origin_description)
9
+ #
10
+ # Creates a {@link ConfigValue} from a plain value, which may be
11
+ # a <code>Boolean</code>, <code>Number</code>, <code>String</code>,
12
+ # <code>Hash</code>, or <code>nil</code>. A
13
+ # <code>Hash</code> must be a <code>Hash</code> from String to more values
14
+ # that can be supplied to <code>from_any_ref()</code>. A <code>Hash</code>
15
+ # will become a {@link ConfigObject} and an <code>Array</code> will become a
16
+ # {@link ConfigList}.
17
+ #
18
+ # <p>
19
+ # In a <code>Hash</code> passed to <code>from_any_ref()</code>, the map's keys
20
+ # are plain keys, not path expressions. So if your <code>Hash</code> has a
21
+ # key "foo.bar" then you will get one object with a key called "foo.bar",
22
+ # rather than an object with a key "foo" containing another object with a
23
+ # key "bar".
24
+ #
25
+ # <p>
26
+ # The origin_description will be used to set the origin() field on the
27
+ # ConfigValue. It should normally be the name of the file the values came
28
+ # from, or something short describing the value such as "default settings".
29
+ # The origin_description is prefixed to error messages so users can tell
30
+ # where problematic values are coming from.
31
+ #
32
+ # <p>
33
+ # Supplying the result of ConfigValue.unwrapped() to this function is
34
+ # guaranteed to work and should give you back a ConfigValue that matches
35
+ # the one you unwrapped. The re-wrapped ConfigValue will lose some
36
+ # information that was present in the original such as its origin, but it
37
+ # will have matching values.
38
+ #
39
+ # <p>
40
+ # If you pass in a <code>ConfigValue</code> to this
41
+ # function, it will be returned unmodified. (The
42
+ # <code>origin_description</code> will be ignored in this
43
+ # case.)
44
+ #
45
+ # <p>
46
+ # This function throws if you supply a value that cannot be converted to a
47
+ # ConfigValue, but supplying such a value is a bug in your program, so you
48
+ # should never handle the exception. Just fix your program (or report a bug
49
+ # against this library).
50
+ #
51
+ # @param object
52
+ # object to convert to ConfigValue
53
+ # @param origin_description
54
+ # name of origin file or brief description of what the value is
55
+ # @return a new value
56
+ #
57
+ def self.from_any_ref(object, origin_description = nil)
8
58
  ConfigImpl.from_any_ref(object, origin_description)
9
59
  end
10
- end
60
+
61
+ #
62
+ # See the {@link #from_any_ref(Object,String)} documentation for details
63
+ #
64
+ # <p>
65
+ # See also {@link ConfigFactory#parse_map(Map)} which interprets the keys in
66
+ # the map as path expressions.
67
+ #
68
+ # @param values map from keys to plain ruby values
69
+ # @return a new {@link ConfigObject}
70
+ #
71
+ def self.from_map(values, origin_description = nil)
72
+ ConfigImpl.from_any_ref(values, origin_description)
73
+ end
74
+ end