class Yadriggy::Algebra
An interface inspired by object algebra (and tag-less final)
Public Class Methods
# File lib/yadriggy/algebra.rb, line 11 def initialize(expr) EvalAlgebra.new(self).evaluate(expr) end
Public Instance Methods
An array literal. ELEMENTS is an array.
# File lib/yadriggy/algebra.rb, line 146 def array(elements) raise NotImplementedError.new('array') end
# File lib/yadriggy/algebra.rb, line 127 def array_ref(array, index) raise NotImplementedError.new('array') end
Array reference as L-value
# File lib/yadriggy/algebra.rb, line 133 def array_ref_field(array, index) array_ref(array, index) end
@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
# File lib/yadriggy/algebra.rb, line 234 def begin_end(body, rescue_clause) raise NotImplementedError.new('begin_end') end
# File lib/yadriggy/algebra.rb, line 108 def binary(left, op, right) raise NotImplementedError.new('binary') end
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, next, redo, retry.
# File lib/yadriggy/algebra.rb, line 198 def break_out(op, values) raise NotImplementedError.new('break_out') end
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
# File lib/yadriggy/algebra.rb, line 252 def class_def(name, superclass, body, rescue_clause) raise NotImplementedError.new('class_def') end
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
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
# File lib/yadriggy/algebra.rb, line 35 def const(name, line_no, column) name(name, line_no, column) end
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
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
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
# File lib/yadriggy/algebra.rb, line 112 def dots(left, op, right) binary(left, op, right) end
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. BODY is a thunk.
# File lib/yadriggy/algebra.rb, line 192 def for_loop(var, set, body) raise NotImplementedError.new('for_loop') end
# File lib/yadriggy/algebra.rb, line 47 def global_variable(name, line_no, column) name(name, line_no, column) end
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
# File lib/yadriggy/algebra.rb, line 27 def identifier(name, line_no, column) identifier_or_call(name, line_no, column) end
# File lib/yadriggy/algebra.rb, line 23 def identifier_or_call(name, line_no, column) name(name, line_no, column) end
# File lib/yadriggy/algebra.rb, line 51 def instance_variable(name, line_no, column) name(name, line_no, column) end
# File lib/yadriggy/algebra.rb, line 39 def label(name, line_no, column) name(name, line_no, column) end
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
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
# File lib/yadriggy/algebra.rb, line 248 def module_def(name, body, rescue_clause) raise NotImplementedError.new('module_def') end
# File lib/yadriggy/algebra.rb, line 19 def name(name, line_no, column) raise NotImplementedError.new('name') end
# File lib/yadriggy/algebra.rb, line 15 def nil_value() raise NotImplementedError.new('nil_value') end
# File lib/yadriggy/algebra.rb, line 63 def number(value, line_no, column) raise NotImplementedError.new('number') end
An expression surrounded with ().
# File lib/yadriggy/algebra.rb, line 139 def paren(element) raise NotImplementedError.new('paren') end
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-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
# File lib/yadriggy/algebra.rb, line 31 def reserved(name, line_no, column) name(name, line_no, column) end
An expression with return.
# File lib/yadriggy/algebra.rb, line 204 def return_values(values) raise NotImplementedError.new('return_values') end
# File lib/yadriggy/algebra.rb, line 256 def singular_class_def(name, body, rescue_clause) raise NotImplementedError.new('singular_class_def') end
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
# File lib/yadriggy/algebra.rb, line 88 def string_literal(value, line_no, column) raise NotImplementedError.new('string_literal') end
# File lib/yadriggy/algebra.rb, line 59 def super_method(expr) raise NotImplementedError.new('super_method') end
# File lib/yadriggy/algebra.rb, line 43 def symbol(name, line_no, column) raise NotImplementedError.new('symbol') end
# File lib/yadriggy/algebra.rb, line 104 def unary(op, expr) raise NotImplementedError.new('unary') end
# File lib/yadriggy/algebra.rb, line 55 def variable_call(name, line_no, column) identifier_or_call(name, line_no, column) end