Class | REXML::Validation::Interleave |
In: |
lib/rexml/validation/relaxng.rb
|
Parent: | Choice |
# File lib/rexml/validation/relaxng.rb, line 449 449: def initialize context 450: super 451: @choice = 0 452: end
# File lib/rexml/validation/relaxng.rb, line 529 529: def expected 530: #puts "IN CHOICE EXPECTED" 531: #puts "EVENTS = #{@events.inspect}" 532: return [@events[@current]] if @events[@current] 533: return @choices[@choice..-1].collect do |x| 534: if x[0].kind_of? State 535: x[0].expected 536: else 537: x[0] 538: end 539: end.flatten 540: end
# File lib/rexml/validation/relaxng.rb, line 542 542: def inspect 543: "< #{to_s} #{@choices.collect{|e| e.collect{|f|f.to_s}.join(', ')}.join(' and ')} >" 544: end
# File lib/rexml/validation/relaxng.rb, line 524 524: def matches?( event ) 525: return @events[@current].matches?( event ) if @events[@current] 526: !@choices[@choice..-1].find{|evt| evt[0].matches?(event)}.nil? 527: end
# File lib/rexml/validation/relaxng.rb, line 488 488: def next( event ) 489: # Find the next series 490: next_current(event) unless @events[@current] 491: return nil unless @events[@current] 492: 493: expand_ref_in( @events, @current ) if @events[@current].class == Ref 494: #puts "In next with #{event.inspect}." 495: #puts "Next (#@current) is #{@events[@current]}" 496: if ( @events[@current].kind_of? State ) 497: @current += 1 498: @events[@current-1].previous = self 499: return @events[@current-1].next( event ) 500: end 501: #puts "Current isn't a state" 502: return @previous.pop.next( event ) if @events[@current].nil? 503: if ( @events[@current].matches?(event) ) 504: @current += 1 505: if @events[@current].nil? 506: #puts "#{inspect[0,5]} 1RETURNING self" unless @choices[@choice].nil? 507: return self unless @choices[@choice].nil? 508: #puts "#{inspect[0,5]} 1RETURNING #{@previous[-1].inspect[0,5]}" 509: return @previous.pop 510: elsif @events[@current].kind_of? State 511: @current += 1 512: #puts "#{inspect[0,5]} 2RETURNING (#{@current-1}) #{@events[@current-1].inspect[0,5]}; on return, next is #{@events[@current]}" 513: @events[@current-1].previous = self 514: return @events[@current-1] 515: else 516: #puts "#{inspect[0,5]} RETURNING self w/ next(#@current) = #{@events[@current]}" 517: return self 518: end 519: else 520: return nil 521: end 522: end
# File lib/rexml/validation/relaxng.rb, line 458 458: def next_current( event ) 459: # Expand references 460: c = 0 ; max = @choices.size 461: while c < max 462: if @choices[c][0].class == Ref 463: expand_ref_in( @choices[c], 0 ) 464: @choices += @choices[c] 465: @choices.delete( @choices[c] ) 466: max -= 1 467: else 468: c += 1 469: end 470: end 471: @events = @choices[@choice..-1].find { |evt| evt[0].matches? event } 472: @current = 0 473: if @events 474: # reorder the choices 475: old = @choices[@choice] 476: idx = @choices.index( @events ) 477: @choices[@choice] = @events 478: @choices[idx] = old 479: @choice += 1 480: end 481: 482: #puts "In next with #{event.inspect}." 483: #puts "events is #{@events.inspect}" 484: @events = [] unless @events 485: end