Class: KPeg::Rule

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

Direct Known Subclasses

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

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (Rule) initialize

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

- (Object) action

Returns the value of attribute action



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

def action
  @action
end

- (Object) name

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

- (Object) detect_tags(rules)



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

- (Object) inspect_type(tag, body)



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

- (Object) prune_values(values)



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

- (Object) set_action(act)



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

def set_action(act)
  @action = act
end

- (Object) |(other)



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

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