Class: Protobug::Compiler::Builder::Token
- Inherits:
-
Struct
- Object
- Struct
- Protobug::Compiler::Builder::Token
- Defined in:
- lib/protobug/compiler/builder.rb
Constant Summary collapse
- COMPACT_OPERATORS =
rubocop:disable Lint/ConstantDefinitionInBlock
%w[** .. ...].freeze
Instance Attribute Summary collapse
-
#content ⇒ Object
Returns the value of attribute content.
-
#type ⇒ Object
Returns the value of attribute type.
Instance Method Summary collapse
- #compact? ⇒ Boolean
- #empty? ⇒ Boolean
-
#render(q) ⇒ Object
rubocop:disable Naming/MethodParameterName.
Instance Attribute Details
#content ⇒ Object
Returns the value of attribute content
222 223 224 |
# File 'lib/protobug/compiler/builder.rb', line 222 def content @content end |
#type ⇒ Object
Returns the value of attribute type
222 223 224 |
# File 'lib/protobug/compiler/builder.rb', line 222 def type @type end |
Instance Method Details
#compact? ⇒ Boolean
247 248 249 250 251 252 253 254 |
# File 'lib/protobug/compiler/builder.rb', line 247 def compact? case type when :operator COMPACT_OPERATORS.include?(content) when :delimiter content == "." end end |
#empty? ⇒ Boolean
243 |
# File 'lib/protobug/compiler/builder.rb', line 243 def empty? = false |
#render(q) ⇒ Object
rubocop:disable Naming/MethodParameterName
224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 |
# File 'lib/protobug/compiler/builder.rb', line 224 def render(q) # rubocop:disable Naming/MethodParameterName case type when :empty, :keyword, :identifier, :delimiter, :operator q.text content when :literal case content when Integer int_part = Integer(content) formatted_int = int_part.abs.to_s.reverse.gsub(/...(?=.)/, '\&_').reverse formatted_int.insert(0, "-") if int_part.negative? q.text formatted_int else q.text content.inspect end else raise "Unknown token type: #{type}" end end |