Class: Riml::AST_Rewriter::VarEqualsComparisonOperator

Inherits:
Riml::AST_Rewriter show all
Defined in:
lib/riml/ast_rewriter.rb

Constant Summary collapse

COMPARISON_OPERATOR_MATCH =
Regexp.union(COMPARISON_OPERATORS)

Constants included from Constants

Constants::BUILTIN_COMMANDS, Constants::BUILTIN_FUNCTIONS, Constants::COMPARISON_OPERATORS, Constants::COMPILED_STRING_LOCATION, Constants::DEFINE_KEYWORDS, Constants::END_KEYWORDS, Constants::IGNORECASE_CAPABLE_OPERATORS, Constants::KEYWORDS, Constants::REGISTERS, Constants::RIML_CLASS_COMMANDS, Constants::RIML_COMMANDS, Constants::RIML_END_KEYWORDS, Constants::RIML_FILE_COMMANDS, Constants::RIML_KEYWORDS, Constants::SPECIAL_VARIABLE_PREFIXES, Constants::SPLAT_LITERAL, Constants::UNKNOWN_LOCATION_INFO, Constants::VIML_COMMANDS, Constants::VIML_END_KEYWORDS, Constants::VIML_KEYWORDS

Instance Attribute Summary

Attributes inherited from Riml::AST_Rewriter

#ast, #classes, #options

Instance Method Summary collapse

Methods inherited from Riml::AST_Rewriter

#add_SID_function!, #add_SID_function?, #do_establish_parents, #do_rewrite_on_match, #establish_parents, #initialize, #max_recursion_lvl, #reorder_includes_based_on_class_dependencies!, #resolve_class_dependencies!, #resolve_class_dependencies?, #rewrite, #rewrite_included_and_sourced_files!, #rewrite_on_match, #watch_for_class_pickup

Constructor Details

This class inherits a constructor from Riml::AST_Rewriter

Instance Method Details

#match?(node) ⇒ Boolean

Returns:

  • (Boolean)


371
372
373
374
375
376
# File 'lib/riml/ast_rewriter.rb', line 371

def match?(node)
  Nodes === node &&
  AssignNode === node.nodes[0] &&
  BinaryOperatorNode === (op = node.nodes[0].rhs) &&
  op.operator =~ COMPARISON_OPERATOR_MATCH
end

#replace(node) ⇒ Object



378
379
380
381
382
383
384
385
386
387
388
389
390
391
# File 'lib/riml/ast_rewriter.rb', line 378

def replace(node)
  binary_op = node.nodes[0].rhs
  old_set_var = node.nodes[0]
  assign_true  = old_set_var.dup.tap {|assign_t| assign_t.rhs = TrueNode.new}
  assign_false = old_set_var.dup.tap {|assign_f| assign_f.rhs = FalseNode.new}
  node.nodes = [
    IfNode.new(binary_op, Nodes.new([
      assign_true, ElseNode.new(Nodes.new([
      assign_false
      ]))
    ]))
  ]
  reestablish_parents(node)
end