Module: IRCParser
- Extended by:
- IRCParser
- Included in:
- IRCParser
- Defined in:
- lib/irc_parser.rb,
lib/irc_parser/helper.rb,
lib/irc_parser/parser.rb,
lib/irc_parser/messages.rb
Defined Under Namespace
Modules: Helper, Messages Classes: ParserError
Constant Summary collapse
- VERSION =
"0.1.2"
- CLASS_FROM_PARSE =
line 51 “lib/irc_parser/parser.rl”
Hash.new { |h,k| h[k] = Messages::ALL[k] }
Class Attribute Summary collapse
-
._irc_parser_index_offsets ⇒ Object
Returns the value of attribute _irc_parser_index_offsets.
-
._irc_parser_indicies ⇒ Object
Returns the value of attribute _irc_parser_indicies.
-
._irc_parser_key_spans ⇒ Object
Returns the value of attribute _irc_parser_key_spans.
-
._irc_parser_trans_actions ⇒ Object
Returns the value of attribute _irc_parser_trans_actions.
-
._irc_parser_trans_keys ⇒ Object
Returns the value of attribute _irc_parser_trans_keys.
-
._irc_parser_trans_targs ⇒ Object
Returns the value of attribute _irc_parser_trans_targs.
-
.irc_parser_en_main ⇒ Object
Returns the value of attribute irc_parser_en_main.
-
.irc_parser_error ⇒ Object
Returns the value of attribute irc_parser_error.
-
.irc_parser_first_final ⇒ Object
Returns the value of attribute irc_parser_first_final.
-
.irc_parser_start ⇒ Object
Returns the value of attribute irc_parser_start.
Instance Method Summary collapse
- #message(identifier, prefix = nil, params = nil) {|obj| ... } ⇒ Object
- #message_class(identifier) ⇒ Object
- #parse(message) ⇒ Object
- #parse_raw(message) ⇒ Object
Class Attribute Details
._irc_parser_index_offsets ⇒ Object
Returns the value of attribute _irc_parser_index_offsets.
40 41 42 |
# File 'lib/irc_parser/parser.rb', line 40 def _irc_parser_index_offsets @_irc_parser_index_offsets end |
._irc_parser_indicies ⇒ Object
Returns the value of attribute _irc_parser_indicies.
50 51 52 |
# File 'lib/irc_parser/parser.rb', line 50 def _irc_parser_indicies @_irc_parser_indicies end |
._irc_parser_key_spans ⇒ Object
Returns the value of attribute _irc_parser_key_spans.
30 31 32 |
# File 'lib/irc_parser/parser.rb', line 30 def _irc_parser_key_spans @_irc_parser_key_spans end |
._irc_parser_trans_actions ⇒ Object
Returns the value of attribute _irc_parser_trans_actions.
306 307 308 |
# File 'lib/irc_parser/parser.rb', line 306 def _irc_parser_trans_actions @_irc_parser_trans_actions end |
._irc_parser_trans_keys ⇒ Object
Returns the value of attribute _irc_parser_trans_keys.
13 14 15 |
# File 'lib/irc_parser/parser.rb', line 13 def _irc_parser_trans_keys @_irc_parser_trans_keys end |
._irc_parser_trans_targs ⇒ Object
Returns the value of attribute _irc_parser_trans_targs.
294 295 296 |
# File 'lib/irc_parser/parser.rb', line 294 def _irc_parser_trans_targs @_irc_parser_trans_targs end |
.irc_parser_en_main ⇒ Object
Returns the value of attribute irc_parser_en_main.
331 332 333 |
# File 'lib/irc_parser/parser.rb', line 331 def irc_parser_en_main @irc_parser_en_main end |
.irc_parser_error ⇒ Object
Returns the value of attribute irc_parser_error.
326 327 328 |
# File 'lib/irc_parser/parser.rb', line 326 def irc_parser_error @irc_parser_error end |
.irc_parser_first_final ⇒ Object
Returns the value of attribute irc_parser_first_final.
322 323 324 |
# File 'lib/irc_parser/parser.rb', line 322 def irc_parser_first_final @irc_parser_first_final end |
.irc_parser_start ⇒ Object
Returns the value of attribute irc_parser_start.
318 319 320 |
# File 'lib/irc_parser/parser.rb', line 318 def irc_parser_start @irc_parser_start end |
Instance Method Details
#message(identifier, prefix = nil, params = nil) {|obj| ... } ⇒ Object
10 11 12 13 14 15 16 |
# File 'lib/irc_parser.rb', line 10 def (identifier, prefix = nil, params = nil) klass = Messages::ALL[identifier] raise IRCParser::Parser::Error, "Message not recognized: #{.inspect}" unless klass obj = klass.new(prefix, params) yield obj if block_given? obj end |
#message_class(identifier) ⇒ Object
18 19 20 21 22 |
# File 'lib/irc_parser.rb', line 18 def (identifier) klass = Messages::ALL[identifier] raise ArgumentError.new("no message with identifier #{identifier.inspect}") unless klass klass end |
#parse(message) ⇒ Object
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 |
# File 'lib/irc_parser/parser.rb', line 340 def parse() data = .unpack("c*") prefix, command, params = nil, nil, [] # line 347 "lib/irc_parser/parser.rb" begin p ||= 0 pe ||= data.length cs = irc_parser_start end # line 60 "lib/irc_parser/parser.rl" # line 356 "lib/irc_parser/parser.rb" begin testEof = false _slen, _trans, _keys, _inds, _acts, _nacts = nil _goto_level = 0 _resume = 10 _eof_trans = 15 _again = 20 _test_eof = 30 _out = 40 while true if _goto_level <= 0 if p == pe _goto_level = _test_eof next end if cs == 0 _goto_level = _out next end end if _goto_level <= _resume _keys = cs << 1 _inds = _irc_parser_index_offsets[cs] _slen = _irc_parser_key_spans[cs] _trans = if ( _slen > 0 && _irc_parser_trans_keys[_keys] <= data[p] && data[p] <= _irc_parser_trans_keys[_keys + 1] ) then _irc_parser_indicies[ _inds + data[p] - _irc_parser_trans_keys[_keys] ] else _irc_parser_indicies[ _inds + _slen ] end cs = _irc_parser_trans_targs[_trans] if _irc_parser_trans_actions[_trans] != 0 case _irc_parser_trans_actions[_trans] when 1 then # line 32 "lib/irc_parser/parser.rl" begin mark = p end when 5 then # line 33 "lib/irc_parser/parser.rl" begin prefix = data[mark..(p-1)].pack("c*") end when 2 then # line 34 "lib/irc_parser/parser.rl" begin command = data[mark..(p-1)].pack("c*") end when 3 then # line 35 "lib/irc_parser/parser.rl" begin params << data[mark..(p-1)].pack("c*") end when 4 then # line 32 "lib/irc_parser/parser.rl" begin mark = p end # line 35 "lib/irc_parser/parser.rl" begin params << data[mark..(p-1)].pack("c*") end # line 415 "lib/irc_parser/parser.rb" end end end if _goto_level <= _again if cs == 0 _goto_level = _out next end p += 1 if p != pe _goto_level = _resume next end end if _goto_level <= _test_eof end if _goto_level <= _out break end end end # line 61 "lib/irc_parser/parser.rl" if cs >= irc_parser_first_final klass = CLASS_FROM_PARSE[command] raise ParserError, "Message not recognized: #{.inspect}" unless klass klass.new(prefix, params) elsif !~ /\r\n$/ raise ParserError, "Message must finish with \\r\\n" else raise ParserError, end end |
#parse_raw(message) ⇒ Object
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 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 |
# File 'lib/irc_parser/parser.rb', line 450 def parse_raw() data = .unpack("c*") prefix, command, params = nil, nil, [] # line 457 "lib/irc_parser/parser.rb" begin p ||= 0 pe ||= data.length cs = irc_parser_start end # line 79 "lib/irc_parser/parser.rl" # line 466 "lib/irc_parser/parser.rb" begin testEof = false _slen, _trans, _keys, _inds, _acts, _nacts = nil _goto_level = 0 _resume = 10 _eof_trans = 15 _again = 20 _test_eof = 30 _out = 40 while true if _goto_level <= 0 if p == pe _goto_level = _test_eof next end if cs == 0 _goto_level = _out next end end if _goto_level <= _resume _keys = cs << 1 _inds = _irc_parser_index_offsets[cs] _slen = _irc_parser_key_spans[cs] _trans = if ( _slen > 0 && _irc_parser_trans_keys[_keys] <= data[p] && data[p] <= _irc_parser_trans_keys[_keys + 1] ) then _irc_parser_indicies[ _inds + data[p] - _irc_parser_trans_keys[_keys] ] else _irc_parser_indicies[ _inds + _slen ] end cs = _irc_parser_trans_targs[_trans] if _irc_parser_trans_actions[_trans] != 0 case _irc_parser_trans_actions[_trans] when 1 then # line 32 "lib/irc_parser/parser.rl" begin mark = p end when 5 then # line 33 "lib/irc_parser/parser.rl" begin prefix = data[mark..(p-1)].pack("c*") end when 2 then # line 34 "lib/irc_parser/parser.rl" begin command = data[mark..(p-1)].pack("c*") end when 3 then # line 35 "lib/irc_parser/parser.rl" begin params << data[mark..(p-1)].pack("c*") end when 4 then # line 32 "lib/irc_parser/parser.rl" begin mark = p end # line 35 "lib/irc_parser/parser.rl" begin params << data[mark..(p-1)].pack("c*") end # line 525 "lib/irc_parser/parser.rb" end end end if _goto_level <= _again if cs == 0 _goto_level = _out next end p += 1 if p != pe _goto_level = _resume next end end if _goto_level <= _test_eof end if _goto_level <= _out break end end end # line 80 "lib/irc_parser/parser.rl" if cs >= irc_parser_first_final return prefix, command, params elsif !~ /\r\n$/ raise ParserError, "Message must finish with \\r\\n" else raise ParserError, end end |