/
redcloth_attributes.java.rl
83 lines (64 loc) · 2.09 KB
/
redcloth_attributes.java.rl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/*
* redcloth_attributes.rl
*
* Copyright (C) 2009 Jason Garber
*/
import java.io.IOException;
import org.jruby.Ruby;
import org.jruby.RubyArray;
import org.jruby.RubyClass;
import org.jruby.RubyHash;
import org.jruby.RubyModule;
import org.jruby.RubyNumeric;
import org.jruby.RubyObject;
import org.jruby.RubyString;
import org.jruby.RubySymbol;
import org.jruby.anno.JRubyMethod;
import org.jruby.runtime.Block;
import org.jruby.runtime.CallbackFactory;
import org.jruby.runtime.builtin.IRubyObject;
import org.jruby.exceptions.RaiseException;
import org.jruby.runtime.load.BasicLibraryService;
import org.jruby.util.ByteList;
public class RedclothAttributes extends RedclothScanService.Base {
%%{
machine redcloth_attributes;
include redcloth_common "redcloth_common.java.rl";
include redcloth_attributes "redcloth_attributes.rl";
}%%
%% write data nofinal;
private int machine;
public RedclothAttributes(int machine, IRubyObject self, byte[] data, int p, int pe) {
this.runtime = self.getRuntime();
this.self = self;
// 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.attr_regs = RubyHash.newHash(runtime);
this.machine = machine;
}
public IRubyObject parse() {
%% write init;
cs = machine;
%% write exec;
return regs;
}
public static IRubyObject attributes(IRubyObject self, IRubyObject str) {
ByteList bl = str.convertToString().getByteList();
int cs = redcloth_attributes_en_inline;
return new RedclothAttributes(cs, self, bl.bytes, bl.begin, bl.realSize).parse();
}
public static IRubyObject link_attributes(IRubyObject self, IRubyObject str) {
Ruby runtime = self.getRuntime();
ByteList bl = str.convertToString().getByteList();
int cs = redcloth_attributes_en_link_says;
return new RedclothAttributes(cs, self, bl.bytes, bl.begin, bl.realSize).parse();
}
}