Module: Prism::Merge::NodeTypeNormalizer

Extended by:
Ast::Merge::NodeTyping::Normalizer
Defined in:
lib/prism/merge/node_type_normalizer.rb

Overview

Normalizes backend-specific node types to canonical Ruby types.

Uses Ast::Merge::NodeTyping::Normalizer to provide portable merge rules across different Ruby parser backends.

Backends

Currently supports:

  • :prism - Prism Ruby parser (via TreeHaver::Backends::Prism)
  • :tree_sitter_ruby - tree-sitter-ruby grammar (not yet implemented)

Canonical Types

  • :def - Method definition
  • :class - Class definition
  • :module - Module definition
  • :singleton_class - Singleton class definition
  • :call - Method call
  • :const - Constant assignment
  • :local_var - Local variable assignment
  • :ivar - Instance variable assignment
  • :cvar - Class variable assignment
  • :gvar - Global variable assignment
  • :multi_write - Multiple assignment
  • :if - If conditional
  • :unless - Unless conditional
  • :case - Case statement
  • :case_match - Case/in pattern match
  • :while - While loop
  • :until - Until loop
  • :for - For loop
  • :begin - Begin block
  • :rescue - Rescue clause
  • :else - Else clause
  • :ensure - Ensure clause
  • :lambda - Lambda literal
  • :pre_execution - BEGIN block
  • :post_execution - END block
  • :super - Super call
  • :forwarding_super - Forwarding super call
  • :parens - Parenthesized expression
  • :string - String literal
  • :symbol - Symbol literal
  • :program - Root program node
  • :statements - Statements container
  • :block - Block node
  • :local_var_read - Local variable read
  • :const_path - Constant path
  • :call_op_write - Call operator write (e.g. +=)

See Also:

  • Ast::Merge::NodeTyping::Normalizer

Constant Summary collapse

DEFAULT_BACKEND =

Default backend for Prism normalization

:prism

Class Method Summary collapse

Class Method Details

.canonical_type(backend_type, backend = DEFAULT_BACKEND) ⇒ Symbol?

Get the canonical type for a backend-specific type. Calls .to_s on the input to handle both String (from TreeHaver) and Symbol (from raw Prism) forms.

Parameters:

  • backend_type (Symbol, String, nil)

    The backend's node type

  • backend (Symbol) (defaults to: DEFAULT_BACKEND)

    The backend identifier (defaults to :prism)

Returns:

  • (Symbol, nil)

    Canonical type (or original if no mapping)



128
129
130
131
132
# File 'lib/prism/merge/node_type_normalizer.rb', line 128

def canonical_type(backend_type, backend = DEFAULT_BACKEND)
  return backend_type if backend_type.nil?

  super(backend_type.to_s.to_sym, backend)
end