hocon 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
data/lib/hocon.rb CHANGED
@@ -1,13 +1,5 @@
1
1
  module Hocon
2
2
  require 'hocon/config_factory'
3
- require 'hocon/config_parse_options'
4
- require 'hocon/config_error'
5
- require 'hocon/config_object'
6
- require 'hocon/config_parse_options'
7
- require 'hocon/config_render_options'
8
- require 'hocon/config_syntax'
9
- require 'hocon/config_value_factory'
10
- require 'hocon/config_value_type'
11
3
 
12
4
  def self.load(file)
13
5
  config = Hocon::ConfigFactory.parse_file(file)
@@ -1,5 +1,6 @@
1
1
  require 'hocon'
2
2
  require 'hocon/impl/parseable'
3
+ require 'hocon/config_parse_options'
3
4
 
4
5
  class Hocon::ConfigFactory
5
6
  def self.parse_file(file_path, options = Hocon::ConfigParseOptions.defaults)
@@ -80,7 +80,7 @@ class Hocon::Impl::ConfigImplUtil
80
80
  # this implementation is *not* a port of the java code. Ruby can strip
81
81
  # unicode whitespace much easier than Java can, and relies on a lot of
82
82
  # Java functions that don't really have straight equivalents in Ruby.
83
- s.gsub(/[[:space]]/, ' ')
83
+ s.gsub(/[:space]/, ' ')
84
84
  s.strip
85
85
  end
86
- end
86
+ end
@@ -6,6 +6,7 @@ require 'stringio'
6
6
  class Hocon::Impl::Path
7
7
 
8
8
  ConfigBugOrBrokenError = Hocon::ConfigError::ConfigBugOrBrokenError
9
+ ConfigImplUtil = Hocon::Impl::ConfigImplUtil
9
10
 
10
11
  # this doesn't have a very precise meaning, just to reduce
11
12
  # noise from quotes in the rendered path for average cases
@@ -1,6 +1,7 @@
1
1
  require 'hocon/impl'
2
2
  require 'hocon/impl/config_impl_util'
3
3
  require 'hocon/impl/tokens'
4
+ require 'hocon/config_error'
4
5
  require 'stringio'
5
6
  require 'forwardable'
6
7
 
@@ -8,6 +9,13 @@ class Hocon::Impl::Tokenizer
8
9
  Tokens = Hocon::Impl::Tokens
9
10
 
10
11
  class TokenizerProblemError < StandardError
12
+ def initialize(problem)
13
+ @problem = problem
14
+ end
15
+
16
+ def problem
17
+ @problem
18
+ end
11
19
  end
12
20
 
13
21
  class TokenIterator
@@ -67,6 +75,13 @@ class Hocon::Impl::Tokenizer
67
75
  # chars that stop an unquoted string
68
76
  NOT_IN_UNQUOTED_TEXT = "$\"{}[]:=,+#`^?!@*&\\"
69
77
 
78
+ def self.problem(origin, what, message, suggest_quotes, cause)
79
+ if what.nil? || message.nil?
80
+ throw Hocon::ConfigError::ConfigBugOrBrokenError.new("internal error, creating bad TokenizerProblemError", nil)
81
+ end
82
+ TokenizerProblemError.new(Tokens.new_problem(origin, what, message, suggest_quotes, cause))
83
+ end
84
+
70
85
  def self.simple_value?(t)
71
86
  Tokens.substitution?(t) ||
72
87
  Tokens.unquoted_text?(t) ||
@@ -128,7 +143,7 @@ class Hocon::Impl::Tokenizer
128
143
  def next_char_raw
129
144
  if @buffer.empty?
130
145
  begin
131
- @input.readchar
146
+ @input.readchar.chr
132
147
  rescue EOFError
133
148
  -1
134
149
  end
@@ -245,8 +260,8 @@ class Hocon::Impl::Tokenizer
245
260
  # not a number after all, see if it's an unquoted string.
246
261
  s.each do |u|
247
262
  if NOT_IN_UNQUOTED_TEXT.index
248
- raise problem(u, "Reserved character '#{u}'" +
249
- "is not allowed outside quotes", true)
263
+ raise self.problem(@line_origin, u, "Reserved character '#{u}'" +
264
+ "is not allowed outside quotes", true, nil)
250
265
  end
