Sha256: 0af43b8de9b7bb8bf890ee295b8091891d0ac4cbacf0c9ee03f6cdb4490f0a96

Contents?: true

Size: 1.59 KB

Versions: 161

Compression:

Stored size: 1.59 KB

Contents

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

161 entries across 156 versions & 12 rubygems

Version Path
actionpack-4.1.14.1 lib/action_dispatch/journey/nfa/builder.rb
angular-rails4-templates-0.4.1 vendor/ruby/2.1.0/gems/actionpack-4.2.4/lib/action_dispatch/journey/nfa/builder.rb
angular-rails4-templates-0.4.1 vendor/ruby/2.1.0/gems/actionpack-4.1.13/lib/action_dispatch/journey/nfa/builder.rb
angular-rails4-templates-0.4.0 vendor/ruby/2.1.0/gems/actionpack-4.1.13/lib/action_dispatch/journey/nfa/builder.rb
angular-rails4-templates-0.4.0 vendor/ruby/2.1.0/gems/actionpack-4.2.4/lib/action_dispatch/journey/nfa/builder.rb
actionpack-5.0.0.beta1 lib/action_dispatch/journey/nfa/builder.rb
angular-rails4-templates-0.3.0 vendor/ruby/2.1.0/gems/actionpack-4.2.4/lib/action_dispatch/journey/nfa/builder.rb
angular-rails4-templates-0.3.0 vendor/ruby/2.1.0/gems/actionpack-4.1.13/lib/action_dispatch/journey/nfa/builder.rb
actionpack-4.1.14 lib/action_dispatch/journey/nfa/builder.rb
actionpack-4.2.5 lib/action_dispatch/journey/nfa/builder.rb
actionpack-4.2.5.rc2 lib/action_dispatch/journey/nfa/builder.rb
actionpack-4.1.14.rc2 lib/action_dispatch/journey/nfa/builder.rb
actionpack-4.2.5.rc1 lib/action_dispatch/journey/nfa/builder.rb
actionpack-4.1.14.rc1 lib/action_dispatch/journey/nfa/builder.rb
sc_core-0.0.7 test/dummy/vendor/bundle/ruby/2.2.0/gems/actionpack-4.2.4/lib/action_dispatch/journey/nfa/builder.rb
actionpack-4.2.4 lib/action_dispatch/journey/nfa/builder.rb
actionpack-4.1.13 lib/action_dispatch/journey/nfa/builder.rb
actionpack-4.2.4.rc1 lib/action_dispatch/journey/nfa/builder.rb
actionpack-4.1.13.rc1 lib/action_dispatch/journey/nfa/builder.rb
solidus_backend-1.0.0.pre3 vendor/bundle/gems/actionpack-4.2.3/lib/action_dispatch/journey/nfa/builder.rb