Class: Hocon::Impl::Tokens

Inherits:
Object
  • Object
show all
Defined in:
lib/hocon/impl/tokens.rb

Overview

FIXME the way the subclasses of Token are private with static isFoo and accessors is kind of ridiculous.

Defined Under Namespace

Classes: Comment, IgnoredWhitespace, Line, Problem, Substitution, UnquotedText, Value

Constant Summary collapse

Token =
Hocon::Impl::Token
TokenType =
Hocon::Impl::TokenType
ConfigNumber =
Hocon::Impl::ConfigNumber
ConfigInt =
Hocon::Impl::ConfigInt
ConfigDouble =
Hocon::Impl::ConfigDouble
ConfigString =
Hocon::Impl::ConfigString
ConfigNull =
Hocon::Impl::ConfigNull
ConfigBoolean =
Hocon::Impl::ConfigBoolean
ResolveStatus =
Hocon::Impl::ResolveStatus
ConfigBugOrBrokenError =
Hocon::ConfigError::ConfigBugOrBrokenError
START =
Token.new_without_origin(TokenType::START, "start of file", "")
EOF =
Token.new_without_origin(TokenType::EOF, "end of file", "")
COMMA =
Token.new_without_origin(TokenType::COMMA, "','", ",")
EQUALS =
Token.new_without_origin(TokenType::EQUALS, "'='", "=")
COLON =
Token.new_without_origin(TokenType::COLON, "':'", ":")
OPEN_CURLY =
Token.new_without_origin(TokenType::OPEN_CURLY, "'{'", "{")
CLOSE_CURLY =
Token.new_without_origin(TokenType::CLOSE_CURLY, "'}'", "}")
OPEN_SQUARE =
Token.new_without_origin(TokenType::OPEN_SQUARE, "'['", "[")
CLOSE_SQUARE =
Token.new_without_origin(TokenType::CLOSE_SQUARE, "']'", "]")
PLUS_EQUALS =
Token.new_without_origin(TokenType::PLUS_EQUALS, "'+='", "+=")

Class Method Summary collapse

Class Method Details

.comment?(t) ⇒ Boolean

Returns:

  • (Boolean)


345
346
347
# File 'lib/hocon/impl/tokens.rb', line 345

def self.comment?(t)
  t.is_a?(Comment)
end

.comment_text(token) ⇒ Object



349
350
351
352
353
354
355
# File 'lib/hocon/impl/tokens.rb', line 349

def self.comment_text(token)
  if comment?(token)
    token.text
  else
    raise ConfigBugOrBrokenError, "tried to get comment text from #{token}"
  end
end

.get_problem_cause(token) ⇒ Object



337
338
339
340
341
342
343
# File 'lib/hocon/impl/tokens.rb', line 337

def self.get_problem_cause(token)
  if token.is_a?(Problem)
    token.cause
  else
    raise ConfigBugOrBrokenError.new("tried to get problem cause from #{token}")
  end
end

.get_problem_message(token) ⇒ Object



321
322
323
324
325
326
327
# File 'lib/hocon/impl/tokens.rb', line 321

def self.get_problem_message(token)
  if token.is_a?(Problem)
    token.message
  else
    raise ConfigBugOrBrokenError.new("tried to get problem message from #{token}")
  end
end

.get_problem_suggest_quotes(token) ⇒ Object



329
330
331
332
333
334
335
# File 'lib/hocon/impl/tokens.rb', line 329

def self.get_problem_suggest_quotes(token)
  if token.is_a?(Problem)
    token.suggest_quotes
  else
    raise ConfigBugOrBrokenError.new("tried to get problem suggest_quotes from #{token}")
  end
end

.get_problem_what(token) ⇒ Object



313
314
315
316
317
318
319
# File 'lib/hocon/impl/tokens.rb', line 313

def self.get_problem_what(token)
  if token.is_a?(Problem)
    token.what
  else
    raise ConfigBugOrBrokenError, "tried to get problem what from #{token}"
  end
end

.get_substitution_optional(token) ⇒ Object



385
386
387
388
389
390
391
# File 'lib/hocon/impl/tokens.rb', line 385

def self.get_substitution_optional(token)
  if token.is_a?(Substitution)
    token.optional?
  else
    raise ConfigBugOrBrokenError, "tried to get substitution optionality from #{token}"
  end
end

.get_substitution_path_expression(token) ⇒ Object



377
378
379
380
381
382
383
# File 'lib/hocon/impl/tokens.rb', line 377

def self.get_substitution_path_expression(token)
  if token.is_a?(Substitution)
    token.value
  else
    raise ConfigBugOrBrokenError, "tried to get substitution from #{token}"
  end
end

.ignored_whitespace?(token) ⇒ Boolean

Returns:

  • (Boolean)


369
370
371
# File 'lib/hocon/impl/tokens.rb', line 369

def self.ignored_whitespace?(token)
  token.is_a?(IgnoredWhitespace)
end

.new_boolean(origin, value) ⇒ Object



456
457
458
# File 'lib/hocon/impl/tokens.rb', line 456

def self.new_boolean(origin, value)
  new_value(ConfigBoolean.new(origin, value), value.to_s)
