(int firstNode, int lastNode, int idxStart)
| 763 | /// |
| 764 | /// Final input array index if match succeeded. -1 if not. |
| 765 | @SuppressWarnings("PMD.SwitchStmtsShouldHaveDefault") |
| 766 | protected int matchNodes(int firstNode, int lastNode, int idxStart) { |
| 767 | // Our current place in the string |
| 768 | int idx = idxStart; |
| 769 | |
| 770 | // Loop while node is valid |
| 771 | int next; |
| 772 | int opcode; |
| 773 | int opdata; |
| 774 | int idxNew; |
| 775 | char[] instruction = program.instruction; |
| 776 | for (int node = firstNode; node < lastNode; ) { |
| 777 | opcode = instruction[node /* + offsetOpcode */]; |
| 778 | next = node + (short) instruction[node + offsetNext]; |
| 779 | opdata = instruction[node + offsetOpdata]; |
| 780 | |
| 781 | switch (opcode) { |
| 782 | case OP_MAYBE: |
| 783 | case OP_STAR: { |
| 784 | // Try to match the following subexpr. If it matches: |
| 785 | // MAYBE: Continues matching rest of the expression |
| 786 | // STAR: Points back here to repeat subexpr matching |
| 787 | if ((idxNew = matchNodes(node + nodeSize, maxNode, idx)) != -1) { //NOPMD AssignmentInOperand |
| 788 | return idxNew; |
| 789 | } |
| 790 | |
| 791 | // If failed, just continue with the rest of expression |
| 792 | break; |
| 793 | } |
| 794 | |
| 795 | case OP_PLUS: { |
| 796 | // Try to match the subexpr again (and again (and ... |
| 797 | if ((idxNew = matchNodes(next, maxNode, idx)) != -1) { //NOPMD AssignmentInOperand |
| 798 | return idxNew; |
| 799 | } |
| 800 | |
| 801 | // If failed, just continue with the rest of expression |
| 802 | // Rest is located at the next pointer of the next instruction |
| 803 | // (which must be OP_CONTINUE) |
| 804 | node = next + (short) instruction[next + offsetNext]; |
| 805 | continue; |
| 806 | } |
| 807 | |
| 808 | case OP_RELUCTANTMAYBE: |
| 809 | case OP_RELUCTANTSTAR: { |
| 810 | // Try to match the rest without using the reluctant subexpr |
| 811 | if ((idxNew = matchNodes(next, maxNode, idx)) != -1) { //NOPMD AssignmentInOperand |
| 812 | return idxNew; |
| 813 | } |
| 814 | |
| 815 | // Try reluctant subexpr. If it matches: |
| 816 | // RELUCTANTMAYBE: Continues matching rest of the expression |
| 817 | // RELUCTANTSTAR: Points back here to repeat reluctant star matching |
| 818 | return matchNodes(node + nodeSize, next, idx); |
| 819 | } |
| 820 | |
| 821 | case OP_RELUCTANTPLUS: { |
| 822 | // Continue matching the rest without using the reluctant subexpr |
no test coverage detected