Class: ConcatOperator

Inherits:
RegexOperator show all
Defined in:
lib/ruby_grammar_builder/regex_operators/concat.rb

Overview

The standard RegexOperator, provides concatination

Instance Attribute Summary

Attributes inherited from RegexOperator

#association, #precedence

Instance Method Summary collapse

Methods inherited from RegexOperator

#==, evaluate, #fold_left, #fold_right

Constructor Details

#initializeConcatOperator

Returns a new instance of ConcatOperator.



9
10
11
12
# File 'lib/ruby_grammar_builder/regex_operators/concat.rb', line 9

def initialize
    @precedence = 2
    @association = :left
end

Instance Method Details

#do_evaluate_self(arr_left, arr_right) ⇒ Array<RegexOperator,String>

This method is abstract.

override to provide evaluate the operator

Note:

arr_left and arr_right contain the entire parse array use RegexOperator#fold_left and RegexOperator#fold_right to collect only the portions that this operator is responsible for

<Description>

Parameters:

Returns:



15
16
17
18
19
20
21
22
# File 'lib/ruby_grammar_builder/regex_operators/concat.rb', line 15

def do_evaluate_self(arr_left, arr_right)
    left = fold_left(arr_left)
    right = fold_right(arr_right)

    self_string = left[0]+right[0]

    [left[1], self_string, right[1]].flatten
end