Sha256: 6c629bd8f5854cce87138e06874d61e47df4da3ea0fa1bf1e9a0e257750788fd

Contents?: true

Size: 1.38 KB

Versions: 104

Compression:

Stored size: 1.38 KB

Contents

require 'journey/nfa/transition_table'
require 'journey/gtg/transition_table'

module Journey
  module NFA
    class Visitor < Visitors::Visitor
      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
      def initialize ast
        @ast = ast
      end

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

Version data entries

104 entries across 78 versions & 19 rubygems

Version Path
active_mailer-0.0.3 test/fixtures/dummyapp_rails_3.2/vendor/bundle/ruby/1.9.1/gems/journey-1.0.4/lib/journey/nfa/builder.rb
graphael-on-rails-0.5.1 vendor/bundle/gems/journey-1.0.4/lib/journey/nfa/builder.rb
graphael-on-rails-0.0.1 vendor/bundle/gems/journey-1.0.4/lib/journey/nfa/builder.rb
challah-0.9.1.beta.3 vendor/bundle/gems/journey-1.0.4/lib/journey/nfa/builder.rb
devise_sociable-0.1.0 vendor/bundle/gems/journey-1.0.4/lib/journey/nfa/builder.rb
backbone-queryparams-rails-0.0.1 vendor/bundle/gems/journey-1.0.4/lib/journey/nfa/builder.rb
railscast-assets-0.0.2 vendor/bundle/gems/journey-1.0.4/lib/journey/nfa/builder.rb
railscast-assets-0.0.2 vendor/bundle/gems/backbone-forms-on-rails-0.10.0/vendor/bundle/gems/journey-1.0.4/lib/journey/nfa/builder.rb
backbone-forms-on-rails-0.10.0 vendor/bundle/gems/backbone-forms-on-rails-0.10.0/vendor/bundle/gems/journey-1.0.4/lib/journey/nfa/builder.rb
backbone-forms-on-rails-0.10.0 vendor/bundle/gems/journey-1.0.4/lib/journey/nfa/builder.rb
backbone-deep-rails-0.0.1 vendor/bundle/gems/journey-1.0.4/lib/journey/nfa/builder.rb
challah-0.9.1.beta vendor/bundle/gems/journey-1.0.4/lib/journey/nfa/builder.rb
sunrise-cms-0.5.0.rc1 vendor/bundle/ruby/1.9.1/gems/journey-1.0.4/lib/journey/nfa/builder.rb
challah-0.9.0 vendor/bundle/gems/journey-1.0.4/lib/journey/nfa/builder.rb
jquery_regex-0.0.3 vendor/bundle/gems/jquery_regex-0.0.3/vendor/bundle/gems/jquery_regex-0.0.2/vendor/bundle/gems/journey-1.0.4/lib/journey/nfa/builder.rb
jquery_regex-0.0.3 vendor/bundle/gems/jquery_regex-0.0.3/vendor/bundle/gems/journey-1.0.4/lib/journey/nfa/builder.rb
jquery_regex-0.0.3 vendor/bundle/gems/jquery_regex-0.0.2/vendor/bundle/gems/journey-1.0.4/lib/journey/nfa/builder.rb
jquery_regex-0.0.3 vendor/bundle/gems/jquery_regex-0.0.2/vendor/bundle/gems/jquery_regex-0.0.1/vendor/bundle/gems/journey-1.0.4/lib/journey/nfa/builder.rb
jquery_regex-0.0.3 vendor/bundle/gems/jquery_regex-0.0.3/vendor/bundle/gems/jquery_regex-0.0.2/vendor/bundle/gems/jquery_regex-0.0.1/vendor/bundle/gems/journey-1.0.4/lib/journey/nfa/builder.rb
jquery_regex-0.0.3 vendor/bundle/gems/jquery_regex-0.0.3/vendor/bundle/gems/jquery_regex-0.0.1/vendor/bundle/gems/journey-1.0.4/lib/journey/nfa/builder.rb