Class: SyntaxTree::CLI::Expr

Inherits:
Action
  • Object
show all
Defined in:
lib/syntax_tree/cli.rb

Overview

An action of the CLI that outputs a pattern-matching Ruby expression that would match the first expression of the input given.

Instance Attribute Summary

Attributes inherited from Action

#options

Instance Method Summary collapse

Methods inherited from Action

#failure, #initialize, #success

Constructor Details

This class inherits a constructor from SyntaxTree::CLI::Action

Instance Method Details

#run(item) ⇒ Object



298
299
300
301
302
303
304
305
306
307
# File 'lib/syntax_tree/cli.rb', line 298

def run(item)
  program = item.handler.parse(item.source)

  if (expressions = program.statements.body) && expressions.size == 1
    puts expressions.first.construct_keys
  else
    warn("The input to `stree expr` must be a single expression.")
    exit(1)
  end
end