Changeset 164
- Timestamp:
- 04/09/2008 22:32:36 (5 months ago)
- Location:
- trunk
- Files:
-
- 3 modified
-
Rakefile (modified) (4 diffs)
-
ext/hpricot_scan/hpricot_scan.java.rl (modified) (9 diffs)
-
ext/hpricot_scan/hpricot_scan.rl (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Rakefile
r163 r164 22 22 Dir.glob("{bin,doc,test,lib,extras}/**/*") + 23 23 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 25 RAGEL_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 } 35 DEFAULT_RAGEL_C_CODE_GENERATION = "really_fast goto_driven" 25 36 SPEC = 26 37 Gem::Specification.new do |s| … … 114 125 task :hpricot_scan => [:ragel] 115 126 116 desc " returns the ragel version"127 desc "Determines the Ragel version and displays it on the console along with the location of the Ragel binary." 117 128 task :ragel_version do 118 129 @ragel_v = `ragel -v`[/(version )(\S*)/,2].to_f 130 puts "Using ragel version: #{@ragel_v}, location: #{`which ragel`}" 131 @ragel_v 119 132 end 120 133 … … 122 135 task :ragel => [:ragel_version] do 123 136 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} 125 139 else 126 140 STDERR.puts "Ragel 6.1 or greater is required." … … 129 143 end 130 144 131 desc "Generates the Java scanner code with Ragel." 145 # Java only supports the table-driven code 146 # generation style at this point. 147 desc "Generates the Java scanner code using the Ragel table-driven code generation style." 132 148 task :ragel_java => [:ragel_version] do 133 149 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} 135 152 else 136 153 STDERR.puts "Ragel 6.1 or greater is required." -
trunk/ext/hpricot_scan/hpricot_scan.java.rl
r163 r164 21 21 22 22 public void ELE(IRubyObject N) { 23 if (t okend > tokstart|| text) {23 if (te > ts || text) { 24 24 IRubyObject raw_string = runtime.getNil(); 25 25 ele_open = false; text = false; 26 if (t okstart!= -1 && N != cdata && N != sym_text && N != procins && N != comment) {27 raw_string = runtime.newString(new String(buf,t okstart,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)); 28 28 } 29 29 rb_yield_tokens(N, tag[0], attr, raw_string, taint); … … 79 79 mark = mark_aval; 80 80 } 81 if(mark > t okstart) {81 if(mark > ts) { 82 82 if(N == tag) { 83 mark_tag -= t okstart;83 mark_tag -= ts; 84 84 } else if(N == akey) { 85 mark_akey -= t okstart;85 mark_akey -= ts; 86 86 } else if(N == aval) { 87 mark_aval -= t okstart;87 mark_aval -= ts; 88 88 } 89 89 } … … 95 95 attr = RubyHash.newHash(runtime); 96 96 } 97 ((RubyHash)attr).aset(K,V); 97 ((RubyHash)attr).op_aset(runtime.getCurrentContext(),K,V); 98 // ((RubyHash)attr).aset(K,V); 98 99 } 99 100 } … … 115 116 if(ele_open) { 116 117 ele_open = false; 117 if(t okstart> -1) {118 mark_tag = t okstart;118 if(ts > -1) { 119 mark_tag = ts; 119 120 } 120 121 } else { … … 184 185 } 185 186 186 include hpricot_common " ext/hpricot_scan/hpricot_common.rl";187 include hpricot_common "hpricot_common.rl"; 187 188 188 189 }%% … … 210 211 int cs, act, have = 0, nread = 0, curline = 1, p=-1; 211 212 boolean text = false; 212 int tokstart=-1, tokend; 213 int ts=-1, te; 214 int eof=-1; 213 215 char[] buf; 214 216 Ruby runtime; … … 300 302 if ( done && ele_open ) { 301 303 ele_open = false; 302 if(t okstart> -1) {303 mark_tag = t okstart;304 t okstart= -1;304 if(ts > -1) { 305 mark_tag = ts; 306 ts = -1; 305 307 text = true; 306 308 } 307 309 } 308 310 309 if(t okstart== -1) {311 if(ts == -1) { 310 312 have = 0; 311 /* text nodes have no t okstartbecause each byte is parsed alone */313 /* text nodes have no ts because each byte is parsed alone */ 312 314 if(mark_tag != -1 && text) { 313 315 if (done) { … … 322 324 mark_tag = 0; 323 325 } else { 324 have = pe - t okstart;325 System.arraycopy(buf,t okstart,buf,0,have);326 have = pe - ts; 327 System.arraycopy(buf,ts,buf,0,have); 326 328 SLIDE(tag); 327 329 SLIDE(akey); 328 330 SLIDE(aval); 329 t okend = (tokend - tokstart);330 t okstart= 0;331 te = (te - ts); 332 ts = 0; 331 333 } 332 334 } … … 359 361 public static void Init_hpricot_scan(Ruby runtime) { 360 362 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")}); 362 364 CallbackFactory fact = runtime.callbackFactory(HpricotScanService.class); 363 365 mHpricot.getMetaClass().defineMethod("scan",fact.getSingletonMethod("__hpricot_scan",IRubyObject.class)); -
trunk/ext/hpricot_scan/hpricot_scan.rl
r162 r164 109 109 } 110 110 111 include hpricot_common " ext/hpricot_scan/hpricot_common.rl";111 include hpricot_common "hpricot_common.rl"; 112 112 113 113 }%%
