class Yadriggy::Algebra

An interface inspired by object algebra (and tag-less final)

Public Class Methods

new(expr) click to toggle source
# File lib/yadriggy/algebra.rb, line 11
def initialize(expr)
  EvalAlgebra.new(self).evaluate(expr)
end

Public Instance Methods

array(elements) click to toggle source

An array literal. ELEMENTS is an array.

# File lib/yadriggy/algebra.rb, line 146
def array(elements)
  raise NotImplementedError.new('array')
end
array_ref(array, index) click to toggle source
# File lib/yadriggy/algebra.rb, line 127
def array_ref(array, index)
  raise NotImplementedError.new('array')
end
array_ref_field(array, index) click to toggle source

Array reference as L-value

# File lib/yadriggy/algebra.rb, line 133
def array_ref_field(array, index)
  array_ref(array, index)
end
assign(left, op, right) click to toggle source

@param [Object|Array] left the left value. @param [Symbol] op the operator. @param [Object|Array] right the right value.

# File lib/yadriggy/algebra.rb, line 119
def assign(left, op, right)
  if left.is_a?(Array) || right.is_a?(Array)
    raise NotImplementedError.new('multiple assignment')
  else
    binary(left, op, right)
  end
end
begin_end(body, rescue_clause) click to toggle source
# File lib/yadriggy/algebra.rb, line 234
def begin_end(body, rescue_clause)
  raise NotImplementedError.new('begin_end')
end
binary(left, op, right) click to toggle source
# File lib/yadriggy/algebra.rb, line 108
def binary(left, op, right)
  raise NotImplementedError.new('binary')
end
block(params, optionals, rest_params, params_after_rest, keywords, rest_of_keywords, block_param, body) click to toggle source

A block. BODY is a thunk.

# File lib/yadriggy/algebra.rb, line 211
def block(params, optionals, rest_params, params_after_rest, keywords,
          rest_of_keywords, block_param, body)
  raise NotImplementedError.new('block')
end
break_out(op, values) click to toggle source

break, next, redo, retry.

# File lib/yadriggy/algebra.rb, line 198
def break_out(op, values)
  raise NotImplementedError.new('break_out')
end
call(receiver, op, name, args, block_arg, block) click to toggle source

Method call. ARGS is an array. BLOCK is a thunk.

# File lib/yadriggy/algebra.rb, line 161
def call(receiver, op, name, args, block_arg, block)
  raise NotImplementedError.new('call')
end
class_def(name, superclass, body, rescue_clause) click to toggle source
# File lib/yadriggy/algebra.rb, line 252
def class_def(name, superclass, body, rescue_clause)
  raise NotImplementedError.new('class_def')
end
command(receiver, op, name, args, block_arg, block) click to toggle source

Method call without parentheses. ARGS is an array. BLOCK is a thunk.

# File lib/yadriggy/algebra.rb, line 168
def command(receiver, op, name, args, block_arg, block)
  call(receiver, op, name, args, block_arg, block)
end
conditional(op, cond, then_exprs, all_elsif, else_exprs) click to toggle source

if, unless, modifier if/unless, and ternary if (?:) THEN_EXPRS is a thunk. ALL_ELSIF is an array of pairs of elsif condition and its body. Both are thunks. ELSE_EXPRS is a thiuk or nil.

# File lib/yadriggy/algebra.rb, line 178
def conditional(op, cond, then_exprs, all_elsif, else_exprs)
  raise NotImplementedError.new('conditional')
end
const(name, line_no, column) click to toggle source
# File lib/yadriggy/algebra.rb, line 35
def const(name, line_no, column)
  name(name, line_no, column)
end
const_path_field(scope, name) click to toggle source

A constant value in a scope as a L-value.

# File lib/yadriggy/algebra.rb, line 100
def const_path_field(scope, name)
  const_path_ref(scope, name)
end
const_path_ref(scope, name) click to toggle source

A constant value in a scope, such as Foo::Bar.

# File lib/yadriggy/algebra.rb, line 94
def const_path_ref(scope, name)
  raise NotImplementedError.new('const_path_ref')
end
define(name, params, optionals, rest_of_params, params_after_rest, keywords, rest_of_keywords, block_param, body, rescue_clause) click to toggle source

def.

BODY and RESCUE_CLAUSE are thunks.

# File lib/yadriggy/algebra.rb, line 242
def define(name, params, optionals, rest_of_params, params_after_rest,
           keywords, rest_of_keywords, block_param,
           body, rescue_clause)
  raise NotImplementedError.new('define')
end
dots(left, op, right) click to toggle source
# File lib/yadriggy/algebra.rb, line 112
def dots(left, op, right)
  binary(left, op, right)
end
exprs(result, expr) click to toggle source

exprs() sequentially processes each expression in a series of expressions. So, for example, { e1, e2, …, e_n } is processed by exprs(.. exprs(exprs(nil, e1), e2).., e_n). In other words, it is by [e1, e2, …, e_n].inject(nil) {|r,e| exprs(r, evaluate(e))}.

RESULT specifies the result of the previous expression. It is nil if EXPR is the first expression.

# File lib/yadriggy/algebra.rb, line 77
def exprs(result, expr)
  raise NotImplementedError.new('exprs')
end
for_loop(var, set, body) click to toggle source

