Sha256: 60319c035738265692105b5f6a9c466566c525ad70a12decf9b632cc2a8aa9f5

Contents?: true

Size: 1.04 KB

Versions: 2

Compression:

Stored size: 1.04 KB

Contents

# -*- coding: utf-8 -*-
#
#  ノードとノード間遷移
#
#  (self)  pat     dest
#    ■ ----------> □
#       ----------> □
#       ----------> □
#

module ReExpand
  class Trans
    def initialize(pat,dest)
      # pat にマッチしたら dest に遷移
      @pat = pat
      @dest = dest
    end
    
    attr_reader :pat, :dest
    
    def str
      @pat.split(/\t/)[0].to_s
    end
    
    def arg
      if @pat =~ /^(.*)\t(.*)$/ then
        return $2
      else
        return @pat
      end
    end
  end
  
  class Node
    @@id = 1
    @@nodes = {}
    
    def initialize
      @accept = nil
      @trans = []
      @id = @@id
      @@nodes[@id] = self
      @@id += 1
      @pars = []
    end
    
    attr_reader :id
    attr_reader :trans
    attr :accept, true
    attr :pars, true
    
    def addTrans(pat,dest)
      t = Trans.new(pat,dest)
      @trans << t
    end
    
    def Node.node(id) # ノードidからノードを取得
      @@nodes[id.to_i]
    end
    
    def Node.nodes
      @@nodes.values
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
re_expand-0.0.3 lib/Node.rb
re_expand-0.0.2 lib/Node.rb