Changeset 247
- Timestamp:
- 02/27/2008 11:27:58 (9 months ago)
- Location:
- branches/superredcloth/ext/superredcloth_scan
- Files:
-
- 4 modified
-
superredcloth.h (modified) (3 diffs)
-
superredcloth_common.rl (modified) (1 diff)
-
superredcloth_inline.rl (modified) (6 diffs)
-
superredcloth_scan.rl (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/superredcloth/ext/superredcloth_scan/superredcloth.h
r244 r247 10 10 void rb_str_cat_escaped(VALUE str, char *ts, char *te); 11 11 void rb_str_cat_escaped_for_preformatted(VALUE str, char *ts, char *te); 12 VALUE superredcloth_inline(VALUE, char *, char * );13 VALUE superredcloth_inline2(VALUE, VALUE );14 VALUE superredcloth_transform(VALUE, char *, char * );12 VALUE superredcloth_inline(VALUE, char *, char *, VALUE); 13 VALUE superredcloth_inline2(VALUE, VALUE, VALUE); 14 VALUE superredcloth_transform(VALUE, char *, char *, VALUE); 15 15 VALUE superredcloth_transform2(VALUE, VALUE); 16 16 void red_inc(VALUE, VALUE); 17 VALUE red_block(VALUE, VALUE, ID); 18 VALUE red_pass2(VALUE, VALUE, VALUE, VALUE); 19 VALUE red_pass(VALUE, VALUE, VALUE, ID); 17 VALUE red_block(VALUE, VALUE, ID, VALUE); 18 VALUE red_blockcode(VALUE, VALUE, VALUE); 19 VALUE red_pass2(VALUE, VALUE, VALUE, VALUE, VALUE); 20 VALUE red_pass(VALUE, VALUE, VALUE, ID, VALUE); 20 21 VALUE red_pass_code(VALUE, VALUE, VALUE, ID); 21 22 … … 25 26 #define INLINE(H, T) rb_str_append(H, rb_funcall(rb_formatter, rb_intern(#T), 1, regs)) 26 27 #define DONE(H) rb_str_append(html, H); CLEAR(H); regs = rb_hash_new() 27 #define PASS(H, A, T) rb_str_append(H, red_pass(rb_formatter, regs, ID2SYM(rb_intern(#A)), rb_intern(#T) ))28 #define PASS2(H, A, T) rb_str_append(H, red_pass2(rb_formatter, regs, ID2SYM(rb_intern(#A)), ID2SYM(rb_intern(#T)) ))28 #define PASS(H, A, T) rb_str_append(H, red_pass(rb_formatter, regs, ID2SYM(rb_intern(#A)), rb_intern(#T), refs)) 29 #define PASS2(H, A, T) rb_str_append(H, red_pass2(rb_formatter, regs, ID2SYM(rb_intern(#A)), ID2SYM(rb_intern(#T)), refs)) 29 30 #define PASS_CODE(H, A, T) rb_str_append(H, red_pass_code(rb_formatter, regs, ID2SYM(rb_intern(#A)), rb_intern(#T))) 30 31 #define ADD_BLOCK() \ 31 rb_str_append(html, red_block(rb_formatter, regs, block )); \32 rb_str_append(html, red_block(rb_formatter, regs, block, refs)); \ 32 33 extend = Qnil; \ 33 34 CLEAR(block); \ 34 35 regs = rb_hash_new() 35 #define ADD_EXTENDED_BLOCK() rb_str_append(html, red_block(rb_formatter, regs, block )); CLEAR(block);36 #define ADD_EXTENDED_BLOCK() rb_str_append(html, red_block(rb_formatter, regs, block, refs)); CLEAR(block); 36 37 #define ADD_BLOCKCODE() rb_str_append(html, red_blockcode(rb_formatter, regs, block)); CLEAR(block); regs = rb_hash_new() 37 38 #define ADD_EXTENDED_BLOCKCODE() rb_str_append(html, red_blockcode(rb_formatter, regs, block)); CLEAR(block); … … 66 67 } \ 67 68 STORE(T); \ 68 p--; 69 p--; \ 70 if ( !NIL_P(refs) && rb_funcall(refs, rb_intern("has_key?"), 1, rb_hash_aref(regs, ID2SYM(rb_intern(#T)))) ) { \ 71 rb_hash_aset(regs, ID2SYM(rb_intern(#T)), rb_hash_aref(refs, rb_hash_aref(regs, ID2SYM(rb_intern(#T))))); \ 72 } 69 73 #define LIST_ITEM() \ 70 74 int aint = 0; \ -
branches/superredcloth/ext/superredcloth_scan/superredcloth_common.rl
r244 r247 65 65 html_comment = "<!--" (default+) :> "-->"; 66 66 67 # URI tokens (lifted from Mongrel) 68 CTL = (cntrl | 127); 69 safe = ("$" | "-" | "_" | "."); 70 extra = ("!" | "*" | "'" | "(" | ")" | "," | "#"); 71 reserved = (";" | "/" | "?" | ":" | "@" | "&" | "=" | "+"); 72 unsafe = (CTL | " " | "\"" | "%" | "<" | ">"); 73 national = any -- (alpha | digit | reserved | extra | safe | unsafe); 74 unreserved = (alpha | digit | safe | extra | national); 75 escape = ("%" xdigit xdigit); 76 uchar = (unreserved | escape); 77 pchar = (uchar | ":" | "@" | "&" | "=" | "+"); 78 scheme = ( alpha | digit | "+" | "-" | "." )+ ; 79 absolute_uri = (scheme ":" (uchar | reserved )*); 80 safepath = (pchar* (alpha | digit | safe) pchar*) ; 81 path = (safepath ( "/" pchar* )*) ; 82 query = ( uchar | reserved )* ; 83 param = ( pchar | "/" )* ; 84 params = (param ( ";" param )*) ; 85 rel_path = (path (";" params)?) ("?" query)?; 86 absolute_path = ("/"+ rel_path?); 87 target = ("#" pchar*) ; 88 uri = (target | absolute_uri | absolute_path | rel_path) ; 89 67 90 }%%; -
branches/superredcloth/ext/superredcloth_scan/superredcloth_inline.rl
r244 r247 14 14 machine superredcloth_inline; 15 15 include superredcloth_common "ext/superredcloth_scan/superredcloth_common.rl"; 16 17 # URI tokens (lifted from Mongrel)18 CTL = (cntrl | 127);19 safe = ("$" | "-" | "_" | ".");20 extra = ("!" | "*" | "'" | "(" | ")" | "," | "#");21 reserved = (";" | "/" | "?" | ":" | "@" | "&" | "=" | "+");22 unsafe = (CTL | " " | "\"" | "%" | "<" | ">");23 national = any -- (alpha | digit | reserved | extra | safe | unsafe);24 unreserved = (alpha | digit | safe | extra | national);25 escape = ("%" xdigit xdigit);26 uchar = (unreserved | escape);27 pchar = (uchar | ":" | "@" | "&" | "=" | "+");28 scheme = ( alpha | digit | "+" | "-" | "." )+ ;29 absolute_uri = (scheme ":" (uchar | reserved )*);30 safepath = (pchar* (alpha | digit | safe) pchar*) ;31 path = (safepath ( "/" pchar* )*) ;32 query = ( uchar | reserved )* ;33 param = ( pchar | "/" )* ;34 params = (param ( ";" param )*) ;35 rel_path = (path (";" params)?) ("?" query)?;36 absolute_path = ("/"+ rel_path?);37 target = ("#" pchar*) ;38 uri = (target | absolute_uri | absolute_path | rel_path) ;39 16 40 17 # common … … 150 127 151 128 VALUE 152 red_pass(VALUE rb_formatter, VALUE regs, VALUE ref, ID meth )129 red_pass(VALUE rb_formatter, VALUE regs, VALUE ref, ID meth, VALUE refs) 153 130 { 154 131 VALUE txt = rb_hash_aref(regs, ref); 155 if (!NIL_P(txt)) rb_hash_aset(regs, ref, superredcloth_inline2(rb_formatter, txt ));132 if (!NIL_P(txt)) rb_hash_aset(regs, ref, superredcloth_inline2(rb_formatter, txt, refs)); 156 133 return rb_funcall(rb_formatter, meth, 1, regs); 157 134 } … … 170 147 171 148 VALUE 172 red_pass2(VALUE rb_formatter, VALUE regs, VALUE ref, VALUE btype )149 red_pass2(VALUE rb_formatter, VALUE regs, VALUE ref, VALUE btype, VALUE refs) 173 150 { 174 151 btype = rb_hash_aref(regs, btype); 175 152 StringValue(btype); 176 return red_pass(rb_formatter, regs, ref, rb_intern(RSTRING(btype)->ptr) );177 } 178 179 VALUE 180 red_block(VALUE rb_formatter, VALUE regs, VALUE block )153 return red_pass(rb_formatter, regs, ref, rb_intern(RSTRING(btype)->ptr), refs); 154 } 155 156 VALUE 157 red_block(VALUE rb_formatter, VALUE regs, VALUE block, VALUE refs) 181 158 { 182 159 VALUE btype = rb_hash_aref(regs, ID2SYM(rb_intern("type"))); … … 184 161 if ((RSTRING(block)->len > 0) && !NIL_P(btype)) 185 162 { 186 rb_hash_aset(regs, ID2SYM(rb_intern("text")), superredcloth_inline2(rb_formatter, block ));163 rb_hash_aset(regs, ID2SYM(rb_intern("text")), superredcloth_inline2(rb_formatter, block, refs)); 187 164 block = rb_funcall(rb_formatter, rb_intern(RSTRING(btype)->ptr), 1, regs); 188 165 } … … 213 190 214 191 VALUE 215 superredcloth_inline(rb_formatter, p, pe )192 superredcloth_inline(rb_formatter, p, pe, refs) 216 193 VALUE rb_formatter; 217 194 char *p, *pe; 195 VALUE refs; 218 196 { 219 197 int cs, act; … … 295 273 296 274 VALUE 297 superredcloth_inline2(formatter, str )298 VALUE formatter, str ;275 superredcloth_inline2(formatter, str, refs) 276 VALUE formatter, str, refs; 299 277 { 300 278 StringValue(str); 301 return superredcloth_inline(formatter, RSTRING(str)->ptr, RSTRING(str)->ptr + RSTRING(str)->len + 1 );302 } 279 return superredcloth_inline(formatter, RSTRING(str)->ptr, RSTRING(str)->ptr + RSTRING(str)->len + 1, refs); 280 } -
branches/superredcloth/ext/superredcloth_scan/superredcloth_scan.rl
r244 r247 43 43 list_start = ( ( ul | ol )+ N A C :> " "+ ) >{nest = 0;} ; 44 44 blank_line = CRLF; 45 link_alias = ( "[" >{ ASET(type, ignore) } %A phrase %T "]" %A uri ) ; 45 46 46 47 # html blocks … … 139 140 list_start { list_layout = rb_ary_new(); LIST_ITEM(); fgoto list; }; 140 141 table { INLINE(table, table_close); DONE(table); fgoto block; }; 142 link_alias { STORE_URL(href); rb_hash_aset(refs_found, rb_hash_aref(regs, ID2SYM(rb_intern("text"))), rb_hash_aref(regs, ID2SYM(rb_intern("href")))); DONE(block); }; 141 143 blank_line => cat; 142 144 default … … 155 157 156 158 VALUE 157 superredcloth_transform(rb_formatter, p, pe )159 superredcloth_transform(rb_formatter, p, pe, refs) 158 160 VALUE rb_formatter; 159 161 char *p, *pe; 160 { 162 VALUE refs; 163 { 164 char *orig_p = p, *orig_pe = pe; 161 165 int cs, act, nest; 162 166 char *ts = NULL, *te = NULL, *reg = NULL, *eof = NULL; … … 172 176 VALUE extend = Qnil; 173 177 char listm[10] = ""; 178 VALUE refs_found = rb_hash_new(); 174 179 175 180 %% write init; … … 182 187 } 183 188 184 return html; 189 if ( NIL_P(refs) && rb_funcall(refs_found, rb_intern("empty?"), 0) == Qfalse ) { 190 return superredcloth_transform(rb_formatter, orig_p, orig_pe, refs_found); 191 } else { 192 return html; 193 } 185 194 } 186 195 … … 191 200 rb_str_cat2(str, "\n"); 192 201 StringValue(str); 193 return superredcloth_transform(formatter, RSTRING(str)->ptr, RSTRING(str)->ptr + RSTRING(str)->len + 1 );202 return superredcloth_transform(formatter, RSTRING(str)->ptr, RSTRING(str)->ptr + RSTRING(str)->len + 1, Qnil); 194 203 } 195 204