Module: Operator

Defined in:
lib/re_duxml/evaluate/operator.rb

Overview

Copyright © 2016 Freescale Semiconductor Inc.

Instance Method Summary collapse

Instance Method Details

#arityFixnum

Returns number of arguments required.

Returns:

  • (Fixnum)

    number of arguments required



90
91
92
93
94
95
# File 'lib/re_duxml/evaluate/operator.rb', line 90

def arity
  nodes.find do |n|
    return n.text.to_i if n.name == 'arity'
  end
  2
end

#grouping?Boolean

Returns:

  • (Boolean)


4
5
6
7
8
9
# File 'lib/re_duxml/evaluate/operator.rb', line 4

def grouping?
  nodes.find do |n|
    return true if n.name == 'pair'
  end
  false
end

#inverseObject



63
64
65
66
67
68
# File 'lib/re_duxml/evaluate/operator.rb', line 63

def inverse
  nodes.find do |n|
    return @logic[n.text] if n.name == 'inverse'
  end
  nil
end

#pairObject

Raises:

  • (Exception)


55
56
57
58
59
60
61
# File 'lib/re_duxml/evaluate/operator.rb', line 55

def pair
  return nil unless grouping?
  nodes.find do |n|
    return @logic[n.text] if n.name == 'pair'
  end
  raise Exception
end

#parent=(logic) ⇒ Object



11
12
13
# File 'lib/re_duxml/evaluate/operator.rb', line 11

def parent=(logic)
  @logic = logic
end

#positionSymbol

Returns :prefix, :infix (default), or :postfix.

Returns:

  • (Symbol)

    :prefix, :infix (default), or :postfix



41
42
43
44
45
46
# File 'lib/re_duxml/evaluate/operator.rb', line 41

def position
  nodes.find do |n|
    return n.text.to_sym if n.name == 'position'
  end
  :infix
end


74
75
76
77
78
79
# File 'lib/re_duxml/evaluate/operator.rb', line 74

def print
  nodes.find do |n|
    return n.text if n.name == 'print'
  end
  symbol
end

#regexpRegexp

Returns expression to find operator in string.

Returns:

  • (Regexp)

    expression to find operator in string



82
83
84
85
86
87
# File 'lib/re_duxml/evaluate/operator.rb', line 82

def regexp
  nodes.find do |n|
    return Regexp.new(n.text) if %w(regexp symbol ).include?(n.name)
  end
  # TODO exception here?
end

#reverseObject



48
49
50
51
52
53
# File 'lib/re_duxml/evaluate/operator.rb', line 48

def reverse
  nodes.find do |n|
    return @logic[n.text] if n.name == 'reverse'
  end
  nil
end

#right_associative?Boolean

Returns:

  • (Boolean)


16
17
18
19
20
21
# File 'lib/re_duxml/evaluate/operator.rb', line 16

def right_associative?
  nodes.find do |n|
    return n.text == 'true' if n.name == 'right_associative'
  end
  false
end

#rubyString

Returns name of ruby method corresponding to this operator.

Returns:

  • (String)

    name of ruby method corresponding to this operator



24
25
26
27
28
29
# File 'lib/re_duxml/evaluate/operator.rb', line 24

def ruby
  nodes.find do |n|
    return n.text if n.name == 'ruby'
  end
  symbol
end

#symbolString

Returns literal for operator e.g. ‘+’.

Returns:

  • (String)

    literal for operator e.g. ‘+’

Raises:

  • (Exception)


32
33
34
35
36
37
38
# File 'lib/re_duxml/evaluate/operator.rb', line 32

def symbol
  return nil unless self.respond_to?(:nodes)
  nodes.find do |n|
    return n.text if n.name == 'symbol'
  end
  raise Exception
end

#to_sObject



70
71
72
# File 'lib/re_duxml/evaluate/operator.rb', line 70

def to_s
  symbol
end