Class: KPeg::Multiple
Instance Attribute Summary collapse
-
#max ⇒ Object
readonly
Returns the value of attribute max.
-
#min ⇒ Object
readonly
Returns the value of attribute min.
-
#op ⇒ Object
readonly
Returns the value of attribute op.
-
#save_values ⇒ Object
readonly
Returns the value of attribute save_values.
Attributes inherited from Operator
Instance Method Summary collapse
- #==(obj) ⇒ Object
-
#initialize(op, min, max) ⇒ Multiple
constructor
A new instance of Multiple.
- #inspect ⇒ Object
- #match(x) ⇒ Object
- #save_values! ⇒ Object
Methods inherited from Operator
#detect_tags, #inspect_type, #prune_values, #set_action, #|
Constructor Details
#initialize(op, min, max) ⇒ Multiple
Returns a new instance of Multiple.
235 236 237 238 239 240 241 |
# File 'lib/kpeg/grammar.rb', line 235 def initialize(op, min, max) super() @op = op @min = min @max = max @save_values = nil end |
Instance Attribute Details
#max ⇒ Object (readonly)
Returns the value of attribute max.
243 244 245 |
# File 'lib/kpeg/grammar.rb', line 243 def max @max end |
#min ⇒ Object (readonly)
Returns the value of attribute min.
243 244 245 |
# File 'lib/kpeg/grammar.rb', line 243 def min @min end |
#op ⇒ Object (readonly)
Returns the value of attribute op.
243 244 245 |
# File 'lib/kpeg/grammar.rb', line 243 def op @op end |
#save_values ⇒ Object (readonly)
Returns the value of attribute save_values.
243 244 245 |
# File 'lib/kpeg/grammar.rb', line 243 def save_values @save_values end |
Instance Method Details
#==(obj) ⇒ Object
278 279 280 281 282 283 284 285 |
# File 'lib/kpeg/grammar.rb', line 278 def ==(obj) case obj when Multiple @op == obj.op and @min == obj.min and @max == obj.max else super end end |
#inspect ⇒ Object
287 288 289 |
# File 'lib/kpeg/grammar.rb', line 287 def inspect inspect_type "multi", "#{@min} #{@max ? @max : "*"} #{@op.inspect}" end |
#match(x) ⇒ Object
249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 |
# File 'lib/kpeg/grammar.rb', line 249 def match(x) n = 0 matches = [] start = x.pos while true if m = @op.match(x) matches << m else break end n += 1 if @max and n > @max x.pos = start return nil end end if n >= @min return MatchComposition.new(self, matches) end x.pos = start return nil end |
#save_values! ⇒ Object
245 246 247 |
# File 'lib/kpeg/grammar.rb', line 245 def save_values! @save_values = true end |