Sha256: 052d16d296013bb34d3b7c40cb183a7f76298b614450ea73336d6ff2adfe1823

Contents?: true

Size: 1.24 KB

Versions: 11

Compression:

Stored size: 1.24 KB

Contents

# frozen_string_literal: true

module Parser
  # Context of parsing that is represented by a stack of scopes.
  #
  # Supported states:
  # + :class - in the class body (class A; end)
  # + :module - in the module body (module M; end)
  # + :sclass - in the singleton class body (class << obj; end)
  # + :def - in the method body (def m; end)
  # + :defs - in the singleton method body (def self.m; end)
  # + :def_open_args - in the arglist of the method definition
  #                    keep in mind that it's set **only** after reducing the first argument,
  #                    if you need to handle the first argument check `lex_state == expr_fname`
  # + :block - in the block body (tap {})
  # + :lambda - in the lambda body (-> {})
  #
  class Context
    FLAGS = %i[
      in_defined
      in_kwarg
      in_argdef
      in_def
      in_class
      in_block
      in_lambda
      cant_return
    ]

    def initialize
      reset
    end

    def reset
      @in_defined = false
      @in_kwarg = false
      @in_argdef = false
      @in_def = false
      @in_class = false
      @in_block = false
      @in_lambda = false
      @cant_return = false
    end

    attr_accessor(*FLAGS)

    def in_dynamic_block?
      in_block || in_lambda
    end
  end
end

Version data entries

11 entries across 11 versions & 5 rubygems

Version Path
cybrid_api_bank_ruby-0.123.149 vendor/bundle/ruby/3.3.0/gems/parser-3.3.7.0/lib/parser/context.rb
cybrid_api_id_ruby-0.123.149 vendor/bundle/ruby/3.3.0/gems/parser-3.3.7.0/lib/parser/context.rb
cybrid_api_organization_ruby-0.123.149 vendor/bundle/ruby/3.3.0/gems/parser-3.3.7.0/lib/parser/context.rb
cybrid_api_bank_ruby-0.123.148 vendor/bundle/ruby/3.3.0/gems/parser-3.3.7.0/lib/parser/context.rb
cybrid_api_id_ruby-0.123.148 vendor/bundle/ruby/3.3.0/gems/parser-3.3.7.0/lib/parser/context.rb
cybrid_api_organization_ruby-0.123.148 vendor/bundle/ruby/3.3.0/gems/parser-3.3.7.0/lib/parser/context.rb
cybrid_api_bank_ruby-0.123.147 vendor/bundle/ruby/3.3.0/gems/parser-3.3.7.0/lib/parser/context.rb
cybrid_api_organization_ruby-0.123.147 vendor/bundle/ruby/3.3.0/gems/parser-3.3.7.0/lib/parser/context.rb
cybrid_api_id_ruby-0.123.147 vendor/bundle/ruby/3.3.0/gems/parser-3.3.7.0/lib/parser/context.rb
ory-client-1.16.2 vendor/bundle/ruby/3.1.0/gems/parser-3.3.7.0/lib/parser/context.rb
parser-3.3.7.0 lib/parser/context.rb