Spec-Zone.ru › Ruby 3.4
  1. Prism::
  2. Translation::
  3. Parser::
  4. Builder

class Prism::Translation::Parser::Builder

Построитель, умеющий преобразовывать более современный синтаксис Ruby в синтаксическое дерево в формате гем-пакета whitequark/parser.

Открытые методы экземпляра

block (method_call, begin_t, args, body, end_t) Показать исходный код
# File lib/prism/translation/parser/builder.rb, line 22
def block(method_call, begin_t, args, body, end_t)
  _receiver, _selector, *call_args = *method_call

  if method_call.type == :yield
    diagnostic :error, :block_given_to_yield, nil, method_call.loc.keyword, [loc(begin_t)]
  end

  last_arg = call_args.last
  if last_arg && (last_arg.type == :block_pass || last_arg.type == :forwarded_args)
    diagnostic :error, :block_and_blockarg, nil, last_arg.loc.expression, [loc(begin_t)]
  end

  if args.type == :itarg
    block_type = :itblock
    args = :it
  elsif args.type == :numargs
    block_type = :numblock
    args = args.children[0]
  else
    block_type = :block
  end

  if [:send, :csend, :index, :super, :zsuper, :lambda].include?(method_call.type)
    n(block_type, [ method_call, args, body ],
      block_map(method_call.loc.expression, begin_t, end_t))
  else
    # Code like "return foo 1 do end" is reduced in a weird sequence.
    # Here, method_call is actually (return).
    actual_send, = *method_call
    block =
      n(block_type, [ actual_send, args, body ],
        block_map(actual_send.loc.expression, begin_t, end_t))

    n(method_call.type, [ block ],
      method_call.loc.with_expression(join_exprs(method_call, block)))
  end
end

Следующие три строки добавлены для поддержки синтаксиса параметра блока it в приведённом ниже исходном коде.

if args.type == :itarg block_type = :itblock args = :it

github.com/whitequark/parser/blob/v3.3.7.1/lib/parser/builders/default.rb#L1122-L1155

itarg () Показать исходный код
# File lib/prism/translation/parser/builder.rb, line 11
def itarg
  n(:itarg, [:it], nil)
end

Он представляет аргумент блока it, который ещё не реализован в геме Parser.

Ruby Core © 1993–2025 Yukihiro Matsumoto
Licensed under the Ruby License.
Ruby Standard Library © contributors
Licensed under their own licenses.

Spec-Zone.ru

Настройки Оффлайн Что нового Помощь О нас
Spec-Zone .ru
спецификации, руководства, описания, API