end

.new_comment_double_slash(origin, text) ⇒ Object



412
413
414
# File 'lib/hocon/impl/tokens.rb', line 412

def self.new_comment_double_slash(origin, text)
  Comment::DoubleSlashComment.new(origin, text)
end

.new_comment_hash(origin, text) ⇒ Object



416
417
418
# File 'lib/hocon/impl/tokens.rb', line 416

def self.new_comment_hash(origin, text)
  Comment::HashComment.new(origin, text)
end

.new_double(origin, value, orig_text) ⇒ Object



444
445
446
# File 'lib/hocon/impl/tokens.rb', line 444

def self.new_double(origin, value, orig_text)
  new_value(ConfigNumber.new_number(origin, value, orig_text), orig_text)
end

.new_ignored_whitespace(origin, s) ⇒ Object



424
425
426
# File 'lib/hocon/impl/tokens.rb', line 424

def self.new_ignored_whitespace(origin, s)
  IgnoredWhitespace.new(origin, s)
end

.new_int(origin, value, orig_text) ⇒ Object



440
441
442
# File 'lib/hocon/impl/tokens.rb', line 440

def self.new_int(origin, value, orig_text)
  new_value(ConfigNumber.new_number(origin, value, orig_text), orig_text)
end

.new_line(origin) ⇒ Object



404
405
406
# File 'lib/hocon/impl/tokens.rb', line 404

def self.new_line(origin)
  Line.new(origin)
end

.new_long(origin, value, orig_text) ⇒ Object



448
449
450
# File 'lib/hocon/impl/tokens.rb', line 448

def self.new_long(origin, value, orig_text)
  new_value(ConfigNumber.new_number(origin, value, orig_text), orig_text)
end

.new_null(origin) ⇒ Object



452
453
454
# File 'lib/hocon/impl/tokens.rb', line 452

def self.new_null(origin)
  new_value(ConfigNull.new(origin), "null")
end

.new_problem(origin, what, message, suggest_quotes, cause) ⇒ Object



408
409
410
# File 'lib/hocon/impl/tokens.rb', line 408

def self.new_problem(origin, what, message, suggest_quotes, cause)
  Problem.new(origin, what, message, suggest_quotes, cause)
end

.new_string(origin, value, orig_text) ⇒ Object



436
437
438
# File 'lib/hocon/impl/tokens.rb', line 436

def self.new_string(origin, value, orig_text)
  new_value(ConfigString::Quoted.new(origin, value), orig_text)
end

.new_substitution(origin, optional, expression) ⇒ Object



428
429
430
# File 'lib/hocon/impl/tokens.rb', line 428

def self.new_substitution(origin, optional, expression)
  Substitution.new(origin, optional, expression)
end

.new_unquoted_text(origin, s) ⇒ Object



420
421
422
# File 'lib/hocon/impl/tokens.rb', line 420

def self.new_unquoted_text(origin, s)
  UnquotedText.new(origin, s)
end

.new_value(value, orig_text = nil) ⇒ Object



432
433
434
# File 'lib/hocon/impl/tokens.rb', line 432

def self.new_value(value, orig_text = nil)
  Value.new(value, orig_text)
end

.newline?(t) ⇒ Boolean

Returns:

  • (Boolean)


305
306
307
# File 'lib/hocon/impl/tokens.rb', line 305

def self.newline?(t)
  t.is_a?(Line)
end

.problem?(t) ⇒ Boolean

Returns:

  • (Boolean)


309
310
311
# File 'lib/hocon/impl/tokens.rb', line 309

def self.problem?(t)
  t.is_a?(Problem)
end

.substitution?(token) ⇒ Boolean

Returns:

  • (Boolean)


373
374
375
# File 'lib/hocon/impl/tokens.rb', line 373

def self.substitution?(token)
  token.is_a?(Substitution)
end

.unquoted_text(token) ⇒ Object



361
362
363
364
365
366
367
# File 'lib/hocon/impl/tokens.rb', line 361

def self.unquoted_text(token)
  if unquoted_text?(token)
    token.value
  else
    raise ConfigBugOrBrokenError, "tried to get unquoted text from #{token}"
  end
end

.unquoted_text?(token) ⇒ Boolean

Returns:

  • (Boolean)


357
358
359
# File 'lib/hocon/impl/tokens.rb', line 357

def self.unquoted_text?(token)
  token.is_a?(UnquotedText)
end

.value(token) ⇒ Object



293
294
295
296
297
298
299
# File 'lib/hocon/impl/tokens.rb', line 293

def self.value(token)
  if token.is_a?(Value)
    token.value
  else
    raise ConfigBugOrBrokenError, "tried to get value of non-value token #{token}"
  end
end

.value?(token) ⇒ Boolean

Returns:

  • (Boolean)


289
290
291
# File 'lib/hocon/impl/tokens.rb', line 289

def self.value?(token)
  token.is_a?(Value)
end

.value_with_type?(t, value_type) ⇒ Boolean

Returns:

  • (Boolean)


301
302
303
# File 'lib/hocon/impl/tokens.rb', line 301

def self.value_with_type?(t, value_type)
  value?(t) && (value(t).value_type == value_type)
end