/usr/lib/falcon/parser/creole.fal is in libfalcon-engine1 0.9.6.9-git20120606-2.1+b1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 | /*
FALCON - Generic Parser
FILE: creole.fal
Read and parses creole WIKI data.
-------------------------------------------------------------------
Author: Giancarlo Niccolai
Begin: Sat, 30 Aug 2008 09:42:22 +0200
-------------------------------------------------------------------
(C) Copyright 2008: the FALCON developers (see list in AUTHORS file)
See LICENSE file for licensing details.
*/
import Node from parser.genparser.node as Node
import LevelNode from parser.genparser.node as LevelNode
import InfoNode from parser.genparser.node as InfoNode
import PState from parser.genparser as PState
import Context from parser.genparser as Context
import ReRule from parser.genparser.rules as ReRule
import ReRuleLA from parser.genparser.rules as ReRuleLA
import TagRule from parser.genparser.rules as TagRule
import EmptyLineRule from parser.genparser.rules as EmptyLineRule
import DummyRule from parser.genparser.rules as DummyRule
import CharRule from parser.genparser.rules as CharRule
import Parser from parser.genparser
Headers = .[
ReRule( '^\s*======\s*(.+?)\s*=*$', "#stay", {ctx, ma, title=> ctx.add( LevelNode("header", 6, title))})
ReRule( '^\s*=====\s*(.+?)\s*=*$', "#stay", {ctx, ma, title=> ctx.add( LevelNode("header", 5, title))})
ReRule( '^\s*====\s*(.+?)\s*=*$', "#stay", {ctx, ma, title=> ctx.add( LevelNode("header", 4, title))})
ReRule( '^\s*===\s*(.+?)\s*=*$', "#stay", {ctx, ma, title=> ctx.add( LevelNode("header", 3, title))})
ReRule( '^\s*==\s*(.+?)\s*=*$', "#stay", {ctx, ma, title=> ctx.add( LevelNode("header", 2, title))} )
ReRule( '^\s*=\s*(.+?)\s*=*$', "#stay", {ctx, ma, title=> ctx.add( LevelNode("header", 1, title))} )
ReRule( '^\s*----*$', "#stay", {ctx, ma, title=> ctx.add( Node("hr", title))} )
]
Headers2 = .[
ReRule( '^\s*======\s*(.+?)\s*=*$', "#pop", {ctx, ma, title=> ctx.popNode(); ctx.add( LevelNode("header", 6, title))})
ReRule( '^\s*=====\s*(.+?)\s*=*$', "#pop", {ctx, ma, title=> ctx.popNode();ctx.add( LevelNode("header", 5, title))})
ReRule( '^\s*====\s*(.+?)\s*=*$', "#pop", {ctx, ma, title=> ctx.popNode();ctx.add( LevelNode("header", 4, title))})
ReRule( '^\s*===\s*(.+?)\s*=*$', "#pop", {ctx, ma, title=> ctx.popNode();ctx.add( LevelNode("header", 3, title))})
ReRule( '^\s*==\s*(.+?)\s*=*$', "#pop", {ctx, ma, title=> ctx.popNode(); ctx.add( LevelNode("header", 2, title))} )
ReRule( '^\s*=\s*(.+?)\s*=*$', "#pop", {ctx, ma, title=> ctx.popNode(); ctx.add( LevelNode("header", 1, title))} )
ReRule( '^\s*----*$', "#pop", {ctx=> ctx.popNode(); ctx.add( Node("hr"))} )
]
TableStart = .[
ReRule( '^\s*\|=\s*', "table", {ctx => ctx.pushNode( Node("table") ); ctx.pushNode(Node("tr")); ctx.pushNode(Node("th"))} )
ReRule( '^\s*\|\s*', "table", {ctx => ctx.pushNode( Node("table") ); ctx.pushNode(Node("tr")); ctx.pushNode(Node("td"))} )
]
Indents = .[
ReRule( '^\s*::::\s*', "#stay", {ctx=> ctx.pushNode( LevelNode("indent", 4) ) })
ReRule( '^\s*:::\s*', "#stay", {ctx=> ctx.pushNode( LevelNode("indent", 3) ) })
ReRule( '^\s*::\s*', "#stay", {ctx=> ctx.pushNode( LevelNode("indent", 2) ) })
ReRule( '^\s*:\s*', "#stay", {ctx=> ctx.pushNode( LevelNode("indent", 1) ) })
]
SpecialEntities = .[
TagRule( '<', "#stay", {ctx => ctx.add("<")} )
TagRule( '>', "#stay", {ctx => ctx.add(">")} )
TagRule( '&', "#stay", {ctx => ctx.add("&")} )
TagRule( '"', "#stay", {ctx => ctx.add(""")} )
]
ListStart = .[
ReRule( '^\s*#\s*', "list", {ctx=> ctx.setListDepth( 1, "ol") })
ReRule( '^\s*\*\s*', "list", {ctx=> ctx.setListDepth( 1, "ul") })
]
FormatElements = .[
TagRule( "**", "bold", {ctx => ctx.pushNode( Node("b"))} )
TagRule( "//", "italic", {ctx => ctx.pushNode( Node("i"))} )
TagRule( "__", "underline", {ctx => ctx.pushNode( Node("u"))} )
TagRule( "^^", "superscript", {ctx => ctx.pushNode( Node("sup"))} )
TagRule( ",,", "subscript", {ctx => ctx.pushNode( Node("sub"))} )
TagRule( '\\', "#stay", {ctx=> ctx.add( Node("br"))} )
TagRule( '{{{', "verbatim", {ctx => ctx.pushNode( Node("tt"))} )
TagRule( "~~", "#stay", {ctx => ctx.add( "~" )} ) // escape escaped
TagRule( "~", "escape" ) // escape char
]
LinkElements = .[
ReRule( '\[\[:(.*?)(\|(.*?))?(\|(.*?))?\]\]', "#stay",
{ctx, ma, pg, d1, txt, d2, mx =>
ctx.add(
InfoNode("file", _options(mx, ["name"=>pg, "text"=>txt, "ext"=>true]))
)
})
ReRule( '\[\[(https?:.*?|ftp:.*?)(\|(.*?))?(\|(.*?))?\]\]', "#stay",
{ctx, ma, pg, d1, txt, d2, mx =>
ctx.add(
InfoNode("link", _options(mx, ["name"=>pg, "text"=>txt, "ext"=>true]))
)
})
ReRule( '\[\[([^:|\]]+):(.*?)(\|(.*?))?(\|(.*?))?\]\]', "#stay",
{ctx, ma, ilink, pg, d1, txt, d2, mx =>
ctx.add(
InfoNode("link", _options(mx, ["name"=>pg, "ext"=>false, "text"=>txt, "ilink"=>ilink]))
)
})
ReRule( '\[\[(.*?)(\|(.*?))?(\|(.*?))?\]\]', "#stay",
{ctx, ma, pg, d1, txt, d2, mx =>
ctx.add(
InfoNode("link", _options(mx, ["name"=>pg, "ext"=>false, "text"=>txt]))
)
})
ReRule( 'https?://[^ ;,\?!:]+', "#stay", {ctx, ma=> ctx.add( InfoNode("link", ["name"=>ma, "text"=>nil, "ext"=>true]))} )
ReRule( 'ftp://[^ ;,\?!:]+', "#stay", {ctx, ma=> ctx.add( InfoNode("link", ["name"=>ma, "text"=>nil, "ext"=>true]))} )
ReRule( '\{\{(.*?)(\|(.*?))?(\|(.*?))\}\}', "#stay", {ctx, ma, pg, d0, txt, d1, mx =>
ctx.add( InfoNode("img", _options(mx, ["name"=>pg, "alt"=> (txt? txt:pg)])))} )
ReRule( '<<(.*?)(\s+(.*?))?>>', "#stay", {ctx, ma, pname, d0, popts =>
ctx.add( InfoNode("plugin", ["name"=>pname, "params"=>_params(popts)], true) ) } )
]
InlineElements = FormatElements + LinkElements + SpecialEntities
/*
Determine the options of a optioned link
*/
function _options( mx, res )
if not mx: return res
elems = mx.split("|")
ielem = 0
le = elems.len()
while ielem < le
elem = elems[ielem++]
if "=" in elem
k,v = elem.split("=",2)
res[k] = v
else
res[elem] = true
end
end
return res
end
/*
Determine options of plugins
*/
function _params( opts )
return opts
end
function _inlineState( limit )
return PState(.[
EmptyLineRule( "#pop;#pop", {ctx => ctx.popNode(); ctx.popNode()} ) // return to base
// Putting it before allows to override
TagRule( limit, "#pop", {ctx => ctx.popNode()} )
]
+ InlineElements,
{ctx, data=>ctx.add( data )},
"para_continue" // the paragraph can contiune at the end of an inline
)
end
class Parser from parser.genparser.Parser
states = [
"start"=> PState(.[
EmptyLineRule( "#stay" ) // at start, empty lines are ignored
]
+ Headers
+ .[ DummyRule( "para", { ctx => ctx.pushNode( Node("para") )} ) ]
),
"para" =>PState(.[
EmptyLineRule( "#pop", {ctx=> ctx.popNode()})
ReRule( '^\{\{\{([^\s]+)$', "verbatim_code", {ctx, ma, lang => ctx.pushNode( InfoNode("code", ["lang"=>lang]))} )
ReRule( '^\{\{\{$', "verbatim_line", {ctx => ctx.pushNode( Node("pre"))} )
ReRule( '^\+\+\+*\s*(.*)?$', "quote_base", {ctx, ma, link => ctx.popNode();
ctx.pushNode( InfoNode("quote", ["link"=>link]))} )
]
+ TableStart
+ ListStart
+ InlineElements
+ Indents
+ Headers2,
{ctx, data=>ctx.add( data )},
"para_continue"
),
"quote_base" =>PState(.[
ReRule( '^\+\+\+*$', "#pop;#pop", {ctx => ctx.popNode();} )
DummyRule( "quote", { ctx => ctx.pushNode( Node("para") )} )
]
),
"quote" =>PState(.[
EmptyLineRule( "#pop", {ctx=> ctx.popNode()})
ReRuleLA( '^\+\+\+*$', "#pop", {ctx => ctx.popNode()} )
]
+ ListStart
+ InlineElements,
{ctx, data=>ctx.add( data )},
"para_continue"
),
"para_continue"=> PState(
.[ DummyRule( "#pop", { ctx => ctx.add(" ")} ) ]
),
"eolverbatim" =>PState(.[
DummyRule( "#pop", { ctx => ctx.add( "\n") } )
]
),
"table" => PState(.[
// at the end of the line we close TD and TR
EmptyLineRule( "#pop")
]
+ InlineElements
+.[
ReRule( '\s*\|$', "tableBeginLine", {ctx=> ctx.popNode(); ctx.popNode()} )
ReRule( '\s*\|=\s*', "#stay", {ctx=> ctx.popNode(); ctx.pushNode(Node("th"))} )
ReRule( '\s*\|\s*', "#stay", {ctx=> ctx.popNode(); ctx.pushNode(Node("td"))} )
ReRule( '\s*$', "#pop", {ctx=> ctx.popNode(); ctx.popNode(); ctx.popNode()} )
],
{ctx, data=>ctx.add( data )}
),
"tableBeginLine" => PState(.[
ReRule( '^\s*\|=\s*', "#pop", {ctx=> ctx.pushNode(Node("tr")); ctx.pushNode(Node("th"))} )
ReRule( '^\s*\|\s*', "#pop", {ctx=> ctx.pushNode(Node("tr")); ctx.pushNode(Node("td"))} )
DummyRule( "#pop", {ctx=> ctx.popNode(); } )
]
),
// Some inline states
"bold" => _inlineState( "**" ),
"italic" => _inlineState( "//" ),
"superscript" => _inlineState( "^^" ),
"subscript" => _inlineState( ",," ),
"underline" => _inlineState( "__" ),
"list" => PState(.[
EmptyLineRule( "#pop;#pop", { ctx=> ctx.setListDepth( 0 ); ctx.popNode(); })
ReRule( '^\s*######\s*', "#stay", {ctx=> ctx.setListDepth(6, "ol" ) })
ReRule( '^\s*#####\s*', "#stay", {ctx=> ctx.setListDepth(5, "ol" ) })
ReRule( '^\s*####\s*', "#stay", {ctx=> ctx.setListDepth(4, "ol" ) })
ReRule( '^\s*###\s*', "#stay", {ctx=> ctx.setListDepth(3, "ol" ) })
ReRule( '^\s*##\s*', "#stay", {ctx=> ctx.setListDepth(2, "ol" )})
ReRule( '^\s*#\s*', "#stay", {ctx=> ctx.setListDepth(1, "ol" )})
ReRule( '^\s*\*\*\*\*\*\*\s*', "#stay", {ctx=> ctx.setListDepth(6, "ul" ) })
ReRule( '^\s*\*\*\*\*\*\s*', "#stay", {ctx=> ctx.setListDepth(5, "ul" ) })
ReRule( '^\s*\*\*\*\*\s*', "#stay", {ctx=> ctx.setListDepth(4, "ul" ) })
ReRule( '^\s*\*\*\*\s*', "#stay", {ctx=> ctx.setListDepth(3, "ul" ) })
ReRule( '^\s*\*\*\s*', "#stay", {ctx=> ctx.setListDepth(2, "ul" )})
ReRule( '^\s*\*\s*', "#stay", {ctx=> ctx.setListDepth(1, "ul" )})
]
+ InlineElements,
{ctx, data=>ctx.add( data )},
"para_continue"
),
"escape" =>PState(.[
TagRule( "https://", "#pop", {ctx => ctx.add( "https://" )} ) // escaped links
TagRule( "http://", "#pop", {ctx => ctx.add( "http://" )} ) // escaped links
TagRule( "ftp://", "#pop", {ctx => ctx.add( "ftp://" )} ) // escaped links
CharRule( "#pop", {ctx, c => if c: ctx.add(c) } )
// force to go away if can't grab even a char
],
nil, // No unrecognised possibile
"*#pop" // pop if not matched at the end of the line, like ~\n
),
"verbatim_line" =>PState(.[
ReRule( '^}}}$', "#pop", {ctx => ctx.popNode()} )
]
+ SpecialEntities,
{ctx, data=>ctx.add( data )},
"eolverbatim"
),
"verbatim_code" =>PState(.[
ReRule( '^}}}$', "#pop", {ctx => ctx.popNode()} )
],
{ctx, data=>ctx.add( data )},
"eolverbatim"
),
"verbatim" =>PState(.[
EmptyLineRule( "#pop;#pop", {ctx => ctx.popNode(); ctx.popNode()} ) // pop if newpara
TagRule( '}}}', "#pop", {ctx => ctx.popNode()} )
]
+ SpecialEntities,
{ctx, data=>ctx.add( data )}
),
// Just to be able to add always "," at the end
"*dummy" => nil
]
function reset()
self.initParser( "start" )
end
end
|