Class: KPeg::Rule

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeRule

Returns a new instance of Rule



257
258
259
260
261
# File 'lib/vendor/kpeg/lib/kpeg.rb', line 257

def initialize
  @name = nil
  @action = nil
  @has_tags = false
end

Instance Attribute Details

#actionObject

Returns the value of attribute action



263
264
265
# File 'lib/vendor/kpeg/lib/kpeg.rb', line 263

def action
  @action
end

#nameObject

Returns the value of attribute name



263
264
265
# File 'lib/vendor/kpeg/lib/kpeg.rb', line 263

def name
  @name
end

Instance Method Details

#detect_tags(rules) ⇒ Object



269
270
271
272
273
274
275
276
277
278
279
# File 'lib/vendor/kpeg/lib/kpeg.rb', line 269

def detect_tags(rules)
  tags = []
  rules.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



286
287
288
289
# File 'lib/vendor/kpeg/lib/kpeg.rb', line 286

def inspect_type(tag, body)
  return "#<#{tag} #{body}>" unless @name
  "#<#{tag}:#{@name} #{body}>"
end

#prune_values(values) ⇒ Object



281
282
283
284
# File 'lib/vendor/kpeg/lib/kpeg.rb', line 281

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

#set_action(act) ⇒ Object



265
266
267
# File 'lib/vendor/kpeg/lib/kpeg.rb', line 265

def set_action(act)
  @action = act
end

#|(other) ⇒ Object



291
292
293
# File 'lib/vendor/kpeg/lib/kpeg.rb', line 291

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