251
266
  end
252
267
  # no evil chars so we just decide this was a string and
@@ -265,7 +280,7 @@ class Hocon::Impl::Tokenizer
265
280
  while c != '"'
266
281
  c = next_char_raw
267
282
  if c == -1
268
- raise problem("End of input but string quote was still open")
283
+ raise self.problem(@line_origin, c, "End of input but string quote was still open", false, nil)
269
284
  end
270
285
 
271
286
  if c == "\\"
@@ -273,8 +288,8 @@ class Hocon::Impl::Tokenizer
273
288
  elsif c == '"'
274
289
  # done!
275
290
  elsif c =~ /[[:cntrl:]]/
276
- raise problem(c, "JSON does not allow unescaped #{c}" +
277
- " in quoted strings, use a backslash escape")
291
+ raise self.problem(@line_origin, c, "JSON does not allow unescaped #{c}" +
292
+ " in quoted strings, use a backslash escape", false, nil)
278
293
  else
279
294
  sb << c
280
295
  end
@@ -326,7 +341,7 @@ class Hocon::Impl::Tokenizer
326
341
  if FIRST_NUMBER_CHARS.index(c)
327
342
  t = pull_number(c)
328
343
  elsif NOT_IN_UNQUOTED_TEXT.index(c)
329
- raise problem(c, "Reserved character '#{c}' is not allowed outside quotes", true)
344
+ raise Hocon::Impl::Tokenizer::TokenIterator.problem(@line_origin, c, "Reserved character '#{c}' is not allowed outside quotes", true, nil)
330
345
  else
331
346
  put_back(c)
332
347
  t = pull_unquoted_text
@@ -4,6 +4,7 @@ require 'hocon/impl/token_type'
4
4
  require 'hocon/impl/config_number'
5
5
  require 'hocon/impl/config_string'
6
6
  require 'hocon/impl/config_boolean'
7
+ require 'hocon/config_error'
7
8
 
8
9
  # FIXME the way the subclasses of Token are private with static isFoo and accessors is kind of ridiculous.
9
10
  class Hocon::Impl::Tokens
@@ -79,12 +80,56 @@ class Hocon::Impl::Tokens
79
80
  @suggest_quotes = suggest_quotes
80
81
  @cause = cause
81
82
  end
83
+
84
+ def what
85
+ @what
86
+ end
87
+
88
+ def message
89
+ @message
90
+ end
91
+
92
+ def suggest_quotes
93
+ @suggest_quotes
94
+ end
95
+
96
+ def cause
97
+ @cause
98
+ end
99
+ end
100
+
101
+ def self.get_problem_message(token)
102
+ if token.is_a?(Problem)
103
+ token.message
104
+ else
105
+ raise Hocon::ConfigError::ConfigBugOrBrokenError.new("tried to get problem message from #{token}", nil)
106
+ end
107
+ end
108
+
109
+ def self.get_problem_suggest_quotes(token)
110
+ if token.is_a?(Problem)
111
+ token.suggest_quotes
112
+ else
113
+ raise Hocon::ConfigError::ConfigBugOrBrokenError.new("tried to get problem suggest_quotes from #{token}", nil)
114
+ end
115
+ end
116
+
117
+ def self.get_problem_cause(token)
118
+ if token.is_a?(Problem)
119
+ token.cause
120
+ else
121
+ raise Hocon::ConfigError::ConfigBugOrBrokenError.new("tried to get problem cause from #{token}", nil)
122
+ end
82
123
  end
83
124
 
84
125
  def self.new_line(origin)
85
126
  Line.new(origin)
86
127
  end
87
128
 
129
+ def self.new_problem(origin, what, message, suggest_quotes, cause)
130
+ Problem.new(origin, what, message, suggest_quotes, cause)
131
+ end
132
+
88
133
  def self.new_comment(origin, text)
89
134
  Comment.new(origin, text)
90
135
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hocon
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -12,7 +12,7 @@ authors:
12
12
  autorequire:
13
13
  bindir: bin
14
14
  cert_chain: []
15
- date: 2014-10-01 00:00:00.000000000 Z
15
+ date: 2014-10-14 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: bundler