Class: Unparser::Emitter

Inherits:
Object
  • Object
show all
Extended by:
DSL
Includes:
AbstractType, Adamantium, Constants, Generation, NodeHelpers
Defined in:
lib/unparser/emitter.rb,
lib/unparser/emitter/if.rb,
lib/unparser/emitter/def.rb,
lib/unparser/emitter/for.rb,
lib/unparser/emitter/pin.rb,
lib/unparser/emitter/args.rb,
lib/unparser/emitter/case.rb,
lib/unparser/emitter/dstr.rb,
lib/unparser/emitter/dsym.rb,
lib/unparser/emitter/hash.rb,
lib/unparser/emitter/mlhs.rb,
lib/unparser/emitter/pair.rb,
lib/unparser/emitter/root.rb,
lib/unparser/emitter/send.rb,
lib/unparser/emitter/xstr.rb,
lib/unparser/emitter/alias.rb,
lib/unparser/emitter/array.rb,
lib/unparser/emitter/begin.rb,
lib/unparser/emitter/block.rb,
lib/unparser/emitter/cbase.rb,
lib/unparser/emitter/class.rb,
lib/unparser/emitter/float.rb,
lib/unparser/emitter/index.rb,
lib/unparser/emitter/masgn.rb,
lib/unparser/emitter/match.rb,
lib/unparser/emitter/range.rb,
lib/unparser/emitter/splat.rb,
lib/unparser/emitter/super.rb,
lib/unparser/emitter/undef.rb,
lib/unparser/emitter/yield.rb,
lib/unparser/emitter/binary.rb,
lib/unparser/emitter/kwargs.rb,
lib/unparser/emitter/lambda.rb,
lib/unparser/emitter/module.rb,
lib/unparser/emitter/regexp.rb,
lib/unparser/emitter/rescue.rb,
lib/unparser/emitter/simple.rb,
lib/unparser/emitter/defined.rb,
lib/unparser/emitter/hookexe.rb,
lib/unparser/emitter/kwbegin.rb,
lib/unparser/emitter/argument.rb,
lib/unparser/emitter/flipflop.rb,
lib/unparser/emitter/in_match.rb,
lib/unparser/emitter/match_as.rb,
lib/unparser/emitter/variable.rb,
lib/unparser/emitter/match_alt.rb,
lib/unparser/emitter/match_var.rb,
lib/unparser/emitter/op_assign.rb,
lib/unparser/emitter/primitive.rb,
lib/unparser/emitter/assignment.rb,
lib/unparser/emitter/case_guard.rb,
lib/unparser/emitter/case_match.rb,
lib/unparser/emitter/in_pattern.rb,
lib/unparser/emitter/match_rest.rb,
lib/unparser/emitter/repetition.rb,
lib/unparser/emitter/find_pattern.rb,
lib/unparser/emitter/hash_pattern.rb,
lib/unparser/emitter/array_pattern.rb,
lib/unparser/emitter/const_pattern.rb,
lib/unparser/emitter/flow_modifier.rb,
lib/unparser/emitter/match_pattern.rb,
lib/unparser/emitter/match_pattern_p.rb

Overview

Emitter base class

Defined Under Namespace

Modules: LocalVariableRoot Classes: Alias, Args, Argument, Array, ArrayPattern, Assignment, Begin, Binary, BinaryAssign, Block, BlockPass, CBase, Case, CaseGuard, CaseMatch, Class, Const, ConstPattern, DStr, DSym, Def, Defined, FindPattern, FlipFlop, Float, FlowModifier, For, ForwardArg, Hash, HashPattern, Hookexe, If, InMatch, InPattern, Index, KWBegin, KeywordOptional, KwSplat, Kwarg, Kwargs, Lambda, MASGN, MLHS, Match, MatchAlt, MatchAs, MatchPattern, MatchPatternP, MatchRest, MatchVar, Module, NthRef, OpAssign, Optarg, Pair, Pin, Post, Primitive, Procarg, Range, Regexp, Repetition, Rescue, Restarg, Root, SClass, Send, Simple, Splat, Super, Undef, Variable, When, XStr, Yield

Constant Summary collapse

REGISTRY =

Registry for node emitters

{}
NO_INDENT =

rubocop:disable Style/MutableConstant

%i[ensure rescue].freeze

Constants included from Constants

Constants::BINARY_OPERATORS, Constants::KEYWORDS, Constants::K_ALIAS, Constants::K_AND, Constants::K_BEGIN, Constants::K_BREAK, Constants::K_CASE, Constants::K_CLASS, Constants::K_DEF, Constants::K_DEFINE, Constants::K_DEFINED, Constants::K_DO, Constants::K_EEND, Constants::K_ELSE, Constants::K_ELSIF, Constants::K_ENCODING, Constants::K_END, Constants::K_ENSURE, Constants::K_FALSE, Constants::K_FILE, Constants::K_FOR, Constants::K_IF, Constants::K_IN, Constants::K_MODULE, Constants::K_NEXT, Constants::K_NIL, Constants::K_NOT, Constants::K_OR, Constants::K_POSTEXE, Constants::K_PREEXE, Constants::K_REDO, Constants::K_RESCUE, Constants::K_RETRY, Constants::K_RETURN, Constants::K_SELF, Constants::K_SUPER, Constants::K_THEN, Constants::K_TRUE, Constants::K_UNDEF, Constants::K_UNLESS, Constants::K_UNTIL, Constants::K_WHEN, Constants::K_WHILE, Constants::K_YIELD, Constants::UNARY_OPERATORS

Constants included from Generation

Generation::EXTRA_NL

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Generation

#emit_heredoc_reminders, #symbol_name, #write_to_buffer

Methods included from NodeHelpers

#n, #n?, #s, #unwrap_single_begin

Class Method Details

.emitter(buffer:, comments:, node:, local_variable_scope:) ⇒ Emitter

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Return emitter

rubocop:disable Metrics/ParameterLists

Returns:



70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/unparser/emitter.rb', line 70

def self.emitter(buffer:, comments:, node:, local_variable_scope:)
  type = node.type

  klass = REGISTRY.fetch(type) do
    fail UnknownNodeError, "Unknown node type: #{type.inspect}"
  end

  klass.new(
    buffer:               buffer,
    comments:             comments,
    local_variable_scope: local_variable_scope,
    node:                 node
  )
end

Instance Method Details

#dispatchundefined

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Dispatch node write as statement

Returns:

  • (undefined)


92
# File 'lib/unparser/emitter.rb', line 92

abstract_method :dispatch

#emit_mlhsObject



59
60
61
# File 'lib/unparser/emitter.rb', line 59

def emit_mlhs
  dispatch
end

#node_typeObject

LocalVariableRoot



38
39
40
# File 'lib/unparser/emitter.rb', line 38

def node_type
  node.type
end