Sha256: 3e86af3b113a163c3b050817b689dd4026a8007b3ae85e52688d57fddf3ff058

Contents?: true

Size: 1 KB

Versions: 47

Compression:

Stored size: 1 KB

Contents

# frozen_string_literal: true

require "strscan"

module ActionDispatch
  module Journey # :nodoc:
    module NFA # :nodoc:
      class MatchData # :nodoc:
        attr_reader :memos

        def initialize(memos)
          @memos = memos
        end
      end

      class Simulator # :nodoc:
        attr_reader :tt

        def initialize(transition_table)
          @tt = transition_table
        end

        def simulate(string)
          input = StringScanner.new(string)
          state = tt.eclosure(0)
          until input.eos?
            sym   = input.scan(%r([/.?]|[^/.?]+))
            state = tt.eclosure(tt.move(state, sym))
          end

          acceptance_states = state.find_all { |s|
            tt.accepting?(tt.eclosure(s).sort.last)
          }

          return if acceptance_states.empty?

          memos = acceptance_states.flat_map { |x| tt.memo(x) }.compact

          MatchData.new(memos)
        end

        alias :=~    :simulate
        alias :match :simulate
      end
    end
  end
end

Version data entries

47 entries across 45 versions & 5 rubygems

Version Path
actionpack-6.0.6.1 lib/action_dispatch/journey/nfa/simulator.rb
actionpack-6.0.6 lib/action_dispatch/journey/nfa/simulator.rb
actionpack-6.0.5.1 lib/action_dispatch/journey/nfa/simulator.rb
actionpack-6.0.5 lib/action_dispatch/journey/nfa/simulator.rb
actionpack-6.0.4.8 lib/action_dispatch/journey/nfa/simulator.rb
actionpack-6.0.4.7 lib/action_dispatch/journey/nfa/simulator.rb
actionpack-6.0.4.6 lib/action_dispatch/journey/nfa/simulator.rb
actionpack-6.0.4.5 lib/action_dispatch/journey/nfa/simulator.rb
actionpack-6.0.4.4 lib/action_dispatch/journey/nfa/simulator.rb
actionpack-6.0.4.3 lib/action_dispatch/journey/nfa/simulator.rb
actionpack-6.0.4.2 lib/action_dispatch/journey/nfa/simulator.rb
actionpack-6.0.4.1 lib/action_dispatch/journey/nfa/simulator.rb
actionpack-6.0.4 lib/action_dispatch/journey/nfa/simulator.rb
actionpack-6.0.3.7 lib/action_dispatch/journey/nfa/simulator.rb
actionpack-6.0.3.6 lib/action_dispatch/journey/nfa/simulator.rb
actionpack-6.0.3.5 lib/action_dispatch/journey/nfa/simulator.rb
actionpack-6.0.3.4 lib/action_dispatch/journey/nfa/simulator.rb
actionpack-6.0.3.3 lib/action_dispatch/journey/nfa/simulator.rb
actionpack-6.0.3.2 lib/action_dispatch/journey/nfa/simulator.rb
actionpack-6.0.3.1 lib/action_dispatch/journey/nfa/simulator.rb