From: "IƱaki Baz Castillo" Date: 2009-02-05T04:43:16+09:00 Subject: Re: Using a Class (not an instance) into threads --Boundary-00=_t/eiJDArWrKWquL Content-Type: Multipart/Mixed; boundary="Boundary-00=_t/eiJDArWrKWquL" --Boundary-00=_t/eiJDArWrKWquL Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline El Mi=E9rcoles, 4 de Febrero de 2009, Robert Klemme escribi=F3: > I do not know Ragel but it may well be that the class that Ragel > created has only immutable state necessary for the parser and that the > parsing related state is in instances of that class. =A0Can you post > more of MyParser? There is no usage of class instances, but just class methods and class=20 attributes. I attatch a Ragel generated Ruby parser (it's just a few extract of a SIP=20 parser I'm building). Note that the Ragel generated code is from line 11 up to line 170. Thanks a lot. =2D-=20 I=F1aki Baz Castillo --Boundary-00=_t/eiJDArWrKWquL Content-Type: application/x-ruby; name="parser.rb" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="parser.rb" # line 1 "parser.rl" #!/usr/bin/env ruby data = ARGV[0] + "\r\n" #data = ARGV[0] class SIP_Parser # line 12 "parser.rb" class << self attr_accessor :_rfc3261_trans_keys private :_rfc3261_trans_keys, :_rfc3261_trans_keys= end self._rfc3261_trans_keys = [ 0, 0, 33, 126, 13, 126, 10, 10, 0, 0, 0 ] class << self attr_accessor :_rfc3261_key_spans private :_rfc3261_key_spans, :_rfc3261_key_spans= end self._rfc3261_key_spans = [ 0, 94, 114, 1, 0 ] class << self attr_accessor :_rfc3261_index_offsets private :_rfc3261_index_offsets, :_rfc3261_index_offsets= end self._rfc3261_index_offsets = [ 0, 0, 95, 210, 212 ] class << self attr_accessor :_rfc3261_indicies private :_rfc3261_indicies, :_rfc3261_indicies= end self._rfc3261_indicies = [ 0, 1, 1, 1, 0, 1, 0, 1, 1, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 0, 1, 1, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 1, 3, 1, 1, 0 ] class << self attr_accessor :_rfc3261_trans_targs private :_rfc3261_trans_targs, :_rfc3261_trans_targs= end self._rfc3261_trans_targs = [ 2, 0, 3, 4 ] class << self attr_accessor :rfc3261_start end self.rfc3261_start = 1; class << self attr_accessor :rfc3261_first_final end self.rfc3261_first_final = 4; class << self attr_accessor :rfc3261_error end self.rfc3261_error = 0; class << self attr_accessor :rfc3261_en_main end self.rfc3261_en_main = 1; # line 15 "parser.rl" def self.run_machine(data) # Initialization data = data.unpack("c*") if data.is_a?(String) p = 0 pe = data.length #mark_tag = 0 #tag = "" # line 111 "parser.rb" begin p ||= 0 pe ||= data.length cs = rfc3261_start end # line 27 "parser.rl" # line 119 "parser.rb" begin testEof = false _slen, _trans, _keys, _inds = nil _goto_level = 0 _resume = 10 _eof_trans = 15 _again = 20 _test_eof = 30 _out = 40 while true if _goto_level <= 0 if p == pe _goto_level = _test_eof next end if cs == 0 _goto_level = _out next end end if _goto_level <= _resume _keys = cs << 1 _inds = _rfc3261_index_offsets[cs] _slen = _rfc3261_key_spans[cs] _trans = if ( _slen > 0 && _rfc3261_trans_keys[_keys] <= data[p] && data[p] <= _rfc3261_trans_keys[_keys + 1] ) then _rfc3261_indicies[ _inds + data[p] - _rfc3261_trans_keys[_keys] ] else _rfc3261_indicies[ _inds + _slen ] end cs = _rfc3261_trans_targs[_trans] end if _goto_level <= _again if cs == 0 _goto_level = _out next end p += 1 if p != pe _goto_level = _resume next end end if _goto_level <= _test_eof end if _goto_level <= _out break end end end # line 28 "parser.rl" puts " --------------------------------" puts " Finished: cs: #{cs} p: #{p} pe: #{pe}" return cs end end t1 = Time.now cs = SIP_Parser.run_machine(data) t2 = Time.now puts " Time: #{t2 - t1}" puts " --------------------------------" if cs == 0 puts "ERROR parsing the data!" exit -1 end --Boundary-00=_t/eiJDArWrKWquL-- --Boundary-00=_t/eiJDArWrKWquL--