Mercurial > vim
comparison src/userfunc.c @ 34773:af48c532bd88 v9.1.0263
patch 9.1.0263: Vim9: Problem with lambda blocks in enums and classes
Commit: https://github.com/vim/vim/commit/3fa8f7728a47822e4efd106ab30c83c28f198b3c
Author: Yegappan Lakshmanan <yegappan@yahoo.com>
Date: Thu Apr 4 21:42:07 2024 +0200
patch 9.1.0263: Vim9: Problem with lambda blocks in enums and classes
Problem: Vim9: Problem with lambda blocks in enums and classes
(Aliaksei Budavei)
Solution: Support evaluating lambda blocks from a string, skip over
comments (Yegappan Lakshmanan)
fixes: #14350
closes: #14405
Signed-off-by: Yegappan Lakshmanan <yegappan@yahoo.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Thu, 04 Apr 2024 22:00:04 +0200 |
parents | d4fb6ea26ae4 |
children | 6d03fa3a05ad |
comparison
equal
deleted
inserted
replaced
34772:cd738b9a790a | 34773:af48c532bd88 |
---|---|
1333 int ret = FAIL; | 1333 int ret = FAIL; |
1334 partial_T *pt; | 1334 partial_T *pt; |
1335 char_u *name; | 1335 char_u *name; |
1336 int lnum_save = -1; | 1336 int lnum_save = -1; |
1337 linenr_T sourcing_lnum_top = SOURCING_LNUM; | 1337 linenr_T sourcing_lnum_top = SOURCING_LNUM; |
1338 char_u *line_arg = NULL; | |
1338 | 1339 |
1339 *arg = skipwhite(*arg + 1); | 1340 *arg = skipwhite(*arg + 1); |
1340 if (**arg == '|' || !ends_excmd2(start, *arg)) | 1341 if (**arg == '|' || !ends_excmd2(start, *arg)) |
1341 { | 1342 { |
1342 semsg(_(e_trailing_characters_str), *arg); | 1343 semsg(_(e_trailing_characters_str), *arg); |
1343 return FAIL; | 1344 return FAIL; |
1344 } | 1345 } |
1346 | |
1347 // When there is a line break use what follows for the lambda body. | |
1348 // Makes lambda body initializers work for object and enum member | |
1349 // variables. | |
1350 if (**arg == '\n') | |
1351 line_arg = *arg + 1; | |
1345 | 1352 |
1346 CLEAR_FIELD(eap); | 1353 CLEAR_FIELD(eap); |
1347 eap.cmdidx = CMD_block; | 1354 eap.cmdidx = CMD_block; |
1348 eap.forceit = FALSE; | 1355 eap.forceit = FALSE; |
1349 eap.cmdlinep = &cmdline; | 1356 eap.cmdlinep = &cmdline; |
1355 eap.ea_getline = evalarg->eval_getline; | 1362 eap.ea_getline = evalarg->eval_getline; |
1356 eap.cookie = evalarg->eval_cookie; | 1363 eap.cookie = evalarg->eval_cookie; |
1357 } | 1364 } |
1358 | 1365 |
1359 ga_init2(&newlines, sizeof(char_u *), 10); | 1366 ga_init2(&newlines, sizeof(char_u *), 10); |
1360 if (get_function_body(&eap, &newlines, NULL, | 1367 if (get_function_body(&eap, &newlines, line_arg, |
1361 &evalarg->eval_tofree_ga) == FAIL) | 1368 &evalarg->eval_tofree_ga) == FAIL) |
1362 goto erret; | 1369 goto erret; |
1363 | 1370 |
1364 // When inside a lambda must add the function lines to evalarg.eval_ga. | 1371 // When inside a lambda must add the function lines to evalarg.eval_ga. |
1365 evalarg->eval_break_count += newlines.ga_len; | 1372 evalarg->eval_break_count += newlines.ga_len; |
1370 size_t plen; | 1377 size_t plen; |
1371 char_u *pnl; | 1378 char_u *pnl; |
1372 | 1379 |
1373 for (idx = 0; idx < newlines.ga_len; ++idx) | 1380 for (idx = 0; idx < newlines.ga_len; ++idx) |
1374 { | 1381 { |
1375 char_u *p = skipwhite(((char_u **)newlines.ga_data)[idx]); | 1382 char_u *p = ((char_u **)newlines.ga_data)[idx]; |
1383 if (p == NULL) | |
1384 // comment line in the lambda body | |
1385 continue; | |
1386 | |
1387 p = skipwhite(p); | |
1376 | 1388 |
1377 if (ga_grow(gap, 1) == FAIL || ga_grow(freegap, 1) == FAIL) | 1389 if (ga_grow(gap, 1) == FAIL || ga_grow(freegap, 1) == FAIL) |
1378 goto erret; | 1390 goto erret; |
1379 | 1391 |
1380 // Going to concatenate the lines after parsing. For an empty or | 1392 // Going to concatenate the lines after parsing. For an empty or |