| 1791 | } |
| 1792 | |
| 1793 | static struct splice_script_error *make_segments(const tal_t *ctx, |
| 1794 | struct token ***tokens_inout) |
| 1795 | { |
| 1796 | struct token **input = *tokens_inout; |
| 1797 | struct token **tokens = tal_arr(ctx, struct token *, tal_count(input)); |
| 1798 | size_t n = 0; |
| 1799 | size_t next_consumable = 0; |
| 1800 | |
| 1801 | for (size_t i = 0; i < tal_count(input); i++) { |
| 1802 | switch(input[i]->type) { |
| 1803 | case TOK_CHAR: |
| 1804 | case TOK_ATSYM: |
| 1805 | case TOK_PLUS: |
| 1806 | case TOK_MINUS: |
| 1807 | case TOK_FEE: |
| 1808 | case TOK_COLON: |
| 1809 | case TOK_LEASERATE: |
| 1810 | case TOK_STR: |
| 1811 | case TOK_CHANQUERY: |
| 1812 | return new_error(ctx, INVALID_TOKEN, input[i], |
| 1813 | "segments"); |
| 1814 | case TOK_ARROW: |
| 1815 | case TOK_PIPE: |
| 1816 | case TOK_SATS: |
| 1817 | case TOK_PERCENT: |
| 1818 | case TOK_QUESTION: |
| 1819 | case TOK_WILDCARD: |
| 1820 | case TOK_CHANID: |
| 1821 | case TOK_WALLET: |
| 1822 | case TOK_FEERATE: |
| 1823 | case TOK_NODEID: |
| 1824 | case TOK_BTCADDR: |
| 1825 | case TOK_MULTI_CHANID: |
| 1826 | case TOK_LEASEREQ: |
| 1827 | break; |
| 1828 | case TOK_DELIMITER: |
| 1829 | if (i == 0 || input[i-1]->type == TOK_SEGMENT |
| 1830 | || input[i-1]->type == TOK_DELIMITER) { |
| 1831 | next_consumable = i+1; |
| 1832 | break; |
| 1833 | } |
| 1834 | if (i - next_consumable == 3) { |
| 1835 | if (input[next_consumable+1]->type != TOK_ARROW) |
| 1836 | return new_error(ctx, MISSING_ARROW, |
| 1837 | input[next_consumable+1], |
| 1838 | "segments"); |
| 1839 | input[i]->type = TOK_SEGMENT; |
| 1840 | input[i]->left = tal_steal(input[i], |
| 1841 | input[next_consumable]); |
| 1842 | input[i]->middle = tal_steal(input[i], |
| 1843 | input[next_consumable+2]); |
| 1844 | tokens[n++] = tal_steal(tokens, input[i]); |
| 1845 | next_consumable = i+1; |
| 1846 | } |
| 1847 | else if (i - next_consumable == 5) { |
| 1848 | if (input[next_consumable+1]->type != TOK_ARROW) |
| 1849 | return new_error(ctx, MISSING_ARROW, |
| 1850 | input[next_consumable+1], |
no test coverage detected