/usr/lib/ruby/1.8/rd/rdinlineparser.ry is in librd-ruby1.8 0.6.22-1.
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 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 | class RDInlineParser
preclow
nonassoc EX_LOW
left QUOTE BAR SLASH BACK_SLASH URL OTHER
REF_OPEN FOOTNOTE_OPEN FOOTNOTE_CLOSE
nonassoc EX_HIGH
prechigh
token EM_OPEN EM_CLOSE
CODE_OPEN CODE_CLOSE
VAR_OPEN VAR_CLOSE
KBD_OPEN KBD_CLOSE
INDEX_OPEN INDEX_CLOSE
REF_OPEN REF_CLOSE
FOOTNOTE_OPEN FOOTNOTE_CLOSE
VERB_OPEN VERB_CLOSE
BAR QUOTE SLASH BACK_SLASH URL OTHER EX_LOW EX_HIGH
rule
content : elements
;
elements : elements element { result.push(val[1]) }
| element { result = val }
;
element : emphasis
| code
| var
| keyboard
| index
| reference
| footnote
| verb
| normal_str_ele
;
emphasis : EM_OPEN content EM_CLOSE {
result = Emphasis.new
add_children_to_element(result, *val[1])
}
;
code : CODE_OPEN content CODE_CLOSE {
result = Code.new
add_children_to_element(result, *val[1])
}
;
var : VAR_OPEN content VAR_CLOSE {
result = Var.new
add_children_to_element(result, *val[1])
}
;
keyboard : KBD_OPEN content KBD_CLOSE {
result = Keyboard.new
add_children_to_element(result, *val[1])
}
;
index : INDEX_OPEN content INDEX_CLOSE {
result = Index.new
add_children_to_element(result, *val[1])
}
;
# Refernce
# ((<subst|filename/element_label>))
reference : REF_OPEN substitute ref_label REF_CLOSE
{ result = Reference.new(val[2])
add_children_to_element(result, *val[1])
}
| REF_OPEN ref_label2 REF_CLOSE
{
result = make_reference_from_label(val[1])
}
;
ref_label : URL ref_url_strings { result = Reference::URL.new(val[1]) }
| filename element_label
{ result = Reference::TemporaryLabel.new(val[1],
val[0]) }
| element_label
{ result = Reference::TemporaryLabel.new(val[0]) }
| filename { result = Reference::TemporaryLabel.new([], val[0]) }
;
ref_label2 : URL ref_url_strings { result = Reference::URL.new(val[1]) }
| filename element_label2
{ result = Reference::TemporaryLabel.new(val[1],
val[0]) }
| element_label2
{ result = Reference::TemporaryLabel.new(val[0]) }
| filename { result = Reference::TemporaryLabel.new([],
val[0]) }
;
substitute : ref_subst_content BAR
| QUOTE ref_subst_content_q QUOTE BAR
{ result = val[1] }
| QUOTE ref_subst_strings_q QUOTE BAR
{ result = [StringElement.new(val[1])] }
;
filename : ref_subst_strings_first SLASH
| QUOTE ref_subst_strings_q QUOTE SLASH
{ result = val[1] }
;
# when substitute part exists
element_label : ref_subst_strings_first
{ result = [StringElement.new(val[0])] }
| QUOTE ref_subst_strings_q QUOTE
{ result = [StringElement.new(val[1])] }
;
# when substitute part doesn't exist
# in this case, element label can contain Inlines
element_label2 : ref_subst_content
| QUOTE ref_subst_content_q QUOTE
{ result = val[1] }
| QUOTE ref_subst_strings_q QUOTE
{ result = [StringElement.new(val[1])] }
;
ref_subst_content : ref_subst_ele2 ref_subst_eles
{ result = val[1].unshift(val[0]) }
| ref_subst_str_ele_first ref_subst_eles
{ result = val[1].unshift(val[0]) }
| ref_subst_str_ele_first
{ result = val }
| ref_subst_ele2 { result = val }
;
ref_subst_content_q : ref_subst_eles_q
;
ref_subst_eles : ref_subst_eles ref_subst_ele
{ result.push(val[1]) }
| ref_subst_ele { result = val }
;
ref_subst_eles_q : ref_subst_eles_q ref_subst_ele_q
{ result.push(val[1]) }
| ref_subst_ele_q { result = val }
;
ref_subst_ele2 : emphasis
| code
| var
| keyboard
| index
| verb
;
ref_subst_ele : ref_subst_ele2
| ref_subst_str_ele
;
ref_subst_ele_q : ref_subst_ele2
| ref_subst_str_ele_q
;
ref_subst_str_ele : ref_subst_strings = EX_LOW
{ result = StringElement.new(val[0]) }
;
ref_subst_str_ele_first : ref_subst_strings_first
{ result = StringElement.new(val[0]) }
;
ref_subst_str_ele_q : ref_subst_strings_q = EX_LOW
{ result = StringElement.new(val[0]) }
;
ref_subst_strings : ref_subst_strings ref_subst_string3
{ result << val[1] }
| ref_subst_string3
;
# if it is first element of substitute, it can't contain
# URL on head.
ref_subst_strings_first : ref_subst_string ref_subst_strings = EX_HIGH
{ result << val[1] }
| ref_subst_string = EX_LOW
;
ref_subst_strings_q : ref_subst_strings_q ref_subst_string_q
{ result << val[1] }
| ref_subst_string_q
;
ref_subst_string : OTHER
| BACK_SLASH
| REF_OPEN
| FOOTNOTE_OPEN
| FOOTNOTE_CLOSE
;
ref_subst_string2 : ref_subst_string
| URL
;
ref_subst_string3 : ref_subst_string2
| QUOTE
;
ref_subst_string_q : ref_subst_string2
| BAR
| SLASH
;
# end subst
# string in url
ref_url_strings : ref_url_strings ref_url_string { result << val[1] }
| ref_url_string
;
ref_url_string : OTHER
| BACK_SLASH BACK_SLASH
| URL
| SLASH
| BAR
| QUOTE
| EM_OPEN
| EM_CLOSE
| CODE_OPEN
| CODE_CLOSE
| VAR_OPEN
| VAR_CLOSE
| KBD_OPEN
| KBD_CLOSE
| INDEX_OPEN
| INDEX_CLOSE
| REF_OPEN
| FOOTNOTE_OPEN
| FOOTNOTE_CLOSE
| VERB_OPEN
| VERB_CLOSE
;
# end url
# end Reference
footnote : FOOTNOTE_OPEN content FOOTNOTE_CLOSE {
result = Footnote.new
add_children_to_element(result, *val[1])
}
;
verb : VERB_OPEN verb_strings VERB_CLOSE {
result = Verb.new(val[1]) }
;
# normal string
# OTHER, QUOTE, BAR, SLASH, BACK_SLASH, URL
normal_string : OTHER
| QUOTE
| BAR
| SLASH
| BACK_SLASH
| URL
;
normal_strings : normal_strings normal_string
{ result << val[1] }
| normal_string
;
normal_str_ele : normal_strings = EX_LOW
{ result = StringElement.new(val[0]) }
;
# in verb
verb_string : verb_normal_string
| BACK_SLASH verb_normal_string { result = val[1] }
| BACK_SLASH VERB_CLOSE { result = val[1] }
| BACK_SLASH BACK_SLASH { result = val[1] }
;
verb_normal_string : OTHER
| QUOTE
| BAR
| SLASH
| EM_OPEN
| EM_CLOSE
| CODE_OPEN
| CODE_CLOSE
| VAR_OPEN
| VAR_CLOSE
| KBD_OPEN
| KBD_CLOSE
| INDEX_OPEN
| INDEX_CLOSE
| REF_OPEN
| REF_CLOSE
| FOOTNOTE_OPEN
| FOOTNOTE_CLOSE
| VERB_OPEN
| URL
;
verb_strings : verb_strings verb_string { result << val[1] }
| verb_string
;
/* verb_str_ele : verb_strings
; */
end
---- inner
include ParserUtility
extend Forwardable
EM_OPEN = '((*'
EM_OPEN_RE = /\A#{Regexp.quote(EM_OPEN)}/
EM_CLOSE = '*))'
EM_CLOSE_RE = /\A#{Regexp.quote(EM_CLOSE)}/
CODE_OPEN = '(({'
CODE_OPEN_RE = /\A#{Regexp.quote(CODE_OPEN)}/
CODE_CLOSE = '}))'
CODE_CLOSE_RE = /\A#{Regexp.quote(CODE_CLOSE)}/
VAR_OPEN = '((|'
VAR_OPEN_RE = /\A#{Regexp.quote(VAR_OPEN)}/
VAR_CLOSE = '|))'
VAR_CLOSE_RE = /\A#{Regexp.quote(VAR_CLOSE)}/
KBD_OPEN = '((%'
KBD_OPEN_RE = /\A#{Regexp.quote(KBD_OPEN)}/
KBD_CLOSE = '%))'
KBD_CLOSE_RE = /\A#{Regexp.quote(KBD_CLOSE)}/
INDEX_OPEN = '((:'
INDEX_OPEN_RE = /\A#{Regexp.quote(INDEX_OPEN)}/
INDEX_CLOSE = ':))'
INDEX_CLOSE_RE = /\A#{Regexp.quote(INDEX_CLOSE)}/
REF_OPEN = '((<'
REF_OPEN_RE = /\A#{Regexp.quote(REF_OPEN)}/
REF_CLOSE = '>))'
REF_CLOSE_RE = /\A#{Regexp.quote(REF_CLOSE)}/
FOOTNOTE_OPEN = '((-'
FOOTNOTE_OPEN_RE = /\A#{Regexp.quote(FOOTNOTE_OPEN)}/
FOOTNOTE_CLOSE = '-))'
FOOTNOTE_CLOSE_RE = /\A#{Regexp.quote(FOOTNOTE_CLOSE)}/
VERB_OPEN = "(('"
VERB_OPEN_RE = /\A#{Regexp.quote(VERB_OPEN)}/
VERB_CLOSE = "'))"
VERB_CLOSE_RE = /\A#{Regexp.quote(VERB_CLOSE)}/
BAR = "|"
BAR_RE = /\A#{Regexp.quote(BAR)}/
QUOTE = '"'
QUOTE_RE = /\A#{Regexp.quote(QUOTE)}/
SLASH = "/"
SLASH_RE = /\A#{Regexp.quote(SLASH)}/
BACK_SLASH = "\\"
BACK_SLASH_RE = /\A#{Regexp.quote(BACK_SLASH)}/
URL = "URL:"
URL_RE = /\A#{Regexp.quote(URL)}/
# Workaround for Regexp option change of Ruby 1.5.x
other_re_mode = Regexp::EXTENDED
if RUBY_VERSION > "1.5"
other_re_mode |= Regexp::MULTILINE
else
other_re_mode |= Regexp::POSIXLINE
end
OTHER_RE = Regexp.new(
"\\A.+?(?=#{Regexp.quote(EM_OPEN)}|#{Regexp.quote(EM_CLOSE)}|
#{Regexp.quote(CODE_OPEN)}|#{Regexp.quote(CODE_CLOSE)}|
#{Regexp.quote(VAR_OPEN)}|#{Regexp.quote(VAR_CLOSE)}|
#{Regexp.quote(KBD_OPEN)}|#{Regexp.quote(KBD_CLOSE)}|
#{Regexp.quote(INDEX_OPEN)}|#{Regexp.quote(INDEX_CLOSE)}|
#{Regexp.quote(REF_OPEN)}|#{Regexp.quote(REF_CLOSE)}|
#{Regexp.quote(FOOTNOTE_OPEN)}|#{Regexp.quote(FOOTNOTE_CLOSE)}|
#{Regexp.quote(VERB_OPEN)}|#{Regexp.quote(VERB_CLOSE)}|
#{Regexp.quote(BAR)}|
#{Regexp.quote(QUOTE)}|
#{Regexp.quote(SLASH)}|
#{Regexp.quote(BACK_SLASH)}|
#{Regexp.quote(URL)})", other_re_mode)
def initialize(bp)
@blockp = bp
end
def_delegator(:@blockp, :tree)
def parse(src)
@src = StringScanner.new(src)
@pre = ""
@yydebug = true
do_parse
end
def next_token
return [false, false] if @src.eos?
# p @src.rest if @yydebug
if ret = @src.scan(EM_OPEN_RE)
@pre << ret
[:EM_OPEN, ret]
elsif ret = @src.scan(EM_CLOSE_RE)
@pre << ret
[:EM_CLOSE, ret]
elsif ret = @src.scan(CODE_OPEN_RE)
@pre << ret
[:CODE_OPEN, ret]
elsif ret = @src.scan(CODE_CLOSE_RE)
@pre << ret
[:CODE_CLOSE, ret]
elsif ret = @src.scan(VAR_OPEN_RE)
@pre << ret
[:VAR_OPEN, ret]
elsif ret = @src.scan(VAR_CLOSE_RE)
@pre << ret
[:VAR_CLOSE, ret]
elsif ret = @src.scan(KBD_OPEN_RE)
@pre << ret
[:KBD_OPEN, ret]
elsif ret = @src.scan(KBD_CLOSE_RE)
@pre << ret
[:KBD_CLOSE, ret]
elsif ret = @src.scan(INDEX_OPEN_RE)
@pre << ret
[:INDEX_OPEN, ret]
elsif ret = @src.scan(INDEX_CLOSE_RE)
@pre << ret
[:INDEX_CLOSE, ret]
elsif ret = @src.scan(REF_OPEN_RE)
@pre << ret
[:REF_OPEN, ret]
elsif ret = @src.scan(REF_CLOSE_RE)
@pre << ret
[:REF_CLOSE, ret]
elsif ret = @src.scan(FOOTNOTE_OPEN_RE)
@pre << ret
[:FOOTNOTE_OPEN, ret]
elsif ret = @src.scan(FOOTNOTE_CLOSE_RE)
@pre << ret
[:FOOTNOTE_CLOSE, ret]
elsif ret = @src.scan(VERB_OPEN_RE)
@pre << ret
[:VERB_OPEN, ret]
elsif ret = @src.scan(VERB_CLOSE_RE)
@pre << ret
[:VERB_CLOSE, ret]
elsif ret = @src.scan(BAR_RE)
@pre << ret
[:BAR, ret]
elsif ret = @src.scan(QUOTE_RE)
@pre << ret
[:QUOTE, ret]
elsif ret = @src.scan(SLASH_RE)
@pre << ret
[:SLASH, ret]
elsif ret = @src.scan(BACK_SLASH_RE)
@pre << ret
[:BACK_SLASH, ret]
elsif ret = @src.scan(URL_RE)
@pre << ret
[:URL, ret]
elsif ret = @src.scan(OTHER_RE)
@pre << ret
[:OTHER, ret]
else
ret = @src.rest
@pre << ret
@src.terminate
[:OTHER, ret]
end
end
def make_reference_from_label(label)
# Reference.new_from_label_under_document_struct(label, tree.document_struct)
Reference.new_from_label_without_document_struct(label)
end
def on_error(et, ev, values)
lines_of_rest = @src.rest.to_a.length
prev_words = prev_words_on_error(ev)
at = 4 + prev_words.length
message = <<-MSG
RD syntax error: line #{@blockp.line_index - lines_of_rest}:
...#{prev_words} #{(ev||'')} #{next_words_on_error()} ...
MSG
message << " " * at + "^" * (ev ? ev.length : 0) + "\n"
raise ParseError, message
end
def prev_words_on_error(ev)
pre = @pre
if ev and /#{Regexp.quote(ev)}$/ =~ pre
pre = $`
end
last_line(pre)
end
def last_line(src)
if n = src.rindex("\n")
src[(n+1) .. -1]
else
src
end
end
private :last_line
def next_words_on_error
if n = @src.rest.index("\n")
@src.rest[0 .. (n-1)]
else
@src.rest
end
end
---- header
require "rd/parser-util"
require "forwardable"
require "strscan"
module RD
---- footer
end # end of module RD
|