for loop. BODY is a thunk.

# File lib/yadriggy/algebra.rb, line 192
def for_loop(var, set, body)
  raise NotImplementedError.new('for_loop')
end
global_variable(name, line_no, column) click to toggle source
# File lib/yadriggy/algebra.rb, line 47
def global_variable(name, line_no, column)
  name(name, line_no, column)
end
hash(pairs) click to toggle source

PAIRS is an array of pairs. Each pair is an array where the first element is a key and the second element is a value.

# File lib/yadriggy/algebra.rb, line 154
def hash(pairs)
  raise NotImplementedError.new('hash')
end
identifier(name, line_no, column) click to toggle source
# File lib/yadriggy/algebra.rb, line 27
def identifier(name, line_no, column)
  identifier_or_call(name, line_no, column)
end
identifier_or_call(name, line_no, column) click to toggle source
# File lib/yadriggy/algebra.rb, line 23
def identifier_or_call(name, line_no, column)
  name(name, line_no, column)
end
instance_variable(name, line_no, column) click to toggle source
# File lib/yadriggy/algebra.rb, line 51
def instance_variable(name, line_no, column)
  name(name, line_no, column)
end
label(name, line_no, column) click to toggle source
# File lib/yadriggy/algebra.rb, line 39
def label(name, line_no, column)
  name(name, line_no, column)
end
lambda_expr(params, optionals, rest_params, params_after_rest, keywords, rest_of_keywords, block_param, body) click to toggle source

A lambda expression. BODY is a thunk.

# File lib/yadriggy/algebra.rb, line 219
def lambda_expr(params, optionals, rest_params, params_after_rest,
                keywords, rest_of_keywords, block_param, body)
  block(params, optionals, rest_params, params_after_rest,
        keywords, rest_of_keywords, block_param, body)
end
loop(op, cond, body) click to toggle source

while, until, and modifier while/until. COND and BODY are thunks.

# File lib/yadriggy/algebra.rb, line 185
def loop(op, cond, body)
  raise NotImplementedError.new('loop')
end
module_def(name, body, rescue_clause) click to toggle source
# File lib/yadriggy/algebra.rb, line 248
def module_def(name, body, rescue_clause)
  raise NotImplementedError.new('module_def')
end
name(name, line_no, column) click to toggle source
# File lib/yadriggy/algebra.rb, line 19
def name(name, line_no, column)
  raise NotImplementedError.new('name')
end
nil_value() click to toggle source
# File lib/yadriggy/algebra.rb, line 15
def nil_value()
  raise NotImplementedError.new('nil_value')
end
number(value, line_no, column) click to toggle source
# File lib/yadriggy/algebra.rb, line 63
def number(value, line_no, column)
  raise NotImplementedError.new('number')
end
paren(element) click to toggle source

An expression surrounded with ().

# File lib/yadriggy/algebra.rb, line 139
def paren(element)
  raise NotImplementedError.new('paren')
end
program(elements) click to toggle source

A whole program.

ELEMENTS is the result of processing the program elements.

# File lib/yadriggy/algebra.rb, line 264
def program(elements)
  raise NotImplementedError.new('program')
end
rescue_end(types, parameter, body, nested_rescue, else_clause, ensure_clause) click to toggle source

rescue-else-ensure-end. BODY, NESTED_RESCUE, ELSE_CLAUSE, and ENSURE_CLAUSE are thunks.

# File lib/yadriggy/algebra.rb, line 229
def rescue_end(types, parameter, body, nested_rescue,
               else_clause, ensure_clause)
  raise NotImplementedError.new('rescue_end')
end
reserved(name, line_no, column) click to toggle source
# File lib/yadriggy/algebra.rb, line 31
def reserved(name, line_no, column)
  name(name, line_no, column)
end
return_values(values) click to toggle source

An expression with return.

# File lib/yadriggy/algebra.rb, line 204
def return_values(values)
  raise NotImplementedError.new('return_values')
end
singular_class_def(name, body, rescue_clause) click to toggle source
# File lib/yadriggy/algebra.rb, line 256
def singular_class_def(name, body, rescue_clause)
  raise NotImplementedError.new('singular_class_def')
end
string_interpolation(contents) click to toggle source

CONTENTS is an array of the results of evaluating each component.

# File lib/yadriggy/algebra.rb, line 84
def string_interpolation(contents)
  raise NotImplementedError.new('string_interpolation')
end
string_literal(value, line_no, column) click to toggle source
# File lib/yadriggy/algebra.rb, line 88
def string_literal(value, line_no, column)
  raise NotImplementedError.new('string_literal')
end
super_method(expr) click to toggle source
# File lib/yadriggy/algebra.rb, line 59
def super_method(expr)
  raise NotImplementedError.new('super_method')
end
symbol(name, line_no, column) click to toggle source
# File lib/yadriggy/algebra.rb, line 43
def symbol(name, line_no, column)
  raise NotImplementedError.new('symbol')
end
unary(op, expr) click to toggle source
# File lib/yadriggy/algebra.rb, line 104
def unary(op, expr)
  raise NotImplementedError.new('unary')
end
variable_call(name, line_no, column) click to toggle source
# File lib/yadriggy/algebra.rb, line 55
def variable_call(name, line_no, column)
  identifier_or_call(name, line_no, column)
end