Class: KPeg::Choice

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

Instance Attribute Summary collapse

Attributes inherited from Operator

#action

Instance Method Summary collapse

Methods inherited from Operator

#detect_tags, #inspect_type, #prune_values, #set_action

Constructor Details

#initialize(*many) ⇒ Choice

Returns a new instance of Choice.



194
195
196
197
# File 'lib/kpeg/grammar.rb', line 194

def initialize(*many)
  super()
  @ops = many
end

Instance Attribute Details

#opsObject (readonly)

Returns the value of attribute ops.



199
200
201
# File 'lib/kpeg/grammar.rb', line 199

def ops
  @ops
end

Instance Method Details

#==(obj) ⇒ Object



220
221
222
223
224
225
226
227
# File 'lib/kpeg/grammar.rb', line 220

def ==(obj)
  case obj
  when Choice
    @ops == obj.ops
  else
    super
  end
end

#inspectObject



229
230
231
# File 'lib/kpeg/grammar.rb', line 229

def inspect
  inspect_type "any", @ops.map { |i| i.inspect }.join(' | ')
end

#match(x) ⇒ Object



206
207
208
209
210
211
212
213
214
215
216
217
218
# File 'lib/kpeg/grammar.rb', line 206

def match(x)
  pos = x.pos

  @ops.each do |c|
    if m = c.match(x)
      return m
    end

    x.pos = pos
  end

  return nil
end

#|(other) ⇒ Object



201
202
203
204
# File 'lib/kpeg/grammar.rb', line 201

def |(other)
  @ops << Grammar.resolve(other)
  self
end