From 4565f8ab84be4cc6923aa56dea707a40531314d7 Mon Sep 17 00:00:00 2001 From: Ola Bini Date: Thu, 23 Oct 2008 15:29:00 +0200 Subject: [PATCH] Fix most issues --- ext/redcloth_scan/redcloth_attributes.java.rl | 18 +++++-- ext/redcloth_scan/redcloth_common.java.rl | 14 ++--- ext/redcloth_scan/redcloth_inline.java.rl | 24 ++++++--- ext/redcloth_scan/redcloth_scan.java.rl | 51 ++++++++++++++++--- 4 files changed, 81 insertions(+), 26 deletions(-) diff --git a/ext/redcloth_scan/redcloth_attributes.java.rl b/ext/redcloth_scan/redcloth_attributes.java.rl index 7db3e379..48ce1628 100644 --- a/ext/redcloth_scan/redcloth_attributes.java.rl +++ b/ext/redcloth_scan/redcloth_attributes.java.rl @@ -75,13 +75,21 @@ public class RedclothAttributes extends RedclothScanService.Base { private IRubyObject buf; public RedclothAttributes(int machine, IRubyObject self, byte[] data, int p, int pe) { -// System.err.println("RedclothAttributes(data.len: " + data.length + ", p: " + p + ", pe: " + pe + ")"); + System.err.println("RedclothAttributes(data.len: " + data.length + ", p: " + p + ", pe: " + pe + ")"); this.runtime = self.getRuntime(); this.self = self; - this.data = data; - this.p = p; - this.pe = p+pe; - this.eof = p+pe; + + // This is GROSS but necessary for EOF matching + this.data = new byte[pe+1]; + System.arraycopy(data, p, this.data, 0, pe); + this.data[pe] = 0; + + this.p = 0; + this.pe = pe+1; + this.eof = this.pe; + this.orig_p = 0; + this.orig_pe = this.pe; + this.regs = RubyHash.newHash(runtime); this.buf = runtime.getNil(); this.machine = machine; diff --git a/ext/redcloth_scan/redcloth_common.java.rl b/ext/redcloth_scan/redcloth_common.java.rl index a1c21116..cd97b1ce 100644 --- a/ext/redcloth_scan/redcloth_common.java.rl +++ b/ext/redcloth_scan/redcloth_common.java.rl @@ -2,12 +2,12 @@ machine redcloth_common; - action A { reg = p; } - action B { bck = p; } - action T { STORE("text"); } - action X { CLEAR_REGS(); reg = -1; } - action cat { CAT(block); } - action esc { strCatEscaped(self, block, data, ts, te); } + action A { System.err.println("action A{reg=" + p + "}");reg = p; } + action B { System.err.println("action B");bck = p; } + action T { System.err.println("action T");STORE("text"); } + action X { System.err.println("action X");CLEAR_REGS(); reg = -1; } + action cat { System.err.println("action cat");CAT(block); } + action esc { System.err.println("action esc");strCatEscaped(self, block, data, ts, te); } action esc_pre { strCatEscapedForPreformatted(self, block, data, ts, te); } action ignore { ((RubyString)block).append(self.callMethod(runtime.getCurrentContext(), "ignore", regs)); } @@ -115,7 +115,7 @@ p == orig_p || data[(p-1)] == '\r' || data[(p-1)] == '\n' || data[(p-1)] == '\f' } action starts_phrase { - p == orig_p || data[(p-1)] == '\r' || data[(p-1)] == '\n' || data[(p-1)] == '\f' || data[(p-1)] == ' ' + print("starts_phrase: " + (p == orig_p || data[(p-1)] == '\r' || data[(p-1)] == '\n' || data[(p-1)] == '\f' || data[(p-1)] == ' ')) && (p == orig_p || data[(p-1)] == '\r' || data[(p-1)] == '\n' || data[(p-1)] == '\f' || data[(p-1)] == ' ') } }%%; diff --git a/ext/redcloth_scan/redcloth_inline.java.rl b/ext/redcloth_scan/redcloth_inline.java.rl index fd51a7c3..03537e07 100644 --- a/ext/redcloth_scan/redcloth_inline.java.rl +++ b/ext/redcloth_scan/redcloth_inline.java.rl @@ -152,7 +152,7 @@ public class RedclothInline extends RedclothScanService.Base { emdash { INLINE(block, "emdash"); }; endash { INLINE(block, "endash"); }; arrow { INLINE(block, "arrow"); }; - caps { INLINE(block, "caps"); }; + caps { System.err.println("MATCHED caps"); INLINE(block, "caps"); }; acronym { INLINE(block, "acronym"); }; dim { INLINE(block, "dim"); }; trademark { INLINE(block, "trademark"); }; @@ -204,14 +204,17 @@ public class RedclothInline extends RedclothScanService.Base { } public void PASS_CODE(IRubyObject H, String A, String T, int O) { + System.err.println("PASS_CODE"); ((RubyString)H).append(red_pass_code(self, regs, runtime.newSymbol(A), T)); } public void PARSE_ATTR(String A) { + System.err.println("PARSE_ATTR"); red_parse_attr(self, regs, runtime.newSymbol(A)); } public void PARSE_LINK_ATTR(String A) { + System.err.println("PARSE_LINK_ATTR"); red_parse_link_attr(self, regs, runtime.newSymbol(A)); } @@ -219,13 +222,20 @@ public class RedclothInline extends RedclothScanService.Base { private IRubyObject buf; public RedclothInline(IRubyObject self, byte[] data, int p, int pe, IRubyObject refs) { -// System.err.println("RedclothInline(data.len: " + data.length + ", p: " + p + ", pe: " + pe + ")"); + System.err.println("RedclothInline(data.len: " + data.length + ", p: " + p + ", pe: " + pe + ")"); this.runtime = self.getRuntime(); this.self = self; - this.data = data; - this.p = p; - this.pe = p+pe; - this.eof = p+pe; + + // This is GROSS but necessary for EOF matching + this.data = new byte[pe+1]; + System.arraycopy(data, p, this.data, 0, pe); + this.data[pe] = 0; + + this.p = 0; + this.pe = pe+1; + this.eof = this.pe; + this.orig_p = 0; + this.orig_pe = this.pe; this.refs = refs; this.block = RubyString.newEmptyString(runtime); this.regs = runtime.getNil(); @@ -237,6 +247,8 @@ public class RedclothInline extends RedclothScanService.Base { public IRubyObject inline() { %% write init; %% write exec; + System.err.println("gah: p: " + p + " pe: " + pe + " regs: " + regs + " refs: " + refs); + System.err.println(" reg: " + reg); return block; } diff --git a/ext/redcloth_scan/redcloth_scan.java.rl b/ext/redcloth_scan/redcloth_scan.java.rl index b4456eb4..4e569175 100644 --- a/ext/redcloth_scan/redcloth_scan.java.rl +++ b/ext/redcloth_scan/redcloth_scan.java.rl @@ -26,6 +26,10 @@ import org.jruby.util.ByteList; public class RedclothScanService implements BasicLibraryService { public static class Base { + public boolean print(String str) { + System.err.println(str); + return true; + } public void LIST_ITEM() { int aint = 0; IRubyObject aval = ((RubyArray)list_index).entry(nest-1); @@ -139,16 +143,22 @@ public class RedclothScanService implements BasicLibraryService { IRubyObject sym_text = runtime.newSymbol("text"); IRubyObject btype = ((RubyHash)regs).aref(runtime.newSymbol("type")); block = block.callMethod(runtime.getCurrentContext(), "strip"); + System.err.println(":red_block: \"" + block + "\""); if(!block.isNil() && !btype.isNil()) { method = btype.convertToString().intern(); + if(method == runtime.newSymbol("notextile")) { + System.err.println("-NOTEXTILE"); ((RubyHash)regs).aset(sym_text, block); } else { + System.err.println("-INLINE2"); ((RubyHash)regs).aset(sym_text, inline2(self, block, refs)); } if(self.respondsTo(method.asJavaString())) { + System.err.println("-method: " + method); block = self.callMethod(runtime.getCurrentContext(), method.asJavaString(), regs); } else { + System.err.println("-fallback"); IRubyObject fallback = ((RubyHash)regs).aref(runtime.newSymbol("fallback")); if(!fallback.isNil()) { ((RubyString)fallback).append(((RubyHash)regs).aref(sym_text)); @@ -163,18 +173,22 @@ public class RedclothScanService implements BasicLibraryService { } public void strCatEscaped(IRubyObject self, IRubyObject str, byte[] data, int ts, int te) { + System.err.println("strCatEscaped(str="+str+", ts="+ts+", te="+te+")"); IRubyObject sourceStr = RubyString.newString(self.getRuntime(), data, ts, te-ts); + System.err.println(" -- result: " + sourceStr); IRubyObject escapedStr = self.callMethod(self.getRuntime().getCurrentContext(), "escape", sourceStr); ((RubyString)str).concat(escapedStr); } - public void strCatEscapedForPreformatted(IRubyObject self, IRubyObject str, byte[] data, int ts, int te) { + public void strCatEscapedForPreformatted(IRubyObject self, IRubyObject str, byte[] data, int ts, int te) { + System.err.println("strCatEscapedForPreformatted"); IRubyObject sourceStr = RubyString.newString(self.getRuntime(), data, ts, te-ts); IRubyObject escapedStr = self.callMethod(self.getRuntime().getCurrentContext(), "escape_pre", sourceStr); ((RubyString)str).concat(escapedStr); } public void CLEAR(IRubyObject obj) { + System.err.println("CLEAR"); if(block == obj) { block = RubyString.newEmptyString(runtime); } else if(html == obj) { @@ -185,61 +199,75 @@ public class RedclothScanService implements BasicLibraryService { } public void ADD_BLOCK() { + System.err.println("ADD_BLOCK: [before] html=|" + html + "| block=|" + block + "| table=|" + table + "|"); ((RubyString)html).append(red_block(self, regs, block, refs)); + System.err.println(" [after] html=|" + html + "| block=|" + block + "| table=|" + table + "|"); extend = runtime.getNil(); CLEAR(block); CLEAR_REGS(); } public void CLEAR_REGS() { + System.err.println("CLEAR_REGS"); regs = RubyHash.newHash(runtime); } public void CAT(IRubyObject H) { + System.err.println("CAT: (ts="+ts+", te="+te+") \"" + new String(data, ts, te-ts) + "\""); ((RubyString)H).cat(data, ts, te-ts); } public void INLINE(IRubyObject H, String T) { + System.err.println("INLINE: \"" + H + "\" for: " + T); ((RubyString)H).append(self.callMethod(runtime.getCurrentContext(), T, regs)); } public void DONE(IRubyObject H) { + System.err.println("DONE"); ((RubyString)html).append(H); CLEAR(H); CLEAR_REGS(); } public void ADD_EXTENDED_BLOCK() { + System.err.println("ADD_EXTENDED_BLOCK"); ((RubyString)html).append(red_block(self, regs, block, refs)); CLEAR(block); } public void ADD_BLOCKCODE() { + System.err.println("ADD_BLOCKCODE"); ((RubyString)html).append(red_blockcode(self, regs, block)); CLEAR(block); CLEAR_REGS(); } public void ADD_EXTENDED_BLOCKCODE() { + System.err.println("ADD_EXTENDED_BLOCKCODE"); ((RubyString)html).append(red_blockcode(self, regs, block)); CLEAR(block); } public void AINC(String T) { + System.err.println("AINC"); red_inc(regs, runtime.newSymbol(T)); } public void END_EXTENDED() { + System.err.println("END_EXTENDED"); extend = runtime.getNil(); CLEAR_REGS(); } public void ASET(String T, String V) { + System.err.println("ASET"); ((RubyHash)regs).aset(runtime.newSymbol(T), runtime.newString(V)); } public void STORE(String T) { +// System.err.println("STORE: " + T + " p: " + p + " reg: " + reg + "(\""+new String(data, reg, p-reg)+"\")"); if(p > reg && reg >= ts) { + IRubyObject str = RubyString.newString(runtime, data, reg, p-reg); ((RubyHash)regs).aset(runtime.newSymbol(T), str); } else { @@ -248,6 +276,7 @@ public class RedclothScanService implements BasicLibraryService { } public void STORE_B(String T) { + System.err.println("STORE_B: " + T + " p: " + p + " bck: " + bck); if(p > bck && bck >= ts) { IRubyObject str = RubyString.newString(runtime, data, bck, p-bck); ((RubyHash)regs).aset(runtime.newSymbol(T), str); @@ -611,20 +640,26 @@ public class RedclothScanService implements BasicLibraryService { %% write data nofinal; public Transformer(IRubyObject self, byte[] data, int p, int pe, IRubyObject refs) { -// System.err.println("Transformer(data.len: " + data.length + ", p: " + p + ", pe: " + pe + ")"); + System.err.println("Transformer(data.len: " + data.length + ", p: " + p + ", pe: " + pe + ")"); if(p+pe > data.length) { throw new RuntimeException("BLAHAHA"); } this.self = self; - this.data = data; - this.p = p; - this.pe = p+pe; - this.eof = p+pe; + + // This is GROSS but necessary for EOF matching + this.data = new byte[pe+1]; + System.arraycopy(data, p, this.data, 0, pe); + this.data[pe] = 0; + + this.p = 0; + this.pe = pe+1; + this.eof = this.pe; + this.orig_p = 0; + this.orig_pe = this.pe; + this.refs = refs; runtime = self.getRuntime(); - orig_p = p; - orig_pe = pe; html = RubyString.newEmptyString(runtime); table = RubyString.newEmptyString(runtime);