hocon 0.0.2 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/hocon.rb +12 -1
- data/lib/hocon/config_error.rb +11 -11
- data/lib/hocon/config_factory.rb +8 -7
- data/lib/hocon/config_object.rb +4 -4
- data/lib/hocon/config_parse_options.rb +43 -43
- data/lib/hocon/config_render_options.rb +41 -41
- data/lib/hocon/config_syntax.rb +7 -7
- data/lib/hocon/config_value_type.rb +23 -23
- data/lib/hocon/impl.rb +4 -5
- data/lib/hocon/impl/parser.rb +5 -5
- data/lib/hocon/impl/simple_config_list.rb +5 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 381d63a664f791ef19243206e6df57fba65f8344
|
4
|
+
data.tar.gz: 9eef67a35bdb45b99d617fe9358d778be75c1210
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d4c6571dd9fdd9bbb6616123f7a5215d8e5c84f80fa2e130507f24a67a743bd4ec4317c542d5ca5fb7b02369aef15088df36a8c069adfe232e56cbed3c84f914
|
7
|
+
data.tar.gz: e1a1351ee91715a8ab1918befcea8967c7d931e13e569506c2f458025a59d7c667ab8f4d259aff00804a21eff2691b97190ee401ead386b2a407eaf0de02e571
|
data/lib/hocon.rb
CHANGED
@@ -1,2 +1,13 @@
|
|
1
|
+
require 'hocon/config_factory'
|
2
|
+
|
1
3
|
module Hocon
|
2
|
-
|
4
|
+
def self.load(file)
|
5
|
+
config = Hocon::ConfigFactory.parse_file(file)
|
6
|
+
return config.root.unwrapped
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.parse(string)
|
10
|
+
config = Hocon::ConfigFactory.parse_string(string)
|
11
|
+
return config.root.unwrapped
|
12
|
+
end
|
13
|
+
end
|
data/lib/hocon/config_error.rb
CHANGED
@@ -1,15 +1,15 @@
|
|
1
|
-
|
1
|
+
module Hocon
|
2
|
+
class ConfigError < StandardError
|
3
|
+
def initialize(origin, message, cause)
|
4
|
+
super(message)
|
5
|
+
@origin = origin
|
6
|
+
@cause = cause
|
7
|
+
end
|
2
8
|
|
3
|
-
class Hocon::ConfigError
|
4
|
-
|
5
|
-
super(message)
|
6
|
-
@origin = origin
|
7
|
-
@cause = cause
|
8
|
-
end
|
9
|
-
|
10
|
-
class ConfigParseError < Hocon::ConfigError
|
11
|
-
end
|
9
|
+
class ConfigParseError < Hocon::ConfigError
|
10
|
+
end
|
12
11
|
|
13
|
-
|
12
|
+
class ConfigWrongTypeError < Hocon::ConfigError
|
13
|
+
end
|
14
14
|
end
|
15
15
|
end
|
data/lib/hocon/config_factory.rb
CHANGED
@@ -1,13 +1,14 @@
|
|
1
|
-
require 'hocon'
|
2
1
|
require 'hocon/config_parse_options'
|
3
2
|
require 'hocon/impl/parseable'
|
4
3
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
4
|
+
module Hocon
|
5
|
+
class ConfigFactory
|
6
|
+
def self.parse_file(file_path, options = Hocon::ConfigParseOptions.defaults)
|
7
|
+
Hocon::Impl::Parseable.new_file(file_path, options).parse.to_config
|
8
|
+
end
|
9
9
|
|
10
|
-
|
11
|
-
|
10
|
+
def self.parse_string(string, options = Hocon::ConfigParseOptions.defaults)
|
11
|
+
Hocon::Impl::Parseable.new_string(string, options).parse.to_config
|
12
|
+
end
|
12
13
|
end
|
13
14
|
end
|
data/lib/hocon/config_object.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
end
|
1
|
+
module Hocon
|
2
|
+
module ConfigObject
|
3
|
+
end
|
4
|
+
end
|
@@ -1,53 +1,53 @@
|
|
1
|
-
|
1
|
+
module Hocon
|
2
|
+
class ConfigParseOptions
|
3
|
+
attr_accessor :syntax, :origin_description, :allow_missing, :includer
|
2
4
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
def self.defaults
|
7
|
-
self.new(nil, nil, true, nil)
|
8
|
-
end
|
5
|
+
def self.defaults
|
6
|
+
self.new(nil, nil, true, nil)
|
7
|
+
end
|
9
8
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
9
|
+
def initialize(syntax, origin_description, allow_missing, includer)
|
10
|
+
@syntax = syntax
|
11
|
+
@origin_description = origin_description
|
12
|
+
@allow_missing = allow_missing
|
13
|
+
@includer = includer
|
14
|
+
end
|
16
15
|
|
17
|
-
|
18
|
-
|
19
|
-
|
16
|
+
def allow_missing?
|
17
|
+
@allow_missing
|
18
|
+
end
|
20
19
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
20
|
+
def with_syntax(syntax)
|
21
|
+
if @syntax == syntax
|
22
|
+
self
|
23
|
+
else
|
24
|
+
Hocon::ConfigParseOptions.new(syntax,
|
25
|
+
@origin_description,
|
26
|
+
@allow_missing,
|
27
|
+
@includer)
|
28
|
+
end
|
29
29
|
end
|
30
|
-
end
|
31
30
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
31
|
+
def with_includer(includer)
|
32
|
+
if @includer == includer
|
33
|
+
self
|
34
|
+
else
|
35
|
+
Hocon::ConfigParseOptions.new(@syntax,
|
36
|
+
@origin_description,
|
37
|
+
@allow_missing,
|
38
|
+
includer)
|
39
|
+
end
|
40
40
|
end
|
41
|
-
end
|
42
41
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
42
|
+
def append_includer(includer)
|
43
|
+
if @includer == includer
|
44
|
+
self
|
45
|
+
elsif @includer
|
46
|
+
with_includer(@includer.with_fallback(includer))
|
47
|
+
else
|
48
|
+
with_includer(includer)
|
49
|
+
end
|
50
50
|
end
|
51
|
-
end
|
52
51
|
|
53
|
-
end
|
52
|
+
end
|
53
|
+
end
|
@@ -1,46 +1,46 @@
|
|
1
|
-
|
1
|
+
module Hocon
|
2
|
+
class ConfigRenderOptions
|
3
|
+
def initialize(origin_comments, comments, formatted, json)
|
4
|
+
@origin_comments = origin_comments
|
5
|
+
@comments = comments
|
6
|
+
@formatted = formatted
|
7
|
+
@json = json
|
8
|
+
end
|
2
9
|
|
3
|
-
|
4
|
-
def initialize(origin_comments, comments, formatted, json)
|
5
|
-
@origin_comments = origin_comments
|
6
|
-
@comments = comments
|
7
|
-
@formatted = formatted
|
8
|
-
@json = json
|
9
|
-
end
|
10
|
+
attr_writer :origin_comments, :comments, :formatted, :json
|
10
11
|
|
11
|
-
|
12
|
+
def origin_comments?
|
13
|
+
@origin_comments
|
14
|
+
end
|
15
|
+
def comments?
|
16
|
+
@comments
|
17
|
+
end
|
18
|
+
def formatted?
|
19
|
+
@formatted
|
20
|
+
end
|
21
|
+
def json?
|
22
|
+
@json
|
23
|
+
end
|
12
24
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
@json
|
24
|
-
end
|
25
|
-
|
26
|
-
#
|
27
|
-
# Returns the default render options which are verbose (commented and
|
28
|
-
# formatted). See {@link ConfigRenderOptions#concise} for stripped-down
|
29
|
-
# options. This rendering will not be valid JSON since it has comments.
|
30
|
-
#
|
31
|
-
# @return the default render options
|
32
|
-
#
|
33
|
-
def self.defaults
|
34
|
-
Hocon::ConfigRenderOptions.new(true, true, true, true)
|
35
|
-
end
|
25
|
+
#
|
26
|
+
# Returns the default render options which are verbose (commented and
|
27
|
+
# formatted). See {@link ConfigRenderOptions#concise} for stripped-down
|
28
|
+
# options. This rendering will not be valid JSON since it has comments.
|
29
|
+
#
|
30
|
+
# @return the default render options
|
31
|
+
#
|
32
|
+
def self.defaults
|
33
|
+
ConfigRenderOptions.new(true, true, true, true)
|
34
|
+
end
|
36
35
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
36
|
+
#
|
37
|
+
# Returns concise render options (no whitespace or comments). For a
|
38
|
+
# resolved {@link Config}, the concise rendering will be valid JSON.
|
39
|
+
#
|
40
|
+
# @return the concise render options
|
41
|
+
#
|
42
|
+
def self.concise
|
43
|
+
ConfigRenderOptions.new(false, false, false, true)
|
44
|
+
end
|
45
45
|
end
|
46
|
-
end
|
46
|
+
end
|
data/lib/hocon/config_syntax.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
end
|
1
|
+
module Hocon
|
2
|
+
module ConfigSyntax
|
3
|
+
JSON = 0
|
4
|
+
CONF = 1
|
5
|
+
PROPERTIES = 2
|
6
|
+
end
|
7
|
+
end
|
@@ -1,26 +1,26 @@
|
|
1
|
-
|
1
|
+
module Hocon
|
2
|
+
#
|
3
|
+
# The type of a configuration value (following the <a
|
4
|
+
# href="http://json.org">JSON</a> type schema).
|
5
|
+
#
|
6
|
+
module ConfigValueType
|
7
|
+
OBJECT = 0
|
8
|
+
LIST = 1
|
9
|
+
NUMBER = 2
|
10
|
+
BOOLEAN = 3
|
11
|
+
NULL = 4
|
12
|
+
STRING = 5
|
2
13
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
STRING = 5
|
14
|
-
|
15
|
-
def self.name(config_value_type)
|
16
|
-
case config_value_type
|
17
|
-
when OBJECT then "OBJECT"
|
18
|
-
when LIST then "LIST"
|
19
|
-
when NUMBER then "NUMBER"
|
20
|
-
when BOOLEAN then "BOOLEAN"
|
21
|
-
when NULL then "NULL"
|
22
|
-
when STRING then "STRING"
|
23
|
-
else raise ConfigBugError, "Unrecognized value type '#{config_value_type}'"
|
14
|
+
def self.name(config_value_type)
|
15
|
+
case config_value_type
|
16
|
+
when OBJECT then "OBJECT"
|
17
|
+
when LIST then "LIST"
|
18
|
+
when NUMBER then "NUMBER"
|
19
|
+
when BOOLEAN then "BOOLEAN"
|
20
|
+
when NULL then "NULL"
|
21
|
+
when STRING then "STRING"
|
22
|
+
else raise ConfigBugError, "Unrecognized value type '#{config_value_type}'"
|
23
|
+
end
|
24
24
|
end
|
25
25
|
end
|
26
|
-
end
|
26
|
+
end
|
data/lib/hocon/impl.rb
CHANGED
@@ -1,5 +1,4 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
end
|
1
|
+
module Hocon
|
2
|
+
module Impl
|
3
|
+
end
|
4
|
+
end
|
data/lib/hocon/impl/parser.rb
CHANGED
@@ -360,7 +360,7 @@ class Hocon::Impl::Parser
|
|
360
360
|
while !key.nil?
|
361
361
|
# for ruby: convert string keys to symbols
|
362
362
|
if key.is_a?(String)
|
363
|
-
key = key
|
363
|
+
key = key
|
364
364
|
end
|
365
365
|
keys.push(key)
|
366
366
|
if remaining.nil?
|
@@ -496,7 +496,7 @@ class Hocon::Impl::Parser
|
|
496
496
|
|
497
497
|
# for ruby: convert string keys to symbols
|
498
498
|
if key.is_a?(String)
|
499
|
-
key = key
|
499
|
+
key = key
|
500
500
|
end
|
501
501
|
|
502
502
|
remaining = path.remainder
|
@@ -579,10 +579,10 @@ class Hocon::Impl::Parser
|
|
579
579
|
|
580
580
|
# special-case the first element
|
581
581
|
if t.token == Tokens::CLOSE_SQUARE
|
582
|
-
SimpleConfigList.new(t.append_comments(array_origin), [])
|
582
|
+
return SimpleConfigList.new(t.append_comments(array_origin), [])
|
583
583
|
elsif (Tokens.value?(t.token)) ||
|
584
584
|
(t.token == Tokens::OPEN_CURLY) ||
|
585
|
-
(
|
585
|
+
(t.token == Tokens::OPEN_SQUARE)
|
586
586
|
v = parse_value(t)
|
587
587
|
v = add_any_comments_after_any_comma(v)
|
588
588
|
values.push(v)
|
@@ -879,4 +879,4 @@ class Hocon::Impl::Parser
|
|
879
879
|
include_context)
|
880
880
|
context.parse
|
881
881
|
end
|
882
|
-
end
|
882
|
+
end
|