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, Line, Problem, Substitution, UnquotedText, Value

Constant Summary collapse

Token =
Hocon::Impl::Token
TokenType =
Hocon::Impl::TokenType
ConfigNumber =
Hocon::Impl::ConfigNumber
ConfigString =
Hocon::Impl::ConfigString
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)


106
107
108
# File 'lib/hocon/impl/tokens.rb', line 106

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

.comment_text(token) ⇒ Object



110
111
112
113
114
115
116
# File 'lib/hocon/impl/tokens.rb', line 110

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

.new_comment(origin, text) ⇒ Object



86
87
88
# File 'lib/hocon/impl/tokens.rb', line 86

def self.new_comment(origin, text)
  Comment.new(origin, text)
end

.new_line(origin) ⇒ Object



82
83
84
# File 'lib/hocon/impl/tokens.rb', line 82

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

.new_long(origin, value, original_text) ⇒ Object



102
103
104
# File 'lib/hocon/impl/tokens.rb', line 102

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

.new_string(origin, value) ⇒ Object



98
99
100
# File 'lib/hocon/impl/tokens.rb', line 98

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

.new_unquoted_text(origin, s) ⇒ Object



90
91
92
# File 'lib/hocon/impl/tokens.rb', line 90

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

.new_value(value) ⇒ Object



94
95
96
# File 'lib/hocon/impl/tokens.rb', line 94

def self.new_value(value)
  Value.new(value)
end

.newline?(t) ⇒ Boolean

Returns:

  • (Boolean)


150
151
152
# File 'lib/hocon/impl/tokens.rb', line 150

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

.problem?(t) ⇒ Boolean

Returns:

  • (Boolean)


154
155
156
# File 'lib/hocon/impl/tokens.rb', line 154

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

.substitution?(t) ⇒ Boolean

Returns:

  • (Boolean)


118
119
120
# File 'lib/hocon/impl/tokens.rb', line 118

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

.unquoted_text(token) ⇒ Object



126
127
128
129
130
131
132
# File 'lib/hocon/impl/tokens.rb', line 126

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

.unquoted_text?(token) ⇒ Boolean

Returns:

  • (Boolean)


122
123
124
# File 'lib/hocon/impl/tokens.rb', line 122

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

.value(token) ⇒ Object



138
139
140
141
142
143
144
# File 'lib/hocon/impl/tokens.rb', line 138

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

.value?(token) ⇒ Boolean

Returns:

  • (Boolean)


134
135
136
# File 'lib/hocon/impl/tokens.rb', line 134

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

.value_with_type?(t, value_type) ⇒ Boolean

Returns:

  • (Boolean)


146
147
148
# File 'lib/hocon/impl/tokens.rb', line 146

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