Sha256: 90efd6af24522d86f7999cb3edae9bd8b9ddd3c29a58614f8be697a24d3dc2d2

Contents?: true

Size: 1.62 KB

Versions: 136

Compression:

Stored size: 1.62 KB

Contents

# frozen_string_literal: true

require "action_dispatch/journey/nfa/transition_table"
require "action_dispatch/journey/gtg/transition_table"

module ActionDispatch
  module Journey # :nodoc:
    module NFA # :nodoc:
      class Visitor < Visitors::Visitor # :nodoc:
        def initialize(tt)
          @tt = tt
          @i  = -1
        end

        def visit_CAT(node)
          left  = visit(node.left)
          right = visit(node.right)

          @tt.merge(left.last, right.first)

          [left.first, right.last]
        end

        def visit_GROUP(node)
          from  = @i += 1
          left  = visit(node.left)
          to    = @i += 1

          @tt.accepting = to

          @tt[from, left.first] = nil
          @tt[left.last, to] = nil
          @tt[from, to] = nil

          [from, to]
        end

        def visit_OR(node)
          from = @i += 1
          children = node.children.map { |c| visit(c) }
          to = @i += 1

          children.each do |child|
            @tt[from, child.first] = nil
            @tt[child.last, to]    = nil
          end

          @tt.accepting = to

          [from, to]
        end

        def terminal(node)
          from_i = @i += 1 # new state
          to_i   = @i += 1 # new state

          @tt[from_i, to_i] = node
          @tt.accepting = to_i
          @tt.add_memo(to_i, node.memo)

          [from_i, to_i]
        end
      end

      class Builder # :nodoc:
        def initialize(ast)
          @ast = ast
        end

        def transition_table
          tt = TransitionTable.new
          Visitor.new(tt).accept(@ast)
          tt
        end
      end
    end
  end
end

Version data entries

136 entries across 128 versions & 7 rubygems

Version Path
actionpack-5.2.4.1 lib/action_dispatch/journey/nfa/builder.rb
actionpack-6.0.2 lib/action_dispatch/journey/nfa/builder.rb
actionpack-6.0.2.rc2 lib/action_dispatch/journey/nfa/builder.rb
zuora_connect_ui-0.10.0 vendor/ruby/2.6.0/gems/actionpack-5.2.3/lib/action_dispatch/journey/nfa/builder.rb
zuora_connect_ui-0.10.0 vendor/ruby/2.6.0/gems/actionpack-6.0.1/lib/action_dispatch/journey/nfa/builder.rb
zuora_connect_ui-0.10.0 vendor/ruby/2.6.0/gems/actionpack-6.0.0/lib/action_dispatch/journey/nfa/builder.rb
actionpack-5.2.4 lib/action_dispatch/journey/nfa/builder.rb
actionpack-6.0.2.rc1 lib/action_dispatch/journey/nfa/builder.rb
actionpack-5.2.4.rc1 lib/action_dispatch/journey/nfa/builder.rb
zuora_connect_ui-0.9.2 vendor/ruby/2.6.0/gems/actionpack-6.0.0/lib/action_dispatch/journey/nfa/builder.rb
zuora_connect_ui-0.9.2 vendor/ruby/2.6.0/gems/actionpack-5.2.3/lib/action_dispatch/journey/nfa/builder.rb
zuora_connect_ui-0.9.2 vendor/ruby/2.6.0/gems/actionpack-6.0.1/lib/action_dispatch/journey/nfa/builder.rb
actionpack-6.0.1 lib/action_dispatch/journey/nfa/builder.rb
chatops-rpc-0.0.2 fixtures/chatops-controller-example/vendor/bundle/ruby/2.5.0/gems/actionpack-6.0.0/lib/action_dispatch/journey/nfa/builder.rb
actionpack-6.0.1.rc1 lib/action_dispatch/journey/nfa/builder.rb
chatops-rpc-0.0.1 fixtures/chatops-controller-example/vendor/bundle/ruby/2.5.0/gems/actionpack-6.0.0/lib/action_dispatch/journey/nfa/builder.rb
zuora_connect_ui-0.9.1 vendor/ruby/2.6.0/gems/actionpack-5.2.3/lib/action_dispatch/journey/nfa/builder.rb
zuora_connect_ui-0.9.1 vendor/ruby/2.6.0/gems/actionpack-6.0.0/lib/action_dispatch/journey/nfa/builder.rb
zuora_connect_ui-0.9.0 vendor/ruby/2.6.0/gems/actionpack-6.0.0/lib/action_dispatch/journey/nfa/builder.rb
zuora_connect_ui-0.9.0 vendor/ruby/2.6.0/gems/actionpack-5.2.3/lib/action_dispatch/journey/nfa/builder.rb