Class: KPeg::Operator

Inherits:
Object
  • Object
show all
Defined in:
lib/kpeg/grammar.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeOperator

Returns a new instance of Operator.



17
18
19
20
# File 'lib/kpeg/grammar.rb', line 17

def initialize
  @action = nil
  @has_tags = false
end

Instance Attribute Details

#actionObject

Returns the value of attribute action.



22
23
24
# File 'lib/kpeg/grammar.rb', line 22

def action
  @action
end

Instance Method Details

#detect_tags(ops) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
# File 'lib/kpeg/grammar.rb', line 28

def detect_tags(ops)
  tags = []
  ops.each_with_index do |r,idx|
    if r.kind_of?(Tag)
      @has_tags = true
      tags << idx
    end
  end

  @tags = tags if @has_tags
end

#inspect_type(tag, body) ⇒ Object



45
46
47
# File 'lib/kpeg/grammar.rb', line 45

def inspect_type(tag, body)
  "#<#{tag} #{body}>"
end

#prune_values(values) ⇒ Object



40
41
42
43
# File 'lib/kpeg/grammar.rb', line 40

def prune_values(values)
  return values unless @has_tags
  return values.values_at(*@tags)
end

#set_action(act) ⇒ Object



24
25
26
# File 'lib/kpeg/grammar.rb', line 24

def set_action(act)
  @action = act
end

#|(other) ⇒ Object



49
50
51
# File 'lib/kpeg/grammar.rb', line 49

def |(other)
  Choice.new(self, Grammar.resolve(other))
end