Skip to content

Commit

Permalink
Fix most issues
Browse files Browse the repository at this point in the history
  • Loading branch information
olabini committed Oct 23, 2008
1 parent 53d9601 commit 4565f8a
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 26 deletions.
18 changes: 13 additions & 5 deletions ext/redcloth_scan/redcloth_attributes.java.rl
Expand Up @@ -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;
Expand Down
14 changes: 7 additions & 7 deletions ext/redcloth_scan/redcloth_common.java.rl
Expand Up @@ -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)); }

Expand Down Expand Up @@ -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)] == ' ')
}

}%%;
24 changes: 18 additions & 6 deletions ext/redcloth_scan/redcloth_inline.java.rl
Expand Up @@ -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"); };
Expand Down Expand Up @@ -204,28 +204,38 @@ 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));
}

private int opts;
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();
Expand All @@ -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;
}

Expand Down
51 changes: 43 additions & 8 deletions ext/redcloth_scan/redcloth_scan.java.rl
Expand Up @@ -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);
Expand Down Expand Up @@ -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));
Expand All @@ -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) {
Expand All @@ -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 {
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 4565f8a

Please sign in to comment.