Class: Unparser::Emitter

Inherits:
Object
  • Object
show all
Extended by:
DSL
Includes:
AbstractType, Adamantium::Flat, Constants, 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/case.rb,
lib/unparser/emitter/meta.rb,
lib/unparser/emitter/redo.rb,
lib/unparser/emitter/root.rb,
lib/unparser/emitter/send.rb,
lib/unparser/emitter/alias.rb,
lib/unparser/emitter/begin.rb,
lib/unparser/emitter/block.rb,
lib/unparser/emitter/cbase.rb,
lib/unparser/emitter/class.rb,
lib/unparser/emitter/empty.rb,
lib/unparser/emitter/index.rb,
lib/unparser/emitter/match.rb,
lib/unparser/emitter/retry.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/ensure.rb,
lib/unparser/emitter/lambda.rb,
lib/unparser/emitter/module.rb,
lib/unparser/emitter/rescue.rb,
lib/unparser/emitter/defined.rb,
lib/unparser/emitter/hookexe.rb,
lib/unparser/emitter/literal.rb,
lib/unparser/emitter/resbody.rb,
lib/unparser/emitter/argument.rb,
lib/unparser/emitter/flipflop.rb,
lib/unparser/emitter/variable.rb,
lib/unparser/emitter/op_assign.rb,
lib/unparser/emitter/assignment.rb,
lib/unparser/emitter/repetition.rb,
lib/unparser/emitter/send/unary.rb,
lib/unparser/emitter/send/binary.rb,
lib/unparser/emitter/literal/hash.rb,
lib/unparser/emitter/send/regular.rb,
lib/unparser/emitter/flow_modifier.rb,
lib/unparser/emitter/literal/array.rb,
lib/unparser/emitter/literal/range.rb,
lib/unparser/emitter/literal/regexp.rb,
lib/unparser/emitter/literal/dynamic.rb,
lib/unparser/emitter/send/conditional.rb,
lib/unparser/emitter/literal/primitive.rb,
lib/unparser/emitter/literal/singleton.rb,
lib/unparser/emitter/literal/dynamic_body.rb,
lib/unparser/emitter/literal/execute_string.rb,
lib/unparser/emitter/send/attribute_assignment.rb

Overview

Emitter base class

buggy, argument values are sends to self

ignore :reek:TooManyMethods

Defined Under Namespace

Modules: LocalVariableRoot, Terminated, Unterminated Classes: Alias, ArgExpr, Argument, Arguments, Assignment, Begin, Binary, BinaryAssign, Block, BlockPass, CBase, Case, Class, Const, Def, Defined, Empty, Ensure, FlipFlop, FlowModifier, For, Hookexe, If, Index, KeywordOptional, KwSplat, Kwarg, Lambda, Literal, Match, Meta, Module, Morearg, NthRef, OpAssign, Optarg, Post, Procarg, Redo, Repetition, Resbody, Rescue, Restarg, Retry, Root, SClass, Send, Splat, Super, Undef, Variable, When, Yield, ZSuper

Constant Summary collapse

REGISTRY =

Registry for node emitters

{}
NOINDENT =

rubocop:disable MutableConstant

%i[rescue ensure].to_set.freeze

Constants included from Constants

Constants::BINARY_OPERATORS, Constants::BRACKETS_CURLY, Constants::BRACKETS_ROUND, Constants::BRACKETS_SQUARE, Constants::COMMENT, Constants::DBL_QUOTE, Constants::DEFAULT_DELIMITER, 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::M_PC, Constants::M_PO, Constants::NL, Constants::SNGL_QUOTE, Constants::T_AMP, Constants::T_AND, Constants::T_ASN, Constants::T_ASR, Constants::T_COLON, Constants::T_DCL, Constants::T_DLT, Constants::T_DOT, Constants::T_DSPLAT, Constants::T_LT, Constants::T_NEG, Constants::T_OR, Constants::T_PIPE, Constants::T_SPLAT, Constants::UNARY_OPERATORS, Constants::WS

Class Method Summary collapse

Instance Method Summary collapse

Methods included from NodeHelpers

#n, #s

Class Method Details

.emitter(node, parent) ⇒ 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

Returns:



116
117
118
119
120
121
122
# File 'lib/unparser/emitter.rb', line 116

def self.emitter(node, parent)
  type = node.type
  klass = REGISTRY.fetch(type) do
    raise ArgumentError, "No emitter for node: #{type.inspect}"
  end
  klass.new(node, parent)
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

Returns:

  • (undefined)


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

abstract_method :dispatch

#local_variable_scopeParser::AST::Node

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 local variable root

Returns:

  • (Parser::AST::Node)


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

def local_variable_scope
  parent.local_variable_scope
end

#local_variablesArray<Symbol>

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 assigned lvars

Returns:

  • (Array<Symbol>)


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

abstract_method :local_variables

#node_typeSymbol

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 node type

Returns:

  • (Symbol)


76
77
78
# File 'lib/unparser/emitter.rb', line 76

def node_type
  node.type
end

#terminated?Boolean

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.

Test if node is emitted as terminated expression

Returns:

  • (Boolean)


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

abstract_method :terminated?

#write_to_bufferself

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.

Trigger write to buffer

Returns:

  • (self)


101
102
103
104
105
106
107
# File 'lib/unparser/emitter.rb', line 101

def write_to_buffer
  emit_comments_before if buffer.fresh_line?
  dispatch
  comments.consume(node)
  emit_eof_comments if parent.is_a?(Root)
  self
end