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
231 232 233 |
# File 'lib/protobug/compiler/builder.rb', line 231 def content @content end |
#type ⇒ Object
Returns the value of attribute type
231 232 233 |
# File 'lib/protobug/compiler/builder.rb', line 231 def type @type end |
Instance Method Details
#compact? ⇒ Boolean
258 259 260 261 262 263 264 265 |
# File 'lib/protobug/compiler/builder.rb', line 258 def compact? case type when :operator COMPACT_OPERATORS.include?(content) when :delimiter content == "." end end |
#empty? ⇒ Boolean
252 253 254 |
# File 'lib/protobug/compiler/builder.rb', line 252 def empty? false end |
#render(q) ⇒ Object
rubocop:disable Naming/MethodParameterName
233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 |
# File 'lib/protobug/compiler/builder.rb', line 233 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 < 0 q.text formatted_int else q.text content.inspect end else raise "Unknown token type: #{type}" end end |