| 1278 | } |
| 1279 | |
| 1280 | static struct splice_script_error *compress_top_operands(const tal_t *ctx, |
| 1281 | struct token ***tokens_inout) |
| 1282 | { |
| 1283 | struct token **input = *tokens_inout; |
| 1284 | struct token **tokens = tal_arr(ctx, struct token *, tal_count(input)); |
| 1285 | size_t n = 0; |
| 1286 | |
| 1287 | for (size_t i = 0; i < tal_count(input); i++) { |
| 1288 | switch(input[i]->type) { |
| 1289 | case TOK_CHAR: |
| 1290 | return new_error(ctx, INVALID_TOKEN, input[i], |
| 1291 | "operands"); |
| 1292 | case TOK_DELIMITER: |
| 1293 | case TOK_ARROW: |
| 1294 | case TOK_PIPE: |
| 1295 | case TOK_STR: |
| 1296 | case TOK_SATS: |
| 1297 | case TOK_PERCENT: |
| 1298 | case TOK_QUESTION: |
| 1299 | case TOK_WILDCARD: |
| 1300 | case TOK_PLUS: |
| 1301 | case TOK_MINUS: |
| 1302 | case TOK_FEE: |
| 1303 | case TOK_CHANID: |
| 1304 | case TOK_WALLET: |
| 1305 | case TOK_NODEID: |
| 1306 | case TOK_BTCADDR: |
| 1307 | tokens[n++] = tal_steal(tokens, input[i]); |
| 1308 | break; |
| 1309 | case TOK_ATSYM: |
| 1310 | if (!n || i + 1 >= tal_count(input)) |
| 1311 | return new_error(ctx, INVALID_TOKEN, input[i], |
| 1312 | "operands"); |
| 1313 | input[i]->type = tokens[n-1]->type == TOK_FEE |
| 1314 | ? TOK_FEERATE |
| 1315 | : TOK_LEASERATE; |
| 1316 | input[i]->right = tal_steal(input[i], input[i+1]); |
| 1317 | tokens[n-1]->right = tal_steal(tokens[n-1], input[i]); |
| 1318 | i++; |
| 1319 | break; |
| 1320 | case TOK_COLON: |
| 1321 | if (!n || i + 1 >= tal_count(input)) |
| 1322 | return new_error(ctx, INVALID_TOKEN, input[i], |
| 1323 | "operands"); |
| 1324 | input[i]->type = TOK_CHANQUERY; |
| 1325 | input[i]->left = tal_steal(input[i], tokens[n-1]); |
| 1326 | input[i]->right = tal_steal(input[i], input[i+1]); |
| 1327 | tokens[n-1] = tal_steal(tokens, input[i]); |
| 1328 | i++; |
| 1329 | break; |
| 1330 | case TOK_CHANQUERY: |
| 1331 | case TOK_MULTI_CHANID: |
| 1332 | case TOK_FEERATE: |
| 1333 | case TOK_LEASERATE: |
| 1334 | case TOK_LEASEREQ: |
| 1335 | case TOK_SEGMENT: |
| 1336 | return new_error(ctx, INVALID_TOKEN, input[i], |
| 1337 | "operands"); |
no test coverage detected