Sha256: d388cc0e4473a690f5f7ac87cc47b1fc7a6521b265c9fa7c9b5df43235945c84
Contents?: true
Size: 1.93 KB
Versions: 2
Compression:
Stored size: 1.93 KB
Contents
# encoding: utf-8 module Unparser class Emitter # Emitter for postconditions class Post < self handle :while_post, :until_post children :condition, :body MAP = { while_post: K_WHILE, until_post: K_UNTIL }.freeze handle(*MAP.keys) # Perform dispatch # # @return [undefined] # # @api private # def dispatch visit(body) write(WS, MAP.fetch(node.type), WS) visit(condition) end end # Base class for while and until emitters class Repetition < self MAP = { while: K_WHILE, until: K_UNTIL }.freeze handle(*MAP.keys) children :condition, :body private # Perform dispatch # # @return [undefined] # # @api private # def dispatch if postcontrol? emit_postcontrol else emit_normal end end # Test for postcontrol # # @return [true] # if repetition must be emitted as post control # # @return [false] # otherwise # # @api private # def postcontrol? return false unless body AST.first_assignment_in_body_and_used_in_condition?(local_variable_root, body, condition) end # Emit keyword # # @return [undefined] # # @api private # def emit_keyword write(MAP.fetch(node.type), WS) end # Emit embedded # # @return [undefned] # # @api private # def emit_normal emit_keyword visit(condition) emit_body k_end end # Emit postcontrol # # @return [undefined] # # @api private # def emit_postcontrol visit(body) ws emit_keyword visit(condition) end end # Repetition end # Emitter end # Unparser
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
unparser-0.1.9 | lib/unparser/emitter/repetition.rb |
unparser-0.1.8 | lib/unparser/emitter/repetition.rb |