Sha256: 8ff7b6ea8ff9bccf6ac15076b52c49705eff021c4b68db569c1dcc224b423366

Contents?: true

Size: 1.46 KB

Versions: 124

Compression:

Stored size: 1.46 KB

Contents

# frozen_string_literal: true

module RuboCop
  module AST
    class NodePattern
      class Compiler
        # Generates code that evaluates to a value (Ruby object)
        # This value responds to `===`.
        #
        # Doc on how this fits in the compiling process:
        #   /docs/modules/ROOT/pages/node_pattern.adoc
        class AtomSubcompiler < Subcompiler
          private

          def visit_unify
            compiler.bind(node.child) do
              raise Invalid, 'unified variables can not appear first as argument'
            end
          end

          def visit_symbol
            node.child.inspect
          end
          alias visit_number visit_symbol
          alias visit_string visit_symbol
          alias visit_regexp visit_symbol

          def visit_const
            node.child
          end

          def visit_named_parameter
            compiler.named_parameter(node.child)
          end

          def visit_positional_parameter
            compiler.positional_parameter(node.child)
          end

          def visit_set
            set = node.children.to_set(&:child).freeze
            NodePattern::Sets[set]
          end

          # Assumes other types are node patterns.
          def visit_other_type
            compiler.with_temp_variables do |compare|
              code = compiler.compile_as_node_pattern(node, var: compare)
              "->(#{compare}) { #{code} }"
            end
          end
        end
      end
    end
  end
end

Version data entries

124 entries across 124 versions & 14 rubygems

Version Path
harbr-0.1.39 vendor/bundle/ruby/3.2.0/gems/rubocop-ast-1.30.0/lib/rubocop/ast/node_pattern/compiler/atom_subcompiler.rb
harbr-0.1.38 vendor/bundle/ruby/3.2.0/gems/rubocop-ast-1.30.0/lib/rubocop/ast/node_pattern/compiler/atom_subcompiler.rb
harbr-0.1.37 vendor/bundle/ruby/3.2.0/gems/rubocop-ast-1.30.0/lib/rubocop/ast/node_pattern/compiler/atom_subcompiler.rb
getargv-0.3.3-universal-darwin vendor/bundle/ruby/3.3.0/gems/rubocop-ast-1.30.0/lib/rubocop/ast/node_pattern/compiler/atom_subcompiler.rb
study_line-0.1.6 vendor/bundle/ruby/3.2.0/gems/rubocop-ast-1.30.0/lib/rubocop/ast/node_pattern/compiler/atom_subcompiler.rb
study_line-0.1.5 vendor/bundle/ruby/3.2.0/gems/rubocop-ast-1.30.0/lib/rubocop/ast/node_pattern/compiler/atom_subcompiler.rb
study_line-0.1.4 vendor/bundle/ruby/3.2.0/gems/rubocop-ast-1.30.0/lib/rubocop/ast/node_pattern/compiler/atom_subcompiler.rb
study_line-0.1.3 vendor/bundle/ruby/3.2.0/gems/rubocop-ast-1.30.0/lib/rubocop/ast/node_pattern/compiler/atom_subcompiler.rb
study_line-0.1.2 vendor/bundle/ruby/3.2.0/gems/rubocop-ast-1.30.0/lib/rubocop/ast/node_pattern/compiler/atom_subcompiler.rb
study_line-0.1.1 vendor/bundle/ruby/3.2.0/gems/rubocop-ast-1.30.0/lib/rubocop/ast/node_pattern/compiler/atom_subcompiler.rb
scrapbook-0.3.2 vendor/ruby/2.7.0/gems/rubocop-ast-1.29.0/lib/rubocop/ast/node_pattern/compiler/atom_subcompiler.rb
rubocop-ast-1.30.0 lib/rubocop/ast/node_pattern/compiler/atom_subcompiler.rb
synctera_ruby_sdk-1.1.3 vendor/bundle/ruby/3.2.0/gems/rubocop-ast-1.29.0/lib/rubocop/ast/node_pattern/compiler/atom_subcompiler.rb
synctera_ruby_sdk-1.1.2 vendor/bundle/ruby/3.2.0/gems/rubocop-ast-1.29.0/lib/rubocop/ast/node_pattern/compiler/atom_subcompiler.rb
synctera_ruby_sdk-1.1.1 vendor/bundle/ruby/3.2.0/gems/rubocop-ast-1.29.0/lib/rubocop/ast/node_pattern/compiler/atom_subcompiler.rb
sampero-0.1.0 vendor/bundle/ruby/3.2.0/gems/rubocop-ast-1.29.0/lib/rubocop/ast/node_pattern/compiler/atom_subcompiler.rb
tursodb-0.1.0 vendor/bundle/ruby/3.2.0/gems/rubocop-ast-1.29.0/lib/rubocop/ast/node_pattern/compiler/atom_subcompiler.rb
synctera_ruby_sdk-1.0.0 vendor/bundle/ruby/3.2.0/gems/rubocop-ast-1.29.0/lib/rubocop/ast/node_pattern/compiler/atom_subcompiler.rb
mlh-rubocop-config-1.0.2 vendor/bundle/ruby/3.2.0/gems/rubocop-ast-1.29.0/lib/rubocop/ast/node_pattern/compiler/atom_subcompiler.rb
fablicop-1.10.3 vendor/bundle/ruby/3.2.0/gems/rubocop-ast-1.29.0/lib/rubocop/ast/node_pattern/compiler/atom_subcompiler.rb