Class: KPeg::Operator

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

Direct Known Subclasses

Action, AndPredicate, CharRange, Choice, Collect, Dot, ForeignInvokeRule, InvokeRule, LiteralRegexp, LiteralString, Multiple, NotPredicate, RuleReference, Sequence, Tag

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (Operator) initialize

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

- (Object) action

Returns the value of attribute action



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

def action
  @action
end

Instance Method Details

- (Object) detect_tags(ops)



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

- (Object) inspect_type(tag, body)



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

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

- (Object) prune_values(values)



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

- (Object) set_action(act)



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

def set_action(act)
  @action = act
end

- (Object) |(other)



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

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