diff options
author | Kornelius Kalnbach <murphy@rubychan.de> | 2016-02-13 16:01:53 +0100 |
---|---|---|
committer | Kornelius Kalnbach <murphy@rubychan.de> | 2016-02-13 16:01:53 +0100 |
commit | 5fdb49307543a218e4bc47e181003c77f181eccf (patch) | |
tree | b29a9d9d99877980c8d29c33a11f838830859104 /test/samples/html.expected | |
parent | d79c6ba2008bff7b65029bc50717ca679c43fb5f (diff) | |
parent | 0a1f500d524ff0fb5eeafef051ccbb641954a87a (diff) | |
download | coderay-5fdb49307543a218e4bc47e181003c77f181eccf.tar.gz |
Merge branch 'master' into escape-utils
Diffstat (limited to 'test/samples/html.expected')
-rw-r--r-- | test/samples/html.expected | 919 |
1 files changed, 0 insertions, 919 deletions
diff --git a/test/samples/html.expected b/test/samples/html.expected deleted file mode 100644 index e98d589..0000000 --- a/test/samples/html.expected +++ /dev/null @@ -1,919 +0,0 @@ -<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" - "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> -<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="de"> -<head> - <meta http-equiv="content-type" content="text/html; charset=utf-8" /> - <title>CodeRay HTML Encoder Example</title> - <style type="text/css"> -.CodeRay { - background-color: #f8f8f8; - border: 1px solid silver; - font-family: 'Courier New', 'Terminal', monospace; - color: #000; -} -.CodeRay pre { margin: 0px } - -div.CodeRay { } - -span.CodeRay { white-space: pre; border: 0px; padding: 2px } - -table.CodeRay { border-collapse: collapse; width: 100%; padding: 2px } -table.CodeRay td { padding: 2px 4px; vertical-align: top } - -.CodeRay .line_numbers, .CodeRay .no { - background-color: #def; - color: gray; - text-align: right; -} -.CodeRay .line_numbers tt { font-weight: bold } -.CodeRay .line_numbers .highlighted { color: red } -.CodeRay .no { padding: 0px 4px } -.CodeRay .code { width: 100% } - -ol.CodeRay { font-size: 10pt } -ol.CodeRay li { white-space: pre } - -.CodeRay .code pre { overflow: auto } - -.CodeRay .debug { color:white ! important; background:blue ! important; } - -.CodeRay .af { color:#00C } -.CodeRay .an { color:#007 } -.CodeRay .at { color:#f08 } -.CodeRay .av { color:#700 } -.CodeRay .aw { color:#C00 } -.CodeRay .bi { color:#509; font-weight:bold } -.CodeRay .c { color:#888; } - -.CodeRay .ch { color:#04D } -.CodeRay .ch .k { color:#04D } -.CodeRay .ch .dl { color:#039 } - -.CodeRay .cl { color:#B06; font-weight:bold } -.CodeRay .cm { color:#A08; font-weight:bold } -.CodeRay .co { color:#036; font-weight:bold } -.CodeRay .cr { color:#0A0 } -.CodeRay .cv { color:#369 } -.CodeRay .de { color:#B0B; } -.CodeRay .df { color:#099; font-weight:bold } -.CodeRay .di { color:#088; font-weight:bold } -.CodeRay .dl { color:black } -.CodeRay .do { color:#970 } -.CodeRay .dt { color:#34b } -.CodeRay .ds { color:#D42; font-weight:bold } -.CodeRay .e { color:#666; font-weight:bold } -.CodeRay .en { color:#800; font-weight:bold } -.CodeRay .er { color:#F00; background-color:#FAA } -.CodeRay .ex { color:#C00; font-weight:bold } -.CodeRay .fl { color:#60E; font-weight:bold } -.CodeRay .fu { color:#06B; font-weight:bold } -.CodeRay .gv { color:#d70; font-weight:bold } -.CodeRay .hx { color:#058; font-weight:bold } -.CodeRay .i { color:#00D; font-weight:bold } -.CodeRay .ic { color:#B44; font-weight:bold } - -.CodeRay .il { background: #ddd; color: black } -.CodeRay .il .il { background: #ccc } -.CodeRay .il .il .il { background: #bbb } -.CodeRay .il .idl { background: #ddd; font-weight: bold; color: #666 } -.CodeRay .idl { background-color: #bbb; font-weight: bold; color: #666; } - -.CodeRay .im { color:#f00; } -.CodeRay .in { color:#B2B; font-weight:bold } -.CodeRay .iv { color:#33B } -.CodeRay .la { color:#970; font-weight:bold } -.CodeRay .lv { color:#963 } -.CodeRay .oc { color:#40E; font-weight:bold } -.CodeRay .of { color:#000; font-weight:bold } -.CodeRay .op { } -.CodeRay .pc { color:#038; font-weight:bold } -.CodeRay .pd { color:#369; font-weight:bold } -.CodeRay .pp { color:#579; } -.CodeRay .ps { color:#00C; font-weight:bold } -.CodeRay .pt { color:#074; font-weight:bold } -.CodeRay .r, .kw { color:#080; font-weight:bold } - -.CodeRay .ke { color: #808; } -.CodeRay .ke .dl { color: #606; } -.CodeRay .ke .ch { color: #80f; } -.CodeRay .vl { color: #088; } - -.CodeRay .rx { background-color:#fff0ff } -.CodeRay .rx .k { color:#808 } -.CodeRay .rx .dl { color:#404 } -.CodeRay .rx .mod { color:#C2C } -.CodeRay .rx .fu { color:#404; font-weight: bold } - -.CodeRay .s { background-color:#fff0f0; color: #D20; } -.CodeRay .s .s { background-color:#ffe0e0 } -.CodeRay .s .s .s { background-color:#ffd0d0 } -.CodeRay .s .k { } -.CodeRay .s .ch { color: #b0b; } -.CodeRay .s .dl { color: #710; } - -.CodeRay .sh { background-color:#f0fff0; color:#2B2 } -.CodeRay .sh .k { } -.CodeRay .sh .dl { color:#161 } - -.CodeRay .sy { color:#A60 } -.CodeRay .sy .k { color:#A60 } -.CodeRay .sy .dl { color:#630 } - -.CodeRay .ta { color:#070 } -.CodeRay .tf { color:#070; font-weight:bold } -.CodeRay .ts { color:#D70; font-weight:bold } -.CodeRay .ty { color:#339; font-weight:bold } -.CodeRay .v { color:#036 } -.CodeRay .xt { color:#444 } - -.CodeRay .ins { background: #afa; } -.CodeRay .del { background: #faa; } -.CodeRay .chg { color: #aaf; background: #007; } -.CodeRay .head { color: #f8f; background: #505 } - -.CodeRay .ins .ins { color: #080; font-weight:bold } -.CodeRay .del .del { color: #800; font-weight:bold } -.CodeRay .chg .chg { color: #66f; } -.CodeRay .head .head { color: #f4f; } - - </style> -</head> -<body style="background-color: white;"> - -<table class="CodeRay"><tr> - <td class="line_numbers" title="click to toggle" onclick="with (this.firstChild.style) { display = (display == '') ? 'none' : '' }"><pre>1<tt> -</tt>2<tt> -</tt>3<tt> -</tt>4<tt> -</tt>5<tt> -</tt>6<tt> -</tt>7<tt> -</tt>8<tt> -</tt>9<tt> -</tt><strong>10</strong><tt> -</tt>11<tt> -</tt>12<tt> -</tt>13<tt> -</tt>14<tt> -</tt>15<tt> -</tt>16<tt> -</tt>17<tt> -</tt>18<tt> -</tt>19<tt> -</tt><strong>20</strong><tt> -</tt>21<tt> -</tt>22<tt> -</tt>23<tt> -</tt>24<tt> -</tt>25<tt> -</tt>26<tt> -</tt>27<tt> -</tt>28<tt> -</tt>29<tt> -</tt><strong>30</strong><tt> -</tt>31<tt> -</tt>32<tt> -</tt>33<tt> -</tt>34<tt> -</tt>35<tt> -</tt>36<tt> -</tt>37<tt> -</tt>38<tt> -</tt>39<tt> -</tt><strong>40</strong><tt> -</tt>41<tt> -</tt>42<tt> -</tt>43<tt> -</tt>44<tt> -</tt>45<tt> -</tt>46<tt> -</tt>47<tt> -</tt>48<tt> -</tt>49<tt> -</tt><strong>50</strong><tt> -</tt>51<tt> -</tt>52<tt> -</tt>53<tt> -</tt>54<tt> -</tt>55<tt> -</tt>56<tt> -</tt>57<tt> -</tt>58<tt> -</tt>59<tt> -</tt><strong>60</strong><tt> -</tt>61<tt> -</tt>62<tt> -</tt>63<tt> -</tt>64<tt> -</tt>65<tt> -</tt>66<tt> -</tt>67<tt> -</tt>68<tt> -</tt>69<tt> -</tt><strong>70</strong><tt> -</tt>71<tt> -</tt>72<tt> -</tt>73<tt> -</tt>74<tt> -</tt>75<tt> -</tt>76<tt> -</tt>77<tt> -</tt>78<tt> -</tt>79<tt> -</tt><strong>80</strong><tt> -</tt>81<tt> -</tt>82<tt> -</tt>83<tt> -</tt>84<tt> -</tt>85<tt> -</tt>86<tt> -</tt>87<tt> -</tt>88<tt> -</tt>89<tt> -</tt><strong>90</strong><tt> -</tt>91<tt> -</tt>92<tt> -</tt>93<tt> -</tt>94<tt> -</tt>95<tt> -</tt>96<tt> -</tt>97<tt> -</tt>98<tt> -</tt>99<tt> -</tt><strong>100</strong><tt> -</tt>101<tt> -</tt>102<tt> -</tt>103<tt> -</tt>104<tt> -</tt>105<tt> -</tt>106<tt> -</tt>107<tt> -</tt>108<tt> -</tt>109<tt> -</tt><strong>110</strong><tt> -</tt>111<tt> -</tt>112<tt> -</tt>113<tt> -</tt>114<tt> -</tt>115<tt> -</tt>116<tt> -</tt>117<tt> -</tt>118<tt> -</tt>119<tt> -</tt><strong>120</strong><tt> -</tt>121<tt> -</tt>122<tt> -</tt>123<tt> -</tt>124<tt> -</tt>125<tt> -</tt>126<tt> -</tt>127<tt> -</tt>128<tt> -</tt>129<tt> -</tt><strong>130</strong><tt> -</tt>131<tt> -</tt>132<tt> -</tt>133<tt> -</tt>134<tt> -</tt>135<tt> -</tt>136<tt> -</tt>137<tt> -</tt>138<tt> -</tt>139<tt> -</tt><strong>140</strong><tt> -</tt>141<tt> -</tt>142<tt> -</tt>143<tt> -</tt>144<tt> -</tt>145<tt> -</tt>146<tt> -</tt>147<tt> -</tt>148<tt> -</tt>149<tt> -</tt><strong>150</strong><tt> -</tt>151<tt> -</tt>152<tt> -</tt>153<tt> -</tt>154<tt> -</tt>155<tt> -</tt>156<tt> -</tt>157<tt> -</tt>158<tt> -</tt>159<tt> -</tt><strong>160</strong><tt> -</tt>161<tt> -</tt>162<tt> -</tt>163<tt> -</tt>164<tt> -</tt>165<tt> -</tt>166<tt> -</tt>167<tt> -</tt>168<tt> -</tt>169<tt> -</tt><strong>170</strong><tt> -</tt>171<tt> -</tt>172<tt> -</tt>173<tt> -</tt>174<tt> -</tt>175<tt> -</tt>176<tt> -</tt>177<tt> -</tt>178<tt> -</tt>179<tt> -</tt><strong>180</strong><tt> -</tt>181<tt> -</tt>182<tt> -</tt>183<tt> -</tt>184<tt> -</tt>185<tt> -</tt>186<tt> -</tt>187<tt> -</tt>188<tt> -</tt>189<tt> -</tt><strong>190</strong><tt> -</tt>191<tt> -</tt>192<tt> -</tt>193<tt> -</tt>194<tt> -</tt>195<tt> -</tt>196<tt> -</tt>197<tt> -</tt>198<tt> -</tt>199<tt> -</tt><strong>200</strong><tt> -</tt>201<tt> -</tt>202<tt> -</tt>203<tt> -</tt>204<tt> -</tt>205<tt> -</tt>206<tt> -</tt>207<tt> -</tt>208<tt> -</tt>209<tt> -</tt><strong>210</strong><tt> -</tt>211<tt> -</tt>212<tt> -</tt>213<tt> -</tt>214<tt> -</tt>215<tt> -</tt>216<tt> -</tt>217<tt> -</tt>218<tt> -</tt>219<tt> -</tt><strong>220</strong><tt> -</tt>221<tt> -</tt>222<tt> -</tt>223<tt> -</tt>224<tt> -</tt>225<tt> -</tt>226<tt> -</tt>227<tt> -</tt>228<tt> -</tt>229<tt> -</tt><strong>230</strong><tt> -</tt>231<tt> -</tt>232<tt> -</tt>233<tt> -</tt>234<tt> -</tt>235<tt> -</tt>236<tt> -</tt>237<tt> -</tt>238<tt> -</tt>239<tt> -</tt><strong>240</strong><tt> -</tt>241<tt> -</tt>242<tt> -</tt>243<tt> -</tt>244<tt> -</tt>245<tt> -</tt>246<tt> -</tt>247<tt> -</tt>248<tt> -</tt>249<tt> -</tt><strong>250</strong><tt> -</tt>251<tt> -</tt>252<tt> -</tt>253<tt> -</tt>254<tt> -</tt>255<tt> -</tt>256<tt> -</tt>257<tt> -</tt>258<tt> -</tt>259<tt> -</tt><strong>260</strong><tt> -</tt>261<tt> -</tt>262<tt> -</tt>263<tt> -</tt>264<tt> -</tt>265<tt> -</tt>266<tt> -</tt>267<tt> -</tt>268<tt> -</tt>269<tt> -</tt><strong>270</strong><tt> -</tt>271<tt> -</tt>272<tt> -</tt>273<tt> -</tt>274<tt> -</tt>275<tt> -</tt>276<tt> -</tt>277<tt> -</tt>278<tt> -</tt>279<tt> -</tt><strong>280</strong><tt> -</tt>281<tt> -</tt>282<tt> -</tt>283<tt> -</tt>284<tt> -</tt>285<tt> -</tt>286<tt> -</tt>287<tt> -</tt>288<tt> -</tt>289<tt> -</tt><strong>290</strong><tt> -</tt>291<tt> -</tt>292<tt> -</tt>293<tt> -</tt>294<tt> -</tt>295<tt> -</tt>296<tt> -</tt>297<tt> -</tt>298<tt> -</tt>299<tt> -</tt><strong>300</strong><tt> -</tt>301<tt> -</tt>302<tt> -</tt>303<tt> -</tt>304<tt> -</tt>305<tt> -</tt>306<tt> -</tt>307<tt> -</tt>308<tt> -</tt>309<tt> -</tt><strong>310</strong><tt> -</tt>311<tt> -</tt>312<tt> -</tt>313<tt> -</tt>314<tt> -</tt>315<tt> -</tt>316<tt> -</tt>317<tt> -</tt>318<tt> -</tt>319<tt> -</tt><strong>320</strong><tt> -</tt>321<tt> -</tt>322<tt> -</tt>323<tt> -</tt>324<tt> -</tt>325<tt> -</tt>326<tt> -</tt>327<tt> -</tt>328<tt> -</tt>329<tt> -</tt><strong>330</strong><tt> -</tt>331<tt> -</tt>332<tt> -</tt>333<tt> -</tt>334<tt> -</tt>335<tt> -</tt>336<tt> -</tt>337<tt> -</tt>338<tt> -</tt>339<tt> -</tt><strong>340</strong><tt> -</tt>341<tt> -</tt>342<tt> -</tt>343<tt> -</tt>344<tt> -</tt>345<tt> -</tt>346<tt> -</tt>347<tt> -</tt>348<tt> -</tt>349<tt> -</tt><strong>350</strong><tt> -</tt>351<tt> -</tt>352<tt> -</tt>353<tt> -</tt>354<tt> -</tt>355<tt> -</tt>356<tt> -</tt>357<tt> -</tt>358<tt> -</tt>359<tt> -</tt><strong>360</strong><tt> -</tt>361<tt> -</tt>362<tt> -</tt>363<tt> -</tt>364<tt> -</tt>365<tt> -</tt>366<tt> -</tt>367<tt> -</tt>368<tt> -</tt>369<tt> -</tt><strong>370</strong><tt> -</tt>371<tt> -</tt>372<tt> -</tt>373<tt> -</tt>374<tt> -</tt>375<tt> -</tt>376<tt> -</tt>377<tt> -</tt>378<tt> -</tt>379<tt> -</tt><strong>380</strong><tt> -</tt>381<tt> -</tt>382<tt> -</tt>383<tt> -</tt>384<tt> -</tt>385<tt> -</tt></pre></td> - <td class="code"><pre ondblclick="with (this.style) { overflow = (overflow == 'auto' || overflow == '') ? 'visible' : 'auto' }">require <span class="s"><span class="dl">'</span><span class="k">scanner</span><span class="dl">'</span></span><tt> -</tt><tt> -</tt><span class="r">module</span> <span class="cl">CodeRay</span><tt> -</tt> <tt> -</tt> <span class="r">class</span> <span class="cl">RubyScanner</span> < <span class="co">Scanner</span><tt> -</tt> <tt> -</tt> <span class="co">RESERVED_WORDS</span> = [<tt> -</tt> <span class="s"><span class="dl">'</span><span class="k">and</span><span class="dl">'</span></span>, <span class="s"><span class="dl">'</span><span class="k">def</span><span class="dl">'</span></span>, <span class="s"><span class="dl">'</span><span class="k">end</span><span class="dl">'</span></span>, <span class="s"><span class="dl">'</span><span class="k">in</span><span class="dl">'</span></span>, <span class="s"><span class="dl">'</span><span class="k">or</span><span class="dl">'</span></span>, <span class="s"><span class="dl">'</span><span class="k">unless</span><span class="dl">'</span></span>, <span class="s"><span class="dl">'</span><span class="k">begin</span><span class="dl">'</span></span>,<tt> -</tt> <span class="s"><span class="dl">'</span><span class="k">defined?</span><span class="dl">'</span></span>, <span class="s"><span class="dl">'</span><span class="k">ensure</span><span class="dl">'</span></span>, <span class="s"><span class="dl">'</span><span class="k">module</span><span class="dl">'</span></span>, <span class="s"><span class="dl">'</span><span class="k">redo</span><span class="dl">'</span></span>, <span class="s"><span class="dl">'</span><span class="k">super</span><span class="dl">'</span></span>, <span class="s"><span class="dl">'</span><span class="k">until</span><span class="dl">'</span></span>,<tt> -</tt> <span class="s"><span class="dl">'</span><span class="k">BEGIN</span><span class="dl">'</span></span>, <span class="s"><span class="dl">'</span><span class="k">break</span><span class="dl">'</span></span>, <span class="s"><span class="dl">'</span><span class="k">do</span><span class="dl">'</span></span>, <span class="s"><span class="dl">'</span><span class="k">next</span><span class="dl">'</span></span>, <span class="s"><span class="dl">'</span><span class="k">rescue</span><span class="dl">'</span></span>, <span class="s"><span class="dl">'</span><span class="k">then</span><span class="dl">'</span></span>,<tt> -</tt> <span class="s"><span class="dl">'</span><span class="k">when</span><span class="dl">'</span></span>, <span class="s"><span class="dl">'</span><span class="k">END</span><span class="dl">'</span></span>, <span class="s"><span class="dl">'</span><span class="k">case</span><span class="dl">'</span></span>, <span class="s"><span class="dl">'</span><span class="k">else</span><span class="dl">'</span></span>, <span class="s"><span class="dl">'</span><span class="k">for</span><span class="dl">'</span></span>, <span class="s"><span class="dl">'</span><span class="k">retry</span><span class="dl">'</span></span>,<tt> -</tt> <span class="s"><span class="dl">'</span><span class="k">while</span><span class="dl">'</span></span>, <span class="s"><span class="dl">'</span><span class="k">alias</span><span class="dl">'</span></span>, <span class="s"><span class="dl">'</span><span class="k">class</span><span class="dl">'</span></span>, <span class="s"><span class="dl">'</span><span class="k">elsif</span><span class="dl">'</span></span>, <span class="s"><span class="dl">'</span><span class="k">if</span><span class="dl">'</span></span>, <span class="s"><span class="dl">'</span><span class="k">not</span><span class="dl">'</span></span>, <span class="s"><span class="dl">'</span><span class="k">return</span><span class="dl">'</span></span>,<tt> -</tt> <span class="s"><span class="dl">'</span><span class="k">undef</span><span class="dl">'</span></span>, <span class="s"><span class="dl">'</span><span class="k">yield</span><span class="dl">'</span></span>,<tt> -</tt> ]<tt> -</tt><tt> -</tt> <span class="co">DEF_KEYWORDS</span> = [<span class="s"><span class="dl">'</span><span class="k">def</span><span class="dl">'</span></span>]<tt> -</tt> <span class="co">MODULE_KEYWORDS</span> = [<span class="s"><span class="dl">'</span><span class="k">class</span><span class="dl">'</span></span>, <span class="s"><span class="dl">'</span><span class="k">module</span><span class="dl">'</span></span>]<tt> -</tt> <span class="co">DEF_NEW_STATE</span> = <span class="co">WordList</span>.new(<span class="sy">:initial</span>).<tt> -</tt> add(<span class="co">DEF_KEYWORDS</span>, <span class="sy">:def_expected</span>).<tt> -</tt> add(<span class="co">MODULE_KEYWORDS</span>, <span class="sy">:module_expected</span>)<tt> -</tt><tt> -</tt> <span class="co">WORDS_ALLOWING_REGEXP</span> = [<tt> -</tt> <span class="s"><span class="dl">'</span><span class="k">and</span><span class="dl">'</span></span>, <span class="s"><span class="dl">'</span><span class="k">or</span><span class="dl">'</span></span>, <span class="s"><span class="dl">'</span><span class="k">not</span><span class="dl">'</span></span>, <span class="s"><span class="dl">'</span><span class="k">while</span><span class="dl">'</span></span>, <span class="s"><span class="dl">'</span><span class="k">until</span><span class="dl">'</span></span>, <span class="s"><span class="dl">'</span><span class="k">unless</span><span class="dl">'</span></span>, <span class="s"><span class="dl">'</span><span class="k">if</span><span class="dl">'</span></span>, <span class="s"><span class="dl">'</span><span class="k">elsif</span><span class="dl">'</span></span>, <span class="s"><span class="dl">'</span><span class="k">when</span><span class="dl">'</span></span><tt> -</tt> ]<tt> -</tt> <span class="co">REGEXP_ALLOWED</span> = <span class="co">WordList</span>.new(<span class="pc">false</span>).<tt> -</tt> add(<span class="co">WORDS_ALLOWING_REGEXP</span>, <span class="sy">:set</span>)<tt> -</tt> <tt> -</tt> <span class="co">PREDEFINED_CONSTANTS</span> = [<tt> -</tt> <span class="s"><span class="dl">'</span><span class="k">nil</span><span class="dl">'</span></span>, <span class="s"><span class="dl">'</span><span class="k">true</span><span class="dl">'</span></span>, <span class="s"><span class="dl">'</span><span class="k">false</span><span class="dl">'</span></span>, <span class="s"><span class="dl">'</span><span class="k">self</span><span class="dl">'</span></span>,<tt> -</tt> <span class="s"><span class="dl">'</span><span class="k">DATA</span><span class="dl">'</span></span>, <span class="s"><span class="dl">'</span><span class="k">ARGV</span><span class="dl">'</span></span>, <span class="s"><span class="dl">'</span><span class="k">ARGF</span><span class="dl">'</span></span>, <span class="s"><span class="dl">'</span><span class="k">__FILE__</span><span class="dl">'</span></span>, <span class="s"><span class="dl">'</span><span class="k">__LINE__</span><span class="dl">'</span></span>,<tt> -</tt> ]<tt> -</tt><tt> -</tt> <span class="co">IDENT_KIND</span> = <span class="co">WordList</span>.new(<span class="sy">:ident</span>).<tt> -</tt> add(<span class="co">RESERVED_WORDS</span>, <span class="sy">:reserved</span>).<tt> -</tt> add(<span class="co">PREDEFINED_CONSTANTS</span>, <span class="sy">:pre_constant</span>)<tt> -</tt><tt> -</tt> <span class="co">METHOD_NAME</span> = <span class="rx"><span class="dl">/</span><span class="k"> </span><span class="il"><span class="idl">#{</span><span class="co">IDENT</span><span class="idl">}</span></span><span class="k"> [?!]? </span><span class="dl">/</span><span class="mod">xo</span></span><tt> -</tt> <span class="co">METHOD_NAME_EX</span> = <span class="rx"><span class="dl">/</span><span class="k"><tt> -</tt> </span><span class="il"><span class="idl">#{</span><span class="co">METHOD_NAME</span><span class="idl">}</span></span><span class="k"> # common methods: split, foo=, empty?, gsub!<tt> -</tt> | </span><span class="ch">\*</span><span class="ch">\*</span><span class="k">? # multiplication and power<tt> -</tt> | [-+~]@? # plus, minus<tt> -</tt> | [</span><span class="ch">\/</span><span class="k">%&|^`] # division, modulo or format strings, &and, |or, ^xor, `system`<tt> -</tt> | </span><span class="ch">\[</span><span class="ch">\]</span><span class="k">=? # array getter and setter<tt> -</tt> | <=?>? | >=? # comparison, rocket operator<tt> -</tt> | << | >> # append or shift left, shift right<tt> -</tt> | ===? # simple equality and case equality<tt> -</tt> </span><span class="dl">/</span><span class="mod">ox</span></span><tt> -</tt> <span class="co">GLOBAL_VARIABLE</span> = <span class="rx"><span class="dl">/</span><span class="k"> </span><span class="ch">\$</span><span class="k"> (?: </span><span class="il"><span class="idl">#{</span><span class="co">IDENT</span><span class="idl">}</span></span><span class="k"> | </span><span class="ch">\d</span><span class="k">+ | [~&+`'=</span><span class="ch">\/</span><span class="k">,;_.<>!@0$?*":F</span><span class="ch">\\</span><span class="k">] | -[a-zA-Z_0-9] ) </span><span class="dl">/</span><span class="mod">ox</span></span><tt> -</tt><tt> -</tt> <span class="co">DOUBLEQ</span> = <span class="rx"><span class="dl">/</span><span class="k"> " [^"</span><span class="ch">\#</span><span class="ch">\\</span><span class="k">]* (?: (?: </span><span class="ch">\#</span><span class="ch">\{</span><span class="k">.*?</span><span class="ch">\}</span><span class="k"> | </span><span class="ch">\#</span><span class="k">(?:$")? | </span><span class="ch">\\</span><span class="k">. ) [^"</span><span class="ch">\#</span><span class="ch">\\</span><span class="k">]* )* "? </span><span class="dl">/</span><span class="mod">ox</span></span><tt> -</tt> <span class="co">SINGLEQ</span> = <span class="rx"><span class="dl">/</span><span class="k"> ' [^'</span><span class="ch">\\</span><span class="k">]* (?: </span><span class="ch">\\</span><span class="k">. [^'</span><span class="ch">\\</span><span class="k">]* )* '? </span><span class="dl">/</span><span class="mod">ox</span></span><tt> -</tt> <span class="co">STRING</span> = <span class="rx"><span class="dl">/</span><span class="k"> </span><span class="il"><span class="idl">#{</span><span class="co">SINGLEQ</span><span class="idl">}</span></span><span class="k"> | </span><span class="il"><span class="idl">#{</span><span class="co">DOUBLEQ</span><span class="idl">}</span></span><span class="k"> </span><span class="dl">/</span><span class="mod">ox</span></span><tt> -</tt> <span class="co">SHELL</span> = <span class="rx"><span class="dl">/</span><span class="k"> ` [^`</span><span class="ch">\#</span><span class="ch">\\</span><span class="k">]* (?: (?: </span><span class="ch">\#</span><span class="ch">\{</span><span class="k">.*?</span><span class="ch">\}</span><span class="k"> | </span><span class="ch">\#</span><span class="k">(?:$`)? | </span><span class="ch">\\</span><span class="k">. ) [^`</span><span class="ch">\#</span><span class="ch">\\</span><span class="k">]* )* `? </span><span class="dl">/</span><span class="mod">ox</span></span><tt> -</tt> <span class="co">REGEXP</span> = <span class="rx"><span class="dl">/</span><span class="k"> </span><span class="ch">\/</span><span class="k"> [^</span><span class="ch">\/</span><span class="ch">\#</span><span class="ch">\\</span><span class="k">]* (?: (?: </span><span class="ch">\#</span><span class="ch">\{</span><span class="k">.*?</span><span class="ch">\}</span><span class="k"> | </span><span class="ch">\#</span><span class="k">(?:$</span><span class="ch">\/</span><span class="k">)? | </span><span class="ch">\\</span><span class="k">. ) [^</span><span class="ch">\/</span><span class="ch">\#</span><span class="ch">\\</span><span class="k">]* )* </span><span class="ch">\/</span><span class="k">? </span><span class="dl">/</span><span class="mod">ox</span></span><tt> -</tt> <tt> -</tt> <span class="co">DECIMAL</span> = <span class="rx"><span class="dl">/</span><span class="ch">\d</span><span class="k">+(?:_</span><span class="ch">\d</span><span class="k">+)*</span><span class="dl">/</span></span> <span class="c"># doesn't recognize 09 as octal error</span><tt> -</tt> <span class="co">OCTAL</span> = <span class="rx"><span class="dl">/</span><span class="k">0_?[0-7]+(?:_[0-7]+)*</span><span class="dl">/</span></span><tt> -</tt> <span class="co">HEXADECIMAL</span> = <span class="rx"><span class="dl">/</span><span class="k">0x[0-9A-Fa-f]+(?:_[0-9A-Fa-f]+)*</span><span class="dl">/</span></span><tt> -</tt> <span class="co">BINARY</span> = <span class="rx"><span class="dl">/</span><span class="k">0b[01]+(?:_[01]+)*</span><span class="dl">/</span></span><tt> -</tt><tt> -</tt> <span class="co">EXPONENT</span> = <span class="rx"><span class="dl">/</span><span class="k"> [eE] [+-]? </span><span class="il"><span class="idl">#{</span><span class="co">DECIMAL</span><span class="idl">}</span></span><span class="k"> </span><span class="dl">/</span><span class="mod">ox</span></span><tt> -</tt> <span class="co">FLOAT</span> = <span class="rx"><span class="dl">/</span><span class="k"> </span><span class="il"><span class="idl">#{</span><span class="co">DECIMAL</span><span class="idl">}</span></span><span class="k"> (?: </span><span class="il"><span class="idl">#{</span><span class="co">EXPONENT</span><span class="idl">}</span></span><span class="k"> | </span><span class="ch">\.</span><span class="k"> </span><span class="il"><span class="idl">#{</span><span class="co">DECIMAL</span><span class="idl">}</span></span><span class="k"> </span><span class="il"><span class="idl">#{</span><span class="co">EXPONENT</span><span class="idl">}</span></span><span class="k">? ) </span><span class="dl">/</span></span><tt> -</tt> <span class="co">INTEGER</span> = <span class="rx"><span class="dl">/</span><span class="il"><span class="idl">#{</span><span class="co">OCTAL</span><span class="idl">}</span></span><span class="k">|</span><span class="il"><span class="idl">#{</span><span class="co">HEXADECIMAL</span><span class="idl">}</span></span><span class="k">|</span><span class="il"><span class="idl">#{</span><span class="co">BINARY</span><span class="idl">}</span></span><span class="k">|</span><span class="il"><span class="idl">#{</span><span class="co">DECIMAL</span><span class="idl">}</span></span><span class="dl">/</span></span><tt> -</tt> <tt> -</tt> <span class="r">def</span> <span class="fu">reset</span><tt> -</tt> <span class="r">super</span><tt> -</tt> <span class="iv">@regexp_allowed</span> = <span class="pc">false</span><tt> -</tt> <span class="r">end</span><tt> -</tt> <tt> -</tt> <span class="r">def</span> <span class="fu">next_token</span><tt> -</tt> <span class="r">return</span> <span class="r">if</span> <span class="iv">@scanner</span>.eos?<tt> -</tt><tt> -</tt> kind = <span class="sy">:error</span><tt> -</tt> <span class="r">if</span> <span class="iv">@scanner</span>.scan(<span class="rx"><span class="dl">/</span><span class="ch">\s</span><span class="k">+</span><span class="dl">/</span></span>) <span class="c"># in every state</span><tt> -</tt> kind = <span class="sy">:space</span><tt> -</tt> <span class="iv">@regexp_allowed</span> = <span class="sy">:set</span> <span class="r">if</span> <span class="iv">@regexp_allowed</span> <span class="r">or</span> <span class="iv">@scanner</span>.matched.index(<span class="i">?\n</span>) <span class="c"># delayed flag setting</span><tt> -</tt><tt> -</tt> <span class="r">elsif</span> <span class="iv">@state</span> == <span class="sy">:def_expected</span><tt> -</tt> <span class="r">if</span> <span class="iv">@scanner</span>.scan(<span class="rx"><span class="dl">/</span><span class="k"> (?: (?:</span><span class="il"><span class="idl">#{</span><span class="co">IDENT</span><span class="idl">}</span></span><span class="k">(?:</span><span class="ch">\.</span><span class="k">|::))* | (?:@@?|$)? </span><span class="il"><span class="idl">#{</span><span class="co">IDENT</span><span class="idl">}</span></span><span class="k">(?:</span><span class="ch">\.</span><span class="k">|::) ) </span><span class="il"><span class="idl">#{</span><span class="co">METHOD_NAME_EX</span><span class="idl">}</span></span><span class="k"> </span><span class="dl">/</span><span class="mod">ox</span></span>)<tt> -</tt> kind = <span class="sy">:method</span><tt> -</tt> <span class="iv">@state</span> = <span class="sy">:initial</span><tt> -</tt> <span class="r">else</span><tt> -</tt> <span class="iv">@scanner</span>.scan(<span class="rx"><span class="dl">/</span><span class="k">.</span><span class="dl">/</span></span>)<tt> -</tt> kind = <span class="sy">:error</span><tt> -</tt> <span class="r">end</span><tt> -</tt> <span class="iv">@state</span> = <span class="sy">:initial</span><tt> -</tt> <tt> -</tt> <span class="r">elsif</span> <span class="iv">@state</span> == <span class="sy">:module_expected</span><tt> -</tt> <span class="r">if</span> <span class="iv">@scanner</span>.scan(<span class="rx"><span class="dl">/</span><span class="k"><<</span><span class="dl">/</span></span>)<tt> -</tt> kind = <span class="sy">:operator</span><tt> -</tt> <span class="r">else</span><tt> -</tt> <span class="r">if</span> <span class="iv">@scanner</span>.scan(<span class="rx"><span class="dl">/</span><span class="k"> (?: </span><span class="il"><span class="idl">#{</span><span class="co">IDENT</span><span class="idl">}</span></span><span class="k"> (?:</span><span class="ch">\.</span><span class="k">|::))* </span><span class="il"><span class="idl">#{</span><span class="co">IDENT</span><span class="idl">}</span></span><span class="k"> </span><span class="dl">/</span><span class="mod">ox</span></span>)<tt> -</tt> kind = <span class="sy">:method</span><tt> -</tt> <span class="r">else</span><tt> -</tt> <span class="iv">@scanner</span>.scan(<span class="rx"><span class="dl">/</span><span class="k">.</span><span class="dl">/</span></span>)<tt> -</tt> kind = <span class="sy">:error</span><tt> -</tt> <span class="r">end</span><tt> -</tt> <span class="iv">@state</span> = <span class="sy">:initial</span><tt> -</tt> <span class="r">end</span><tt> -</tt> <tt> -</tt> <span class="r">elsif</span> <span class="c"># state == :initial</span><tt> -</tt> <span class="c"># IDENTIFIERS, KEYWORDS</span><tt> -</tt> <span class="r">if</span> <span class="iv">@scanner</span>.scan(<span class="co">GLOBAL_VARIABLE</span>)<tt> -</tt> kind = <span class="sy">:global_variable</span><tt> -</tt> <span class="r">elsif</span> <span class="iv">@scanner</span>.scan(<span class="rx"><span class="dl">/</span><span class="k"> @@ </span><span class="il"><span class="idl">#{</span><span class="co">IDENT</span><span class="idl">}</span></span><span class="k"> </span><span class="dl">/</span><span class="mod">ox</span></span>)<tt> -</tt> kind = <span class="sy">:class_variable</span><tt> -</tt> <span class="r">elsif</span> <span class="iv">@scanner</span>.scan(<span class="rx"><span class="dl">/</span><span class="k"> @ </span><span class="il"><span class="idl">#{</span><span class="co">IDENT</span><span class="idl">}</span></span><span class="k"> </span><span class="dl">/</span><span class="mod">ox</span></span>)<tt> -</tt> kind = <span class="sy">:instance_variable</span><tt> -</tt> <span class="r">elsif</span> <span class="iv">@scanner</span>.scan(<span class="rx"><span class="dl">/</span><span class="k"> __END__</span><span class="ch">\n</span><span class="k"> ( (?!</span><span class="ch">\#</span><span class="k">CODE</span><span class="ch">\#</span><span class="k">) .* )? | </span><span class="ch">\#</span><span class="k">[^</span><span class="ch">\n</span><span class="k">]* | =begin(?=</span><span class="ch">\s</span><span class="k">).*? </span><span class="ch">\n</span><span class="k">=end(?=</span><span class="ch">\s</span><span class="k">|</span><span class="ch">\z</span><span class="k">)(?:[^</span><span class="ch">\n</span><span class="k">]*)? </span><span class="dl">/</span><span class="mod">x</span></span>)<tt> -</tt> kind = <span class="sy">:comment</span><tt> -</tt> <span class="r">elsif</span> <span class="iv">@scanner</span>.scan(<span class="co">METHOD_NAME</span>)<tt> -</tt> <span class="r">if</span> <span class="iv">@last_token_dot</span><tt> -</tt> kind = <span class="sy">:ident</span><tt> -</tt> <span class="r">else</span><tt> -</tt> matched = <span class="iv">@scanner</span>.matched<tt> -</tt> kind = <span class="co">IDENT_KIND</span>[matched]<tt> -</tt> <span class="r">if</span> kind == <span class="sy">:ident</span> <span class="r">and</span> matched =~ <span class="rx"><span class="dl">/</span><span class="k">^[A-Z]</span><span class="dl">/</span></span><tt> -</tt> kind = <span class="sy">:constant</span><tt> -</tt> <span class="r">elsif</span> kind == <span class="sy">:reserved</span><tt> -</tt> <span class="iv">@state</span> = <span class="co">DEF_NEW_STATE</span>[matched]<tt> -</tt> <span class="iv">@regexp_allowed</span> = <span class="co">REGEXP_ALLOWED</span>[matched]<tt> -</tt> <span class="r">end</span><tt> -</tt> <span class="r">end</span><tt> -</tt> <tt> -</tt> <span class="r">elsif</span> <span class="iv">@scanner</span>.scan(<span class="co">STRING</span>)<tt> -</tt> kind = <span class="sy">:string</span><tt> -</tt> <span class="r">elsif</span> <span class="iv">@scanner</span>.scan(<span class="co">SHELL</span>)<tt> -</tt> kind = <span class="sy">:shell</span><tt> -</tt> <span class="c">## HEREDOCS</span><tt> -</tt> <span class="r">elsif</span> <span class="iv">@scanner</span>.scan(<span class="rx"><span class="dl">/</span><span class="ch">\/</span><span class="dl">/</span></span>) <span class="r">and</span> <span class="iv">@regexp_allowed</span><tt> -</tt> <span class="iv">@scanner</span>.unscan<tt> -</tt> <span class="iv">@scanner</span>.scan(<span class="co">REGEXP</span>)<tt> -</tt> kind = <span class="sy">:regexp</span><tt> -</tt> <span class="c">## %strings</span><tt> -</tt> <span class="r">elsif</span> <span class="iv">@scanner</span>.scan(<span class="rx"><span class="dl">/</span><span class="k">:(?:</span><span class="il"><span class="idl">#{</span><span class="co">GLOBAL_VARIABLE</span><span class="idl">}</span></span><span class="k">|</span><span class="il"><span class="idl">#{</span><span class="co">METHOD_NAME_EX</span><span class="idl">}</span></span><span class="k">|</span><span class="il"><span class="idl">#{</span><span class="co">STRING</span><span class="idl">}</span></span><span class="k">)</span><span class="dl">/</span><span class="mod">ox</span></span>)<tt> -</tt> kind = <span class="sy">:global_variable</span><tt> -</tt> <span class="r">elsif</span> <span class="iv">@scanner</span>.scan(<span class="rx"><span class="dl">/</span><span class="k"><tt> -</tt> </span><span class="ch">\?</span><span class="k"> (?:<tt> -</tt> [^</span><span class="ch">\s</span><span class="ch">\\</span><span class="k">]<tt> -</tt> | <tt> -</tt> </span><span class="ch">\\</span><span class="k"> (?:M-</span><span class="ch">\\</span><span class="k">C-|C-</span><span class="ch">\\</span><span class="k">M-|M-</span><span class="ch">\\</span><span class="k">c|c</span><span class="ch">\\</span><span class="k">M-|c|C-|M-))? (?: </span><span class="ch">\\</span><span class="k"> (?: . | [0-7]{3} | x[0-9A-Fa-f][0-9A-Fa-f] )<tt> -</tt> )<tt> -</tt> </span><span class="dl">/</span><span class="mod">ox</span></span>)<tt> -</tt> kind = <span class="sy">:integer</span><tt> -</tt> <tt> -</tt> <span class="r">elsif</span> <span class="iv">@scanner</span>.scan(<span class="rx"><span class="dl">/</span><span class="k"> [-+*</span><span class="ch">\/</span><span class="k">%=<>;,|&!()</span><span class="ch">\[</span><span class="ch">\]</span><span class="k">{}~?] | </span><span class="ch">\.</span><span class="ch">\.</span><span class="k">?</span><span class="ch">\.</span><span class="k">? | ::? </span><span class="dl">/</span><span class="mod">x</span></span>)<tt> -</tt> kind = <span class="sy">:operator</span><tt> -</tt> <span class="iv">@regexp_allowed</span> = <span class="sy">:set</span> <span class="r">if</span> <span class="iv">@scanner</span>.matched[<span class="i">-1</span>,<span class="i">1</span>] =~ <span class="rx"><span class="dl">/</span><span class="k">[~=!<>|&^,</span><span class="ch">\(</span><span class="ch">\[</span><span class="k">+</span><span class="ch">\-</span><span class="ch">\/</span><span class="ch">\*</span><span class="k">%]</span><span class="ch">\z</span><span class="dl">/</span></span><tt> -</tt> <span class="r">elsif</span> <span class="iv">@scanner</span>.scan(<span class="co">FLOAT</span>)<tt> -</tt> kind = <span class="sy">:float</span><tt> -</tt> <span class="r">elsif</span> <span class="iv">@scanner</span>.scan(<span class="co">INTEGER</span>)<tt> -</tt> kind = <span class="sy">:integer</span><tt> -</tt> <span class="r">elsif</span> <span class="iv">@scanner</span>.scan(<span class="rx"><span class="dl">/</span><span class="k">:(?:</span><span class="il"><span class="idl">#{</span><span class="co">GLOBAL_VARIABLE</span><span class="idl">}</span></span><span class="k">|</span><span class="il"><span class="idl">#{</span><span class="co">METHOD_NAME_EX</span><span class="idl">}</span></span><span class="k">|</span><span class="il"><span class="idl">#{</span><span class="co">STRING</span><span class="idl">}</span></span><span class="k">)</span><span class="dl">/</span><span class="mod">ox</span></span>)<tt> -</tt> kind = <span class="sy">:global_variable</span><tt> -</tt> <span class="r">else</span><tt> -</tt> <span class="iv">@scanner</span>.scan(<span class="rx"><span class="dl">/</span><span class="k">.</span><span class="dl">/</span><span class="mod">m</span></span>)<tt> -</tt> <span class="r">end</span><tt> -</tt> <span class="r">end</span><tt> -</tt> <tt> -</tt> token = <span class="co">Token</span>.new <span class="iv">@scanner</span>.matched, kind<tt> -</tt><tt> -</tt> <span class="r">if</span> kind == <span class="sy">:regexp</span><tt> -</tt> token.text << <span class="iv">@scanner</span>.scan(<span class="rx"><span class="dl">/</span><span class="k">[eimnosux]*</span><span class="dl">/</span></span>)<tt> -</tt> <span class="r">end</span><tt> -</tt> <tt> -</tt> <span class="iv">@regexp_allowed</span> = (<span class="iv">@regexp_allowed</span> == <span class="sy">:set</span>) <span class="c"># delayed flag setting</span><tt> -</tt><tt> -</tt> token<tt> -</tt> <span class="r">end</span><tt> -</tt> <span class="r">end</span><tt> -</tt> <tt> -</tt> <span class="co">ScannerList</span>.register <span class="co">RubyScanner</span>, <span class="s"><span class="dl">'</span><span class="k">ruby</span><span class="dl">'</span></span><tt> -</tt><tt> -</tt><span class="r">end</span><tt> -</tt><tt> -</tt><span class="r">module</span> <span class="cl">CodeRay</span><tt> -</tt> require <span class="s"><span class="dl">'</span><span class="k">scanner</span><span class="dl">'</span></span><tt> -</tt><tt> -</tt> <span class="r">class</span> <span class="cl">Highlighter</span><tt> -</tt><tt> -</tt> <span class="r">def</span> <span class="fu">initialize</span> lang<tt> -</tt> <span class="iv">@scanner</span> = <span class="co">Scanner</span>[lang].new<tt> -</tt> <span class="r">end</span><tt> -</tt><tt> -</tt> <span class="r">def</span> <span class="fu">highlight</span> code<tt> -</tt> <span class="iv">@scanner</span>.feed code<tt> -</tt> <span class="iv">@scanner</span>.all_tokens.map { |t| t.inspect }.join <span class="s"><span class="dl">"</span><span class="ch">\n</span><span class="dl">"</span></span><tt> -</tt> <span class="r">end</span><tt> -</tt><tt> -</tt> <span class="r">end</span><tt> -</tt><tt> -</tt> <span class="r">class</span> <span class="cl">HTMLHighlighter</span> < <span class="co">Highlighter</span><tt> -</tt> <tt> -</tt> <span class="co">ClassOfKind</span> = {<tt> -</tt> <span class="sy">:attribute_name</span> => <span class="s"><span class="dl">'</span><span class="k">an</span><span class="dl">'</span></span>,<tt> -</tt> <span class="sy">:attribute_name_fat</span> => <span class="s"><span class="dl">'</span><span class="k">af</span><span class="dl">'</span></span>,<tt> -</tt> <span class="sy">:attribute_value</span> => <span class="s"><span class="dl">'</span><span class="k">av</span><span class="dl">'</span></span>,<tt> -</tt> <span class="sy">:attribute_value_fat</span> => <span class="s"><span class="dl">'</span><span class="k">aw</span><span class="dl">'</span></span>,<tt> -</tt> <span class="sy">:bin</span> => <span class="s"><span class="dl">'</span><span class="k">bi</span><span class="dl">'</span></span>,<tt> -</tt> <span class="sy">:char</span> => <span class="s"><span class="dl">'</span><span class="k">ch</span><span class="dl">'</span></span>,<tt> -</tt> <span class="sy">:class</span> => <span class="s"><span class="dl">'</span><span class="k">cl</span><span class="dl">'</span></span>,<tt> -</tt> <span class="sy">:class_variable</span> => <span class="s"><span class="dl">'</span><span class="k">cv</span><span class="dl">'</span></span>,<tt> -</tt> <span class="sy">:color</span> => <span class="s"><span class="dl">'</span><span class="k">cr</span><span class="dl">'</span></span>,<tt> -</tt> <span class="sy">:comment</span> => <span class="s"><span class="dl">'</span><span class="k">c</span><span class="dl">'</span></span>,<tt> -</tt> <span class="sy">:constant</span> => <span class="s"><span class="dl">'</span><span class="k">co</span><span class="dl">'</span></span>,<tt> -</tt> <span class="sy">:definition</span> => <span class="s"><span class="dl">'</span><span class="k">df</span><span class="dl">'</span></span>,<tt> -</tt> <span class="sy">:directive</span> => <span class="s"><span class="dl">'</span><span class="k">di</span><span class="dl">'</span></span>,<tt> -</tt> <span class="sy">:doc</span> => <span class="s"><span class="dl">'</span><span class="k">do</span><span class="dl">'</span></span>,<tt> -</tt> <span class="sy">:doc_string</span> => <span class="s"><span class="dl">'</span><span class="k">ds</span><span class="dl">'</span></span>,<tt> -</tt> <span class="sy">:exception</span> => <span class="s"><span class="dl">'</span><span class="k">ex</span><span class="dl">'</span></span>,<tt> -</tt> <span class="sy">:error</span> => <span class="s"><span class="dl">'</span><span class="k">er</span><span class="dl">'</span></span>,<tt> -</tt> <span class="sy">:float</span> => <span class="s"><span class="dl">'</span><span class="k">fl</span><span class="dl">'</span></span>,<tt> -</tt> <span class="sy">:function</span> => <span class="s"><span class="dl">'</span><span class="k">fu</span><span class="dl">'</span></span>,<tt> -</tt> <span class="sy">:global_variable</span> => <span class="s"><span class="dl">'</span><span class="k">gv</span><span class="dl">'</span></span>,<tt> -</tt> <span class="sy">:hex</span> => <span class="s"><span class="dl">'</span><span class="k">hx</span><span class="dl">'</span></span>,<tt> -</tt> <span class="sy">:include</span> => <span class="s"><span class="dl">'</span><span class="k">ic</span><span class="dl">'</span></span>,<tt> -</tt> <span class="sy">:instance_variable</span> => <span class="s"><span class="dl">'</span><span class="k">iv</span><span class="dl">'</span></span>,<tt> -</tt> <span class="sy">:integer</span> => <span class="s"><span class="dl">'</span><span class="k">i</span><span class="dl">'</span></span>,<tt> -</tt> <span class="sy">:interpreted</span> => <span class="s"><span class="dl">'</span><span class="k">in</span><span class="dl">'</span></span>,<tt> -</tt> <span class="sy">:label</span> => <span class="s"><span class="dl">'</span><span class="k">la</span><span class="dl">'</span></span>,<tt> -</tt> <span class="sy">:local_variable</span> => <span class="s"><span class="dl">'</span><span class="k">lv</span><span class="dl">'</span></span>,<tt> -</tt> <span class="sy">:oct</span> => <span class="s"><span class="dl">'</span><span class="k">oc</span><span class="dl">'</span></span>,<tt> -</tt> <span class="sy">:operator_name</span> => <span class="s"><span class="dl">'</span><span class="k">on</span><span class="dl">'</span></span>,<tt> -</tt> <span class="sy">:pre_constant</span> => <span class="s"><span class="dl">'</span><span class="k">pc</span><span class="dl">'</span></span>,<tt> -</tt> <span class="sy">:pre_type</span> => <span class="s"><span class="dl">'</span><span class="k">pt</span><span class="dl">'</span></span>,<tt> -</tt> <span class="sy">:predefined</span> => <span class="s"><span class="dl">'</span><span class="k">pd</span><span class="dl">'</span></span>,<tt> -</tt> <span class="sy">:preprocessor</span> => <span class="s"><span class="dl">'</span><span class="k">pp</span><span class="dl">'</span></span>,<tt> -</tt> <span class="sy">:regexp</span> => <span class="s"><span class="dl">'</span><span class="k">rx</span><span class="dl">'</span></span>,<tt> -</tt> <span class="sy">:reserved</span> => <span class="s"><span class="dl">'</span><span class="k">r</span><span class="dl">'</span></span>,<tt> -</tt> <span class="sy">:shell</span> => <span class="s"><span class="dl">'</span><span class="k">sh</span><span class="dl">'</span></span>,<tt> -</tt> <span class="sy">:string</span> => <span class="s"><span class="dl">'</span><span class="k">s</span><span class="dl">'</span></span>,<tt> -</tt> <span class="sy">:symbol</span> => <span class="s"><span class="dl">'</span><span class="k">sy</span><span class="dl">'</span></span>,<tt> -</tt> <span class="sy">:tag</span> => <span class="s"><span class="dl">'</span><span class="k">ta</span><span class="dl">'</span></span>,<tt> -</tt> <span class="sy">:tag_fat</span> => <span class="s"><span class="dl">'</span><span class="k">tf</span><span class="dl">'</span></span>,<tt> -</tt> <span class="sy">:tag_special</span> => <span class="s"><span class="dl">'</span><span class="k">ts</span><span class="dl">'</span></span>,<tt> -</tt> <span class="sy">:type</span> => <span class="s"><span class="dl">'</span><span class="k">ty</span><span class="dl">'</span></span>,<tt> -</tt> <span class="sy">:variable</span> => <span class="s"><span class="dl">'</span><span class="k">v</span><span class="dl">'</span></span>,<tt> -</tt> <span class="sy">:xml_text</span> => <span class="s"><span class="dl">'</span><span class="k">xt</span><span class="dl">'</span></span>,<tt> -</tt><tt> -</tt> <span class="sy">:ident</span> => <span class="sy">:NO_HIGHLIGHT</span>,<tt> -</tt> <span class="sy">:operator</span> => <span class="sy">:NO_HIGHLIGHT</span>,<tt> -</tt> <span class="sy">:space</span> => <span class="sy">:NO_HIGHLIGHT</span>,<tt> -</tt> }<tt> -</tt> <span class="co">ClassOfKind</span>[<span class="sy">:procedure</span>] = <span class="co">ClassOfKind</span>[<span class="sy">:method</span>] = <span class="co">ClassOfKind</span>[<span class="sy">:function</span>]<tt> -</tt> <span class="co">ClassOfKind</span>.default = <span class="co">ClassOfKind</span>[<span class="sy">:error</span>] <span class="r">or</span> raise <span class="s"><span class="dl">'</span><span class="k">no class found for :error!</span><span class="dl">'</span></span><tt> -</tt> <tt> -</tt> <span class="r">def</span> <span class="fu">initialize</span> lang, options = {}<tt> -</tt> <span class="r">super</span> lang<tt> -</tt> <tt> -</tt> <span class="iv">@HTML_TAB</span> = <span class="s"><span class="dl">'</span><span class="k"> </span><span class="dl">'</span></span> * options.fetch(<span class="sy">:tabs2space</span>, <span class="i">8</span>)<tt> -</tt> <span class="r">case</span> level = options.fetch(<span class="sy">:level</span>, <span class="s"><span class="dl">'</span><span class="k">xhtml</span><span class="dl">'</span></span>)<tt> -</tt> <span class="r">when</span> <span class="s"><span class="dl">'</span><span class="k">html</span><span class="dl">'</span></span><tt> -</tt> <span class="iv">@HTML_BR</span> = <span class="s"><span class="dl">"</span><span class="k"><BR></span><span class="ch">\n</span><span class="dl">"</span></span><tt> -</tt> <span class="r">when</span> <span class="s"><span class="dl">'</span><span class="k">xhtml</span><span class="dl">'</span></span><tt> -</tt> <span class="iv">@HTML_BR</span> = <span class="s"><span class="dl">"</span><span class="k"><br /></span><span class="ch">\n</span><span class="dl">"</span></span><tt> -</tt> <span class="r">else</span><tt> -</tt> raise <span class="s"><span class="dl">"</span><span class="k">Unknown HTML level: </span><span class="il"><span class="idl">#{</span>level<span class="idl">}</span></span><span class="dl">"</span></span><tt> -</tt> <span class="r">end</span><tt> -</tt> <span class="r">end</span><tt> -</tt><tt> -</tt> <span class="r">def</span> <span class="fu">highlight</span> code<tt> -</tt> <span class="iv">@scanner</span>.feed code<tt> -</tt> <tt> -</tt> out = <span class="s"><span class="dl">'</span><span class="dl">'</span></span><tt> -</tt> <span class="r">while</span> t = <span class="iv">@scanner</span>.next_token<tt> -</tt> warn t.inspect <span class="r">if</span> t.text.nil?<tt> -</tt> out << to_html(t)<tt> -</tt> <span class="r">end</span><tt> -</tt> <span class="co">TEMPLATE</span> =~ <span class="rx"><span class="dl">/</span><span class="k"><%CONTENT%></span><span class="dl">/</span></span><tt> -</tt> <span class="gv">$`</span> + out + <span class="gv">$'</span><tt> -</tt> <span class="r">end</span><tt> -</tt> <tt> -</tt> private<tt> -</tt> <span class="r">def</span> <span class="fu">to_html</span> token<tt> -</tt> css_class = <span class="co">ClassOfKind</span>[token.kind]<tt> -</tt> <span class="r">if</span> <span class="r">defined?</span> ::<span class="co">DEBUG</span> <span class="r">and</span> <span class="r">not</span> <span class="co">ClassOfKind</span>.has_key? token.kind<tt> -</tt> warn <span class="s"><span class="dl">"</span><span class="k">no token class found for :</span><span class="il"><span class="idl">#{</span>token.kind<span class="idl">}</span></span><span class="dl">"</span></span><tt> -</tt> <span class="r">end</span><tt> -</tt> <tt> -</tt> text = text_to_html token.text<tt> -</tt> <span class="r">if</span> css_class == <span class="sy">:NO_HIGHLIGHT</span><tt> -</tt> text<tt> -</tt> <span class="r">else</span><tt> -</tt> <span class="s"><span class="dl">"</span><span class="k"><span class=</span><span class="ch">\"</span><span class="il"><span class="idl">#{</span>css_class<span class="idl">}</span></span><span class="ch">\"</span><span class="k">></span><span class="il"><span class="idl">#{</span>text<span class="idl">}</span></span><span class="k"></span></span><span class="dl">"</span></span><tt> -</tt> <span class="r">end</span><tt> -</tt> <span class="r">end</span><tt> -</tt> <tt> -</tt> <span class="r">def</span> <span class="fu">text_to_html</span> text<tt> -</tt> <span class="r">return</span> <span class="s"><span class="dl">'</span><span class="dl">'</span></span> <span class="r">if</span> text.empty?<tt> -</tt> text = text.dup <span class="c"># important</span><tt> -</tt> <span class="r">if</span> text.index(<span class="rx"><span class="dl">/</span><span class="k">["><&]</span><span class="dl">/</span></span>)<tt> -</tt> text.gsub!(<span class="s"><span class="dl">'</span><span class="k">&</span><span class="dl">'</span></span>, <span class="s"><span class="dl">'</span><span class="k">&amp;</span><span class="dl">'</span></span>)<tt> -</tt> text.gsub!(<span class="s"><span class="dl">'</span><span class="k">"</span><span class="dl">'</span></span>, <span class="s"><span class="dl">'</span><span class="k">&quot;</span><span class="dl">'</span></span>)<tt> -</tt> text.gsub!(<span class="s"><span class="dl">'</span><span class="k">></span><span class="dl">'</span></span>, <span class="s"><span class="dl">'</span><span class="k">&gt;</span><span class="dl">'</span></span>)<tt> -</tt> text.gsub!(<span class="s"><span class="dl">'</span><span class="k"><</span><span class="dl">'</span></span>, <span class="s"><span class="dl">'</span><span class="k">&lt;</span><span class="dl">'</span></span>)<tt> -</tt> <span class="r">end</span><tt> -</tt> <span class="r">if</span> text.index(<span class="rx"><span class="dl">/</span><span class="ch">\s</span><span class="dl">/</span></span>)<tt> -</tt> text.gsub!(<span class="s"><span class="dl">"</span><span class="ch">\n</span><span class="dl">"</span></span>, <span class="iv">@HTML_BR</span>)<tt> -</tt> text.gsub!(<span class="s"><span class="dl">"</span><span class="ch">\t</span><span class="dl">"</span></span>, <span class="iv">@HTML_TAB</span>)<tt> -</tt> text.gsub!(<span class="rx"><span class="dl">/</span><span class="k">^ </span><span class="dl">/</span></span>, <span class="s"><span class="dl">'</span><span class="k">&nbsp;</span><span class="dl">'</span></span>)<tt> -</tt> text.gsub!(<span class="s"><span class="dl">'</span><span class="k"> </span><span class="dl">'</span></span>, <span class="s"><span class="dl">'</span><span class="k"> &nbsp;</span><span class="dl">'</span></span>)<tt> -</tt> <span class="r">end</span><tt> -</tt> text<tt> -</tt> <span class="r">end</span><tt> -</tt> <tt> -</tt> <span class="co">TEMPLATE</span> = <span class="s"><span class="dl"><<-'TEMPLATE'</span></span><span class="s"><span class="k"><tt> -</tt><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"><tt> -</tt><html dir="ltr"><tt> -</tt><head><tt> -</tt><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"><tt> -</tt><meta http-equiv="Content-Style-Type" content="text/css"><tt> -</tt><tt> -</tt><title>RubyBB BBCode</title><tt> -</tt><style type="text/css"><tt> -</tt>.code {<tt> -</tt> width: 100%;<tt> -</tt> background-color: #FAFAFA;<tt> -</tt> border: 1px solid #D1D7DC;<tt> -</tt> font-family: 'Courier New', 'Terminal', monospace;<tt> -</tt> font-size: 10pt;<tt> -</tt> color: black;<tt> -</tt> vertical-align: top;<tt> -</tt> text-align: left;<tt> -</tt>}<tt> -</tt>.code .af { color:#00C; }<tt> -</tt>.code .an { color:#007; }<tt> -</tt>.code .av { color:#700; }<tt> -</tt>.code .aw { color:#C00; }<tt> -</tt>.code .bi { color:#509; font-weight:bold; }<tt> -</tt>.code .c { color:#888; }<tt> -</tt>.code .ch { color:#C28; font-weight:bold; }<tt> -</tt>.code .cl { color:#B06; font-weight:bold; }<tt> -</tt>.code .co { color:#036; font-weight:bold; }<tt> -</tt>.code .cr { color:#0A0; }<tt> -</tt>.code .cv { color:#369; }<tt> -</tt>.code .df { color:#099; font-weight:bold; }<tt> -</tt>.code .di { color:#088; font-weight:bold; }<tt> -</tt>.code .do { color:#970; }<tt> -</tt>.code .ds { color:#D42; font-weight:bold; }<tt> -</tt>.code .er { color:#F00; background-color:#FAA; }<tt> -</tt>.code .ex { color:#F00; font-weight:bold; }<tt> -</tt>.code .fl { color:#60E; font-weight:bold; }<tt> -</tt>.code .fu { color:#06B; font-weight:bold; }<tt> -</tt>.code .gv { color:#800; font-weight:bold; }<tt> -</tt>.code .hx { color:#058; font-weight:bold; }<tt> -</tt>.code .i { color:#00D; font-weight:bold; }<tt> -</tt>.code .ic { color:#B44; font-weight:bold; }<tt> -</tt>.code .in { color:#B2B; font-weight:bold; }<tt> -</tt>.code .iv { color:#33B; }<tt> -</tt>.code .la { color:#970; font-weight:bold; }<tt> -</tt>.code .lv { color:#963; }<tt> -</tt>.code .oc { color:#40E; font-weight:bold; }<tt> -</tt>.code .on { color:#000; font-weight:bold; }<tt> -</tt>.code .pc { color:#038; font-weight:bold; }<tt> -</tt>.code .pd { color:#369; font-weight:bold; }<tt> -</tt>.code .pp { color:#579; }<tt> -</tt>.code .pt { color:#339; font-weight:bold; }<tt> -</tt>.code .r { color:#080; font-weight:bold; }<tt> -</tt>.code .rx { color:#927; font-weight:bold; }<tt> -</tt>.code .s { color:#D42; font-weight:bold; }<tt> -</tt>.code .sh { color:#B2B; font-weight:bold; }<tt> -</tt>.code .sy { color:#A60; }<tt> -</tt>.code .ta { color:#070; }<tt> -</tt>.code .tf { color:#070; font-weight:bold; }<tt> -</tt>.code .ts { color:#D70; font-weight:bold; }<tt> -</tt>.code .ty { color:#339; font-weight:bold; }<tt> -</tt>.code .v { color:#036; }<tt> -</tt>.code .xt { color:#444; }<tt> -</tt></style><tt> -</tt></head><tt> -</tt><body><tt> -</tt><div class="code"><tt> -</tt><%CONTENT%><tt> -</tt></div><tt> -</tt><div class="validators"><tt> -</tt><a href="http://validator.w3.org/check?uri=referer"><img src="http://www.w3.org/Icons/valid-html401" alt="Valid HTML 4.01!" height="31" width="88" style="border:none;"></a><tt> -</tt><img style="border:0" src="http://jigsaw.w3.org/css-validator/images/vcss" alt="Valid CSS!" ><tt> -</tt></div> <tt> -</tt></body><tt> -</tt></html></span><span class="dl"><tt> -</tt> TEMPLATE</span></span><tt> -</tt><tt> -</tt> <span class="r">end</span><tt> -</tt><tt> -</tt><span class="r">end</span><tt> -</tt></pre></td> -</tr></table> - -</body> -</html> |