Module: GraphQL::Language::Lexer
- Defined in:
- lib/graphql/language/lexer.rb
Class Attribute Summary collapse
-
._graphql_lexer_actions ⇒ Object
Returns the value of attribute _graphql_lexer_actions.
-
._graphql_lexer_eof_trans ⇒ Object
Returns the value of attribute _graphql_lexer_eof_trans.
-
._graphql_lexer_from_state_actions ⇒ Object
Returns the value of attribute _graphql_lexer_from_state_actions.
-
._graphql_lexer_index_offsets ⇒ Object
Returns the value of attribute _graphql_lexer_index_offsets.
-
._graphql_lexer_indicies ⇒ Object
Returns the value of attribute _graphql_lexer_indicies.
-
._graphql_lexer_key_offsets ⇒ Object
Returns the value of attribute _graphql_lexer_key_offsets.
-
._graphql_lexer_range_lengths ⇒ Object
Returns the value of attribute _graphql_lexer_range_lengths.
-
._graphql_lexer_single_lengths ⇒ Object
Returns the value of attribute _graphql_lexer_single_lengths.
-
._graphql_lexer_to_state_actions ⇒ Object
Returns the value of attribute _graphql_lexer_to_state_actions.
-
._graphql_lexer_trans_actions ⇒ Object
Returns the value of attribute _graphql_lexer_trans_actions.
-
._graphql_lexer_trans_keys ⇒ Object
Returns the value of attribute _graphql_lexer_trans_keys.
-
._graphql_lexer_trans_targs ⇒ Object
Returns the value of attribute _graphql_lexer_trans_targs.
-
.graphql_lexer_en_main ⇒ Object
Returns the value of attribute graphql_lexer_en_main.
-
.graphql_lexer_error ⇒ Object
Returns the value of attribute graphql_lexer_error.
-
.graphql_lexer_first_final ⇒ Object
Returns the value of attribute graphql_lexer_first_final.
-
.graphql_lexer_start ⇒ Object
Returns the value of attribute graphql_lexer_start.
Class Method Summary collapse
- .emit(token_name, ts, te, meta) ⇒ Object
- .emit_string(ts, te, meta) ⇒ Object
-
.replace_escaped_characters_in_place(raw_string) ⇒ Object
Replace any escaped unicode or whitespace with the actual characters To avoid allocating more strings, this modifies the string passed into it.
-
.run_lexer(query_string) ⇒ Object
line 99 “lib/graphql/language/lexer.rl”.
- .tokenize(query_string) ⇒ Object
Class Attribute Details
._graphql_lexer_actions ⇒ Object
Returns the value of attribute _graphql_lexer_actions.
28 29 30 |
# File 'lib/graphql/language/lexer.rb', line 28 def _graphql_lexer_actions @_graphql_lexer_actions end |
._graphql_lexer_eof_trans ⇒ Object
Returns the value of attribute _graphql_lexer_eof_trans.
273 274 275 |
# File 'lib/graphql/language/lexer.rb', line 273 def _graphql_lexer_eof_trans @_graphql_lexer_eof_trans end |
._graphql_lexer_from_state_actions ⇒ Object
Returns the value of attribute _graphql_lexer_from_state_actions.
259 260 261 |
# File 'lib/graphql/language/lexer.rb', line 259 def _graphql_lexer_from_state_actions @_graphql_lexer_from_state_actions end |
._graphql_lexer_index_offsets ⇒ Object
Returns the value of attribute _graphql_lexer_index_offsets.
147 148 149 |
# File 'lib/graphql/language/lexer.rb', line 147 def _graphql_lexer_index_offsets @_graphql_lexer_index_offsets end |
._graphql_lexer_indicies ⇒ Object
Returns the value of attribute _graphql_lexer_indicies.
161 162 163 |
# File 'lib/graphql/language/lexer.rb', line 161 def _graphql_lexer_indicies @_graphql_lexer_indicies end |
._graphql_lexer_key_offsets ⇒ Object
Returns the value of attribute _graphql_lexer_key_offsets.
47 48 49 |
# File 'lib/graphql/language/lexer.rb', line 47 def _graphql_lexer_key_offsets @_graphql_lexer_key_offsets end |
._graphql_lexer_range_lengths ⇒ Object
Returns the value of attribute _graphql_lexer_range_lengths.
133 134 135 |
# File 'lib/graphql/language/lexer.rb', line 133 def _graphql_lexer_range_lengths @_graphql_lexer_range_lengths end |
._graphql_lexer_single_lengths ⇒ Object
Returns the value of attribute _graphql_lexer_single_lengths.
119 120 121 |
# File 'lib/graphql/language/lexer.rb', line 119 def _graphql_lexer_single_lengths @_graphql_lexer_single_lengths end |
._graphql_lexer_to_state_actions ⇒ Object
Returns the value of attribute _graphql_lexer_to_state_actions.
245 246 247 |
# File 'lib/graphql/language/lexer.rb', line 245 def _graphql_lexer_to_state_actions @_graphql_lexer_to_state_actions end |
._graphql_lexer_trans_actions ⇒ Object
Returns the value of attribute _graphql_lexer_trans_actions.
227 228 229 |
# File 'lib/graphql/language/lexer.rb', line 227 def _graphql_lexer_trans_actions @_graphql_lexer_trans_actions end |
._graphql_lexer_trans_keys ⇒ Object
Returns the value of attribute _graphql_lexer_trans_keys.
61 62 63 |
# File 'lib/graphql/language/lexer.rb', line 61 def _graphql_lexer_trans_keys @_graphql_lexer_trans_keys end |
._graphql_lexer_trans_targs ⇒ Object
Returns the value of attribute _graphql_lexer_trans_targs.
209 210 211 |
# File 'lib/graphql/language/lexer.rb', line 209 def _graphql_lexer_trans_targs @_graphql_lexer_trans_targs end |
.graphql_lexer_en_main ⇒ Object
Returns the value of attribute graphql_lexer_en_main.
300 301 302 |
# File 'lib/graphql/language/lexer.rb', line 300 def graphql_lexer_en_main @graphql_lexer_en_main end |
.graphql_lexer_error ⇒ Object
Returns the value of attribute graphql_lexer_error.
295 296 297 |
# File 'lib/graphql/language/lexer.rb', line 295 def graphql_lexer_error @graphql_lexer_error end |
.graphql_lexer_first_final ⇒ Object
Returns the value of attribute graphql_lexer_first_final.
291 292 293 |
# File 'lib/graphql/language/lexer.rb', line 291 def graphql_lexer_first_final @graphql_lexer_first_final end |
.graphql_lexer_start ⇒ Object
Returns the value of attribute graphql_lexer_start.
287 288 289 |
# File 'lib/graphql/language/lexer.rb', line 287 def graphql_lexer_start @graphql_lexer_start end |
Class Method Details
.emit(token_name, ts, te, meta) ⇒ Object
728 729 730 731 732 733 734 735 736 737 |
# File 'lib/graphql/language/lexer.rb', line 728 def self.emit(token_name, ts, te, ) [:tokens] << GraphQL::Language::Token.new( name: token_name, value: [:data][ts...te].pack("c*"), line: [:line], col: [:col], ) # Bump the column counter for the next token [:col] += te - ts end |
.emit_string(ts, te, meta) ⇒ Object
754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 |
# File 'lib/graphql/language/lexer.rb', line 754 def self.emit_string(ts, te, ) value = [:data][ts...te].pack("c*").force_encoding("UTF-8") if value =~ /\\u|\\./ && value !~ ESCAPES [:tokens] << GraphQL::Language::Token.new( name: :BAD_UNICODE_ESCAPE, value: value, line: [:line], col: [:col], ) else replace_escaped_characters_in_place(value) [:tokens] << GraphQL::Language::Token.new( name: :STRING, value: value, line: [:line], col: [:col], ) end [:col] += te - ts end |
.replace_escaped_characters_in_place(raw_string) ⇒ Object
Replace any escaped unicode or whitespace with the actual characters To avoid allocating more strings, this modifies the string passed into it
17 18 19 20 21 |
# File 'lib/graphql/language/lexer.rb', line 17 def self.replace_escaped_characters_in_place(raw_string) raw_string.gsub!(ESCAPES, ESCAPES_REPLACE) raw_string.gsub!(UTF_8, &UTF_8_REPLACE) nil end |
.run_lexer(query_string) ⇒ Object
line 99 “lib/graphql/language/lexer.rl”
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 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 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 |
# File 'lib/graphql/language/lexer.rb', line 307 def self.run_lexer(query_string) data = query_string.unpack("c*") eof = data.length = { line: 1, col: 1, data: data, tokens: [] } # line 320 "lib/graphql/language/lexer.rb" begin p ||= 0 pe ||= data.length cs = graphql_lexer_start ts = nil te = nil act = 0 end # line 112 "lib/graphql/language/lexer.rl" emit_token = -> (name) { emit(name, ts, te, ) } # line 337 "lib/graphql/language/lexer.rb" begin _klen, _trans, _keys, _acts, _nacts = nil _goto_level = 0 _resume = 10 _eof_trans = 15 _again = 20 _test_eof = 30 _out = 40 while true _trigger_goto = false if _goto_level <= 0 if p == pe _goto_level = _test_eof next end end if _goto_level <= _resume _acts = _graphql_lexer_from_state_actions[cs] _nacts = _graphql_lexer_actions[_acts] _acts += 1 while _nacts > 0 _nacts -= 1 _acts += 1 case _graphql_lexer_actions[_acts - 1] when 1 then # line 1 "NONE" begin ts = p end # line 367 "lib/graphql/language/lexer.rb" end # from state action switch end if _trigger_goto next end _keys = _graphql_lexer_key_offsets[cs] _trans = _graphql_lexer_index_offsets[cs] _klen = _graphql_lexer_single_lengths[cs] _break_match = false begin if _klen > 0 _lower = _keys _upper = _keys + _klen - 1 loop do break if _upper < _lower _mid = _lower + ( (_upper - _lower) >> 1 ) if data[p].ord < _graphql_lexer_trans_keys[_mid] _upper = _mid - 1 elsif data[p].ord > _graphql_lexer_trans_keys[_mid] _lower = _mid + 1 else _trans += (_mid - _keys) _break_match = true break end end # loop break if _break_match _keys += _klen _trans += _klen end _klen = _graphql_lexer_range_lengths[cs] if _klen > 0 _lower = _keys _upper = _keys + (_klen << 1) - 2 loop do break if _upper < _lower _mid = _lower + (((_upper-_lower) >> 1) & ~1) if data[p].ord < _graphql_lexer_trans_keys[_mid] _upper = _mid - 2 elsif data[p].ord > _graphql_lexer_trans_keys[_mid+1] _lower = _mid + 2 else _trans += ((_mid - _keys) >> 1) _break_match = true break end end # loop break if _break_match _trans += _klen end end while false _trans = _graphql_lexer_indicies[_trans] end if _goto_level <= _eof_trans cs = _graphql_lexer_trans_targs[_trans] if _graphql_lexer_trans_actions[_trans] != 0 _acts = _graphql_lexer_trans_actions[_trans] _nacts = _graphql_lexer_actions[_acts] _acts += 1 while _nacts > 0 _nacts -= 1 _acts += 1 case _graphql_lexer_actions[_acts - 1] when 2 then # line 1 "NONE" begin te = p+1 end when 3 then # line 42 "lib/graphql/language/lexer.rl" begin act = 1; end when 4 then # line 43 "lib/graphql/language/lexer.rl" begin act = 2; end when 5 then # line 44 "lib/graphql/language/lexer.rl" begin act = 3; end when 6 then # line 45 "lib/graphql/language/lexer.rl" begin act = 4; end when 7 then # line 46 "lib/graphql/language/lexer.rl" begin act = 5; end when 8 then # line 47 "lib/graphql/language/lexer.rl" begin act = 6; end when 9 then # line 48 "lib/graphql/language/lexer.rl" begin act = 7; end when 10 then # line 49 "lib/graphql/language/lexer.rl" begin act = 8; end when 11 then # line 50 "lib/graphql/language/lexer.rl" begin act = 9; end when 12 then # line 51 "lib/graphql/language/lexer.rl" begin act = 10; end when 13 then # line 59 "lib/graphql/language/lexer.rl" begin act = 18; end when 14 then # line 65 "lib/graphql/language/lexer.rl" begin act = 24; end when 15 then # line 75 "lib/graphql/language/lexer.rl" begin act = 28; end when 16 then # line 52 "lib/graphql/language/lexer.rl" begin te = p+1 begin emit_token.call(:RCURLY) end end when 17 then # line 53 "lib/graphql/language/lexer.rl" begin te = p+1 begin emit_token.call(:LCURLY) end end when 18 then # line 54 "lib/graphql/language/lexer.rl" begin te = p+1 begin emit_token.call(:RPAREN) end end when 19 then # line 55 "lib/graphql/language/lexer.rl" begin te = p+1 begin emit_token.call(:LPAREN) end end when 20 then # line 56 "lib/graphql/language/lexer.rl" begin te = p+1 begin emit_token.call(:RBRACKET) end end when 21 then # line 57 "lib/graphql/language/lexer.rl" begin te = p+1 begin emit_token.call(:LBRACKET) end end when 22 then # line 58 "lib/graphql/language/lexer.rl" begin te = p+1 begin emit_token.call(:COLON) end end when 23 then # line 59 "lib/graphql/language/lexer.rl" begin te = p+1 begin emit_string(ts + 1, te - 1, ) end end when 24 then # line 60 "lib/graphql/language/lexer.rl" begin te = p+1 begin emit_token.call(:VAR_SIGN) end end when 25 then # line 61 "lib/graphql/language/lexer.rl" begin te = p+1 begin emit_token.call(:DIR_SIGN) end end when 26 then # line 62 "lib/graphql/language/lexer.rl" begin te = p+1 begin emit_token.call(:ELLIPSIS) end end when 27 then # line 63 "lib/graphql/language/lexer.rl" begin te = p+1 begin emit_token.call(:EQUALS) end end when 28 then # line 64 "lib/graphql/language/lexer.rl" begin te = p+1 begin emit_token.call(:BANG) end end when 29 then # line 67 "lib/graphql/language/lexer.rl" begin te = p+1 begin [:line] += 1 [:col] = 1 end end when 30 then # line 75 "lib/graphql/language/lexer.rl" begin te = p+1 begin emit_token.call(:UNKNOWN_CHAR) end end when 31 then # line 42 "lib/graphql/language/lexer.rl" begin te = p p = p - 1; begin emit_token.call(:INT) end end when 32 then # line 43 "lib/graphql/language/lexer.rl" begin te = p p = p - 1; begin emit_token.call(:FLOAT) end end when 33 then # line 65 "lib/graphql/language/lexer.rl" begin te = p p = p - 1; begin emit_token.call(:IDENTIFIER) end end when 34 then # line 72 "lib/graphql/language/lexer.rl" begin te = p p = p - 1; begin [:col] += te - ts end end when 35 then # line 73 "lib/graphql/language/lexer.rl" begin te = p p = p - 1; begin [:col] += te - ts end end when 36 then # line 75 "lib/graphql/language/lexer.rl" begin te = p p = p - 1; begin emit_token.call(:UNKNOWN_CHAR) end end when 37 then # line 42 "lib/graphql/language/lexer.rl" begin begin p = ((te))-1; end begin emit_token.call(:INT) end end when 38 then # line 75 "lib/graphql/language/lexer.rl" begin begin p = ((te))-1; end begin emit_token.call(:UNKNOWN_CHAR) end end when 39 then # line 1 "NONE" begin case act when 1 then begin begin p = ((te))-1; end emit_token.call(:INT) end when 2 then begin begin p = ((te))-1; end emit_token.call(:FLOAT) end when 3 then begin begin p = ((te))-1; end emit_token.call(:ON) end when 4 then begin begin p = ((te))-1; end emit_token.call(:FRAGMENT) end when 5 then begin begin p = ((te))-1; end emit_token.call(:TRUE) end when 6 then begin begin p = ((te))-1; end emit_token.call(:FALSE) end when 7 then begin begin p = ((te))-1; end emit_token.call(:NULL) end when 8 then begin begin p = ((te))-1; end emit_token.call(:QUERY) end when 9 then begin begin p = ((te))-1; end emit_token.call(:MUTATION) end when 10 then begin begin p = ((te))-1; end emit_token.call(:SUBSCRIPTION) end when 18 then begin begin p = ((te))-1; end emit_string(ts + 1, te - 1, ) end when 24 then begin begin p = ((te))-1; end emit_token.call(:IDENTIFIER) end when 28 then begin begin p = ((te))-1; end emit_token.call(:UNKNOWN_CHAR) end end end # line 677 "lib/graphql/language/lexer.rb" end # action switch end end if _trigger_goto next end end if _goto_level <= _again _acts = _graphql_lexer_to_state_actions[cs] _nacts = _graphql_lexer_actions[_acts] _acts += 1 while _nacts > 0 _nacts -= 1 _acts += 1 case _graphql_lexer_actions[_acts - 1] when 0 then # line 1 "NONE" begin ts = nil; end # line 697 "lib/graphql/language/lexer.rb" end # to state action switch end if _trigger_goto next end p += 1 if p != pe _goto_level = _resume next end end if _goto_level <= _test_eof if p == eof if _graphql_lexer_eof_trans[cs] > 0 _trans = _graphql_lexer_eof_trans[cs] - 1; _goto_level = _eof_trans next; end end end if _goto_level <= _out break end end end # line 118 "lib/graphql/language/lexer.rl" [:tokens] end |
.tokenize(query_string) ⇒ Object
11 12 13 |
# File 'lib/graphql/language/lexer.rb', line 11 def self.tokenize(query_string) run_lexer(query_string) end |