Class: Unparser::Emitter
- Inherits:
-
Object
- Object
- Unparser::Emitter
- Includes:
- AbstractType, Adamantium::Flat, Constants
- Defined in:
- lib/unparser/emitter.rb,
lib/unparser/emitter/if.rb,
lib/unparser/emitter/def.rb,
lib/unparser/emitter/for.rb,
lib/unparser/emitter/not.rb,
lib/unparser/emitter/case.rb,
lib/unparser/emitter/next.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/break.rb,
lib/unparser/emitter/cbase.rb,
lib/unparser/emitter/class.rb,
lib/unparser/emitter/empty.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/module.rb,
lib/unparser/emitter/rescue.rb,
lib/unparser/emitter/return.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/index.rb,
lib/unparser/emitter/send/unary.rb,
lib/unparser/emitter/send/binary.rb,
lib/unparser/emitter/literal/range.rb,
lib/unparser/emitter/literal/regexp.rb,
lib/unparser/emitter/literal/dynamic.rb,
lib/unparser/emitter/literal/composed.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
Overview
Emitter base class
Direct Known Subclasses
Alias, ArgExpr, Argument, Arguments, Assignment, Assignment::MLHS, Begin, Binary, BinaryAssign, Block, BlockPass, Blockarg, Break, CBase, Case, Class, Const, Def, Defined, Empty, Ensure, FlipFlop, For, Hookexe, If, KeywordOptional, KeywordRest, Kwarg, Literal, Match, Module, Next, Not, NthRef, OpAssign, Optarg, Post, Redo, Repetition, Resbody, Rescue, Restarg, Retry, Return, SClass, Send, SourceMap, Splat, Super, Undef, Variable, When, Yield, ZSuper
Defined Under Namespace
Classes: Alias, ArgExpr, Argument, Arguments, Assignment, Begin, Binary, BinaryAssign, Block, BlockPass, Blockarg, Break, CBase, Case, Class, Const, Def, Defined, Empty, Ensure, FlipFlop, For, Hookexe, If, KeywordOptional, KeywordRest, Kwarg, Literal, Match, Module, Next, Not, NthRef, OpAssign, Optarg, Post, Redo, Repetition, Resbody, Rescue, Restarg, Retry, Return, SClass, Send, SourceMap, Splat, Super, Undef, Variable, When, Yield, ZSuper
Constant Summary collapse
- REGISTRY =
Registry for node emitters
{}
- NOINDENT =
[:rescue, :ensure].to_set
- DEFAULT_DELIMITER =
', '.freeze
- CURLY_BRACKETS =
IceNine.deep_freeze(%w({ }))
- Root =
::Class.new(self) do def initialize(); end end.send(:new)
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::M_PC, Constants::M_PO, Constants::NL, 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
Instance Attribute Summary collapse
-
#node ⇒ Parser::AST::Node
readonly
private
Return node.
Class Method Summary collapse
-
.emit(*arguments) ⇒ self
private
Emit node into buffer.
-
.visit(node, buffer, parent = Root) ⇒ Emitter
private
Visit node.
Instance Method Summary collapse
-
#dispatch ⇒ undefined
private
Dispatch node.
-
#initialize(node, buffer, parent) ⇒ undefined
constructor
private
Initialize object.
Constructor Details
#initialize(node, buffer, parent) ⇒ undefined
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.
Initialize object
100 101 102 103 |
# File 'lib/unparser/emitter.rb', line 100 def initialize(node, buffer, parent) @node, @buffer, @parent = node, buffer, parent dispatch end |
Instance Attribute Details
#node ⇒ Parser::AST::Node (readonly)
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
139 140 141 |
# File 'lib/unparser/emitter.rb', line 139 def node @node end |
Class Method Details
.emit(*arguments) ⇒ self
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.
Emit node into buffer
86 87 88 89 |
# File 'lib/unparser/emitter.rb', line 86 def self.emit(*arguments) new(*arguments) self end |
.visit(node, buffer, parent = Root) ⇒ 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.
Visit node
116 117 118 119 120 121 122 123 |
# File 'lib/unparser/emitter.rb', line 116 def self.visit(node, buffer, parent = Root) type = node.type emitter = REGISTRY.fetch(type) do raise ArgumentError, "No emitter for node: #{type.inspect}" end emitter.emit(node, buffer, parent) self end |
Instance Method Details
#dispatch ⇒ undefined
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
131 |
# File 'lib/unparser/emitter.rb', line 131 abstract_method :dispatch |