Changeset 164

Show
Ignore:
Timestamp:
04/09/2008 22:32:36 (5 months ago)
Author:
stepheneb
Message:

ragel 6.1 fixes for hpricot_scan.java.rl; update jruby object access

Applied the updates to the ragel code for 6.1 to hpricot_scan.java.rl.

Updated decrated method used to access IRubyObject object:

new IRubyObject[]{runtime.newSymbol("buffer_size")}

becomes:

runtime.getCurrentContext(),new IRubyObject[]{runtime.newSymbol("buffer_size")}

The include statements in the main ragel code didn't
work with paths starting with ext/ so I made them
into relative path references which did work.

Updates to the Rakefile to support easy
compilation of the C ragel source code
using different ragel compilation strategies.
This is the default setting:

DEFAULT_RAGEL_C_CODE_GENERATION = "really_fast goto_driven"

which is -G2

The result is no test failures in C and only
one in Java: test_latin1_entities.

Location:
trunk
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • trunk/Rakefile

    r163 r164  
    2222      Dir.glob("{bin,doc,test,lib,extras}/**/*") +  
    2323      Dir.glob("ext/**/*.{h,java,c,rb,rl}") +  
    24       %w[ext/hpricot_scan/hpricot_scan.c ext/hpricot_scan/HpricotScanService.java] # needed because it's generated later 
     24      %w[ext/hpricot_scan/hpricot_scan.c ext/hpricot_scan/HpricotScanService.java] # needed because they are generated later 
     25RAGEL_C_CODE_GENERATION_STYLES = { 
     26  "table_driven" => 'T0', 
     27  "faster_table_driven" => 'T1', 
     28  "flat_table_driven" => 'F0', 
     29  "faster_flat_table_driven" => 'F1', 
     30  "goto_driven" => 'G0', 
     31  "faster_goto_driven" => 'G1', 
     32  "really_fast goto_driven" => 'G2' 
     33  # "n_way_split_really_fast_goto_driven" => 'P<N>' 
     34} 
     35DEFAULT_RAGEL_C_CODE_GENERATION = "really_fast goto_driven" 
    2536SPEC = 
    2637  Gem::Specification.new do |s| 
     
    114125task :hpricot_scan => [:ragel] 
    115126 
    116 desc "returns the ragel version" 
     127desc "Determines the Ragel version and displays it on the console along with the location of the Ragel binary." 
    117128task :ragel_version do 
    118129  @ragel_v = `ragel -v`[/(version )(\S*)/,2].to_f 
     130  puts "Using ragel version: #{@ragel_v}, location: #{`which ragel`}" 
     131  @ragel_v 
    119132end 
    120133 
     
    122135task :ragel => [:ragel_version] do 
    123136  if @ragel_v >= 6.1 
    124     sh %{ragel ext/hpricot_scan/hpricot_scan.rl -G2 -o ext/hpricot_scan/hpricot_scan.c} 
     137    @ragel_c_code_generation_style = RAGEL_C_CODE_GENERATION_STYLES[DEFAULT_RAGEL_C_CODE_GENERATION] 
     138    sh %{ragel ext/hpricot_scan/hpricot_scan.rl -#{@ragel_c_code_generation_style} -o ext/hpricot_scan/hpricot_scan.c} 
    125139  else 
    126140    STDERR.puts "Ragel 6.1 or greater is required." 
     
    129143end 
    130144 
    131 desc "Generates the Java scanner code with Ragel." 
     145# Java only supports the table-driven code  
     146# generation style at this point.  
     147desc "Generates the Java scanner code using the Ragel table-driven code generation style." 
    132148task :ragel_java => [:ragel_version] do 
    133149  if @ragel_v >= 6.1 
    134     sh %{ragel -J ext/hpricot_scan/hpricot_scan.java.rl -G2 -o ext/hpricot_scan/HpricotScanService.java} 
     150    puts "compiling with ragel version #{@ragel_v}" 
     151    sh %{ragel -J -o ext/hpricot_scan/HpricotScanService.java ext/hpricot_scan/hpricot_scan.java.rl}     
    135152  else 
    136153    STDERR.puts "Ragel 6.1 or greater is required." 
  • trunk/ext/hpricot_scan/hpricot_scan.java.rl

    r163 r164  
    2121 
    2222       public void ELE(IRubyObject N) { 
    23          if (tokend > tokstart || text) { 
     23         if (te > ts || text) { 
    2424           IRubyObject raw_string = runtime.getNil(); 
    2525           ele_open = false; text = false; 
    26            if (tokstart != -1 && N != cdata && N != sym_text && N != procins && N != comment) {  
    27              raw_string = runtime.newString(new String(buf,tokstart,tokend-tokstart)); 
     26           if (ts != -1 && N != cdata && N != sym_text && N != procins && N != comment) {  
     27             raw_string = runtime.newString(new String(buf,ts,te-ts)); 
    2828           }  
    2929           rb_yield_tokens(N, tag[0], attr, raw_string, taint); 
     
    7979             mark = mark_aval; 
    8080           } 
    81            if(mark > tokstart) { 
     81           if(mark > ts) { 
    8282             if(N == tag) { 
    83                mark_tag  -= tokstart; 
     83               mark_tag  -= ts; 
    8484             } else if(N == akey) { 
    85                mark_akey -= tokstart; 
     85               mark_akey -= ts; 
    8686             } else if(N == aval) { 
    87                mark_aval -= tokstart; 
     87               mark_aval -= ts; 
    8888             } 
    8989           } 
     
    9595             attr = RubyHash.newHash(runtime); 
    9696           } 
    97            ((RubyHash)attr).aset(K,V); 
     97           ((RubyHash)attr).op_aset(runtime.getCurrentContext(),K,V); 
     98           // ((RubyHash)attr).aset(K,V); 
    9899         } 
    99100       } 
     
    115116           if(ele_open) {  
    116117             ele_open = false;  
    117              if(tokstart > -1) {  
    118                mark_tag = tokstart;  
     118             if(ts > -1) {  
     119               mark_tag = ts;  
    119120             }  
    120121           } else { 
     
    184185  } 
    185186 
    186   include hpricot_common "ext/hpricot_scan/hpricot_common.rl"; 
     187  include hpricot_common "hpricot_common.rl"; 
    187188 
    188189}%% 
     
    210211int cs, act, have = 0, nread = 0, curline = 1, p=-1; 
    211212boolean text = false; 
    212 int tokstart=-1, tokend; 
     213int ts=-1, te; 
     214int eof=-1; 
    213215char[] buf; 
    214216Ruby runtime; 
     
    300302    if ( done && ele_open ) { 
    301303      ele_open = false; 
    302       if(tokstart > -1) { 
    303         mark_tag = tokstart; 
    304         tokstart = -1; 
     304      if(ts > -1) { 
     305        mark_tag = ts; 
     306        ts = -1; 
    305307        text = true; 
    306308      } 
    307309    } 
    308310 
    309     if(tokstart == -1) { 
     311    if(ts == -1) { 
    310312      have = 0; 
    311       /* text nodes have no tokstart because each byte is parsed alone */ 
     313      /* text nodes have no ts because each byte is parsed alone */ 
    312314      if(mark_tag != -1 && text) { 
    313315        if (done) { 
     
    322324      mark_tag = 0; 
    323325    } else { 
    324       have = pe - tokstart; 
    325       System.arraycopy(buf,tokstart,buf,0,have); 
     326      have = pe - ts; 
     327      System.arraycopy(buf,ts,buf,0,have); 
    326328      SLIDE(tag); 
    327329      SLIDE(akey); 
    328330      SLIDE(aval); 
    329       tokend = (tokend - tokstart); 
    330       tokstart = 0; 
     331      te = (te - ts); 
     332      ts = 0; 
    331333    } 
    332334  } 
     
    359361public static void Init_hpricot_scan(Ruby runtime) { 
    360362  RubyModule mHpricot = runtime.defineModule("Hpricot"); 
    361   mHpricot.getMetaClass().attr_accessor(new IRubyObject[]{runtime.newSymbol("buffer_size")}); 
     363  mHpricot.getMetaClass().attr_accessor(runtime.getCurrentContext(),new IRubyObject[]{runtime.newSymbol("buffer_size")}); 
    362364  CallbackFactory fact = runtime.callbackFactory(HpricotScanService.class); 
    363365  mHpricot.getMetaClass().defineMethod("scan",fact.getSingletonMethod("__hpricot_scan",IRubyObject.class)); 
  • trunk/ext/hpricot_scan/hpricot_scan.rl

    r162 r164  
    109109  } 
    110110 
    111   include hpricot_common "ext/hpricot_scan/hpricot_common.rl"; 
     111  include hpricot_common "hpricot_common.rl"; 
    112112 
    113113}%%