Class: KPeg::Choice
Instance Attribute Summary collapse
-
#ops ⇒ Object
readonly
Returns the value of attribute ops.
Attributes inherited from Operator
Instance Method Summary collapse
- #==(obj) ⇒ Object
-
#initialize(*many) ⇒ Choice
constructor
A new instance of Choice.
- #inspect ⇒ Object
- #match(x) ⇒ Object
- #|(other) ⇒ Object
Methods inherited from Operator
#detect_tags, #inspect_type, #prune_values, #set_action
Constructor Details
#initialize(*many) ⇒ Choice
Returns a new instance of Choice.
204 205 206 207 |
# File 'lib/kpeg/grammar.rb', line 204 def initialize(*many) super() @ops = many end |
Instance Attribute Details
#ops ⇒ Object (readonly)
Returns the value of attribute ops.
209 210 211 |
# File 'lib/kpeg/grammar.rb', line 209 def ops @ops end |
Instance Method Details
#==(obj) ⇒ Object
230 231 232 233 234 235 236 237 |
# File 'lib/kpeg/grammar.rb', line 230 def ==(obj) case obj when Choice @ops == obj.ops else super end end |
#inspect ⇒ Object
239 240 241 |
# File 'lib/kpeg/grammar.rb', line 239 def inspect inspect_type "any", @ops.map { |i| i.inspect }.join(' | ') end |
#match(x) ⇒ Object
216 217 218 219 220 221 222 223 224 225 226 227 228 |
# File 'lib/kpeg/grammar.rb', line 216 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 |