class KPeg::Operator

Attributes

action[RW]

Public Class Methods

new() click to toggle source
# File lib/kpeg/grammar.rb, line 17
def initialize
  @action = nil
  @has_tags = false
end

Public Instance Methods

detect_tags(ops) click to toggle source
# 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) click to toggle source
# File lib/kpeg/grammar.rb, line 45
def inspect_type(tag, body)
  "#<#{tag} #{body}>"
end
prune_values(values) click to toggle source
# 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) click to toggle source
# File lib/kpeg/grammar.rb, line 24
def set_action(act)
  @action = act
end
|(other) click to toggle source
# File lib/kpeg/grammar.rb, line 49
def |(other)
  Choice.new(self, Grammar.resolve(other))
end