comparison src/vim9compile.c @ 20023:c85d4e173cc9 v8.2.0567

patch 8.2.0567: Vim9: cannot put comments halfway expressions Commit: https://github.com/vim/vim/commit/2c330432cfb12181c61d698b5459bfd73d2610df Author: Bram Moolenaar <Bram@vim.org> Date: Mon Apr 13 14:41:35 2020 +0200 patch 8.2.0567: Vim9: cannot put comments halfway expressions Problem: Vim9: cannot put comments halfway expressions. Solution: Support # comments in many places.
author Bram Moolenaar <Bram@vim.org>
date Mon, 13 Apr 2020 14:45:04 +0200
parents e9af5a09a55b
children 04ef2ccf2519
comparison
equal deleted inserted replaced
20022:fb9a66d81a39 20023:c85d4e173cc9
2068 } while (line == NULL || *skipwhite(line) == NUL); 2068 } while (line == NULL || *skipwhite(line) == NUL);
2069 return line; 2069 return line;
2070 } 2070 }
2071 2071
2072 /* 2072 /*
2073 * Return TRUE if "p" points at a "#" but not at "#{".
2074 */
2075 static int
2076 comment_start(char_u *p)
2077 {
2078 return p[0] == '#' && p[1] != '{';
2079 }
2080
2081 /*
2073 * If "*arg" is at the end of the line, advance to the next line. 2082 * If "*arg" is at the end of the line, advance to the next line.
2083 * Also when "whitep" points to white space and "*arg" is on a "#".
2074 * Return FAIL if beyond the last line, "*arg" is unmodified then. 2084 * Return FAIL if beyond the last line, "*arg" is unmodified then.
2075 */ 2085 */
2076 static int 2086 static int
2077 may_get_next_line(char_u **arg, cctx_T *cctx) 2087 may_get_next_line(char_u *whitep, char_u **arg, cctx_T *cctx)
2078 { 2088 {
2079 if (**arg == NUL) 2089 if (**arg == NUL || (VIM_ISWHITE(*whitep) && comment_start(*arg)))
2080 { 2090 {
2081 char_u *next = next_line_from_context(cctx); 2091 char_u *next = next_line_from_context(cctx);
2082 2092
2083 if (next == NULL) 2093 if (next == NULL)
2084 return FAIL; 2094 return FAIL;
2319 * "arg" points to just after the "(" and is advanced to after the ")" 2329 * "arg" points to just after the "(" and is advanced to after the ")"
2320 */ 2330 */
2321 static int 2331 static int
2322 compile_arguments(char_u **arg, cctx_T *cctx, int *argcount) 2332 compile_arguments(char_u **arg, cctx_T *cctx, int *argcount)
2323 { 2333 {
2324 char_u *p = *arg; 2334 char_u *p = *arg;
2335 char_u *whitep = *arg;
2325 2336
2326 for (;;) 2337 for (;;)
2327 { 2338 {
2328 if (*p == NUL) 2339 while (*p == NUL || (VIM_ISWHITE(*whitep) && comment_start(p)))
2329 { 2340 {
2330 p = next_line_from_context(cctx); 2341 p = next_line_from_context(cctx);
2331 if (p == NULL) 2342 if (p == NULL)
2332 break; 2343 goto failret;
2344 whitep = (char_u *)" ";
2333 p = skipwhite(p); 2345 p = skipwhite(p);
2334 } 2346 }
2335 if (*p == ')') 2347 if (*p == ')')
2336 { 2348 {
2337 *arg = p + 1; 2349 *arg = p + 1;
2351 { 2363 {
2352 ++p; 2364 ++p;
2353 if (*p != NUL && !VIM_ISWHITE(*p)) 2365 if (*p != NUL && !VIM_ISWHITE(*p))
2354 semsg(_(e_white_after), ","); 2366 semsg(_(e_white_after), ",");
2355 } 2367 }
2368 whitep = p;
2356 p = skipwhite(p); 2369 p = skipwhite(p);
2357 } 2370 }
2358 2371 failret:
2359 emsg(_(e_missing_close)); 2372 emsg(_(e_missing_close));
2360 return FAIL; 2373 return FAIL;
2361 } 2374 }
2362 2375
2363 /* 2376 /*
2587 */ 2600 */
2588 static int 2601 static int
2589 compile_list(char_u **arg, cctx_T *cctx) 2602 compile_list(char_u **arg, cctx_T *cctx)
2590 { 2603 {
2591 char_u *p = skipwhite(*arg + 1); 2604 char_u *p = skipwhite(*arg + 1);
2605 char_u *whitep = *arg + 1;
2592 int count = 0; 2606 int count = 0;
2593 2607
2594 for (;;) 2608 for (;;)
2595 { 2609 {
2596 if (*p == NUL) 2610 while (*p == NUL || (VIM_ISWHITE(*whitep) && comment_start(p)))
2597 { 2611 {
2598 p = next_line_from_context(cctx); 2612 p = next_line_from_context(cctx);
2599 if (p == NULL) 2613 if (p == NULL)
2600 { 2614 {
2601 semsg(_(e_list_end), *arg); 2615 semsg(_(e_list_end), *arg);
2602 return FAIL; 2616 return FAIL;
2603 } 2617 }
2618 whitep = (char_u *)" ";
2604 p = skipwhite(p); 2619 p = skipwhite(p);
2605 } 2620 }
2606 if (*p == ']') 2621 if (*p == ']')
2607 { 2622 {
2608 ++p; 2623 ++p;
2614 if (compile_expr1(&p, cctx) == FAIL) 2629 if (compile_expr1(&p, cctx) == FAIL)
2615 break; 2630 break;
2616 ++count; 2631 ++count;
2617 if (*p == ',') 2632 if (*p == ',')
2618 ++p; 2633 ++p;
2634 whitep = p;
2619 p = skipwhite(p); 2635 p = skipwhite(p);
2620 } 2636 }
2621 *arg = p; 2637 *arg = p;
2622 2638
2623 generate_NEWLIST(cctx, count); 2639 generate_NEWLIST(cctx, count);
2711 { 2727 {
2712 garray_T *instr = &cctx->ctx_instr; 2728 garray_T *instr = &cctx->ctx_instr;
2713 int count = 0; 2729 int count = 0;
2714 dict_T *d = dict_alloc(); 2730 dict_T *d = dict_alloc();
2715 dictitem_T *item; 2731 dictitem_T *item;
2732 char_u *whitep = *arg;
2733 char_u *p;
2716 2734
2717 if (d == NULL) 2735 if (d == NULL)
2718 return FAIL; 2736 return FAIL;
2719 *arg = skipwhite(*arg + 1); 2737 *arg = skipwhite(*arg + 1);
2720 for (;;) 2738 for (;;)
2721 { 2739 {
2722 char_u *key = NULL; 2740 char_u *key = NULL;
2723 2741
2724 if (**arg == NUL || (literal && **arg == '"')) 2742 while (**arg == NUL || (literal && **arg == '"')
2743 || (VIM_ISWHITE(*whitep) && comment_start(*arg)))
2725 { 2744 {
2726 *arg = next_line_from_context(cctx); 2745 *arg = next_line_from_context(cctx);
2727 if (*arg == NULL) 2746 if (*arg == NULL)
2728 goto failret; 2747 goto failret;
2748 whitep = (char_u *)" ";
2729 *arg = skipwhite(*arg); 2749 *arg = skipwhite(*arg);
2730 } 2750 }
2731 2751
2732 if (**arg == '}') 2752 if (**arg == '}')
2733 break; 2753 break;
2734 2754
2735 if (literal) 2755 if (literal)
2736 { 2756 {
2737 char_u *p = to_name_end(*arg, !literal); 2757 char_u *end = to_name_end(*arg, !literal);
2738 2758
2739 if (p == *arg) 2759 if (end == *arg)
2740 { 2760 {
2741 semsg(_("E1014: Invalid key: %s"), *arg); 2761 semsg(_("E1014: Invalid key: %s"), *arg);
2742 return FAIL; 2762 return FAIL;
2743 } 2763 }
2744 key = vim_strnsave(*arg, p - *arg); 2764 key = vim_strnsave(*arg, end - *arg);
2745 if (generate_PUSHS(cctx, key) == FAIL) 2765 if (generate_PUSHS(cctx, key) == FAIL)
2746 return FAIL; 2766 return FAIL;
2747 *arg = p; 2767 *arg = end;
2748 } 2768 }
2749 else 2769 else
2750 { 2770 {
2751 isn_T *isn; 2771 isn_T *isn;
2752 2772
2782 { 2802 {
2783 semsg(_(e_missing_dict_colon), *arg); 2803 semsg(_(e_missing_dict_colon), *arg);
2784 return FAIL; 2804 return FAIL;
2785 } 2805 }
2786 2806
2807 whitep = *arg + 1;
2787 *arg = skipwhite(*arg + 1); 2808 *arg = skipwhite(*arg + 1);
2788 if (**arg == NUL) 2809 while (**arg == NUL || (VIM_ISWHITE(*whitep) && comment_start(*arg)))
2789 { 2810 {
2790 *arg = next_line_from_context(cctx); 2811 *arg = next_line_from_context(cctx);
2791 if (*arg == NULL) 2812 if (*arg == NULL)
2792 goto failret; 2813 goto failret;
2814 whitep = (char_u *)" ";
2793 *arg = skipwhite(*arg); 2815 *arg = skipwhite(*arg);
2794 } 2816 }
2795 2817
2796 if (compile_expr1(arg, cctx) == FAIL) 2818 if (compile_expr1(arg, cctx) == FAIL)
2797 return FAIL; 2819 return FAIL;
2798 ++count; 2820 ++count;
2799 2821
2800 if (**arg == NUL || *skipwhite(*arg) == '"') 2822 whitep = *arg;
2823 p = skipwhite(*arg);
2824 while (*p == NUL || (VIM_ISWHITE(*whitep) && comment_start(p)))
2801 { 2825 {
2802 *arg = next_line_from_context(cctx); 2826 *arg = next_line_from_context(cctx);
2803 if (*arg == NULL) 2827 if (*arg == NULL)
2804 goto failret; 2828 goto failret;
2829 whitep = (char_u *)" ";
2805 *arg = skipwhite(*arg); 2830 *arg = skipwhite(*arg);
2831 p = *arg;
2806 } 2832 }
2807 if (**arg == '}') 2833 if (**arg == '}')
2808 break; 2834 break;
2809 if (**arg != ',') 2835 if (**arg != ',')
2810 { 2836 {
2811 semsg(_(e_missing_dict_comma), *arg); 2837 semsg(_(e_missing_dict_comma), *arg);
2812 goto failret; 2838 goto failret;
2813 } 2839 }
2840 whitep = *arg + 1;
2814 *arg = skipwhite(*arg + 1); 2841 *arg = skipwhite(*arg + 1);
2815 } 2842 }
2816 2843
2817 *arg = *arg + 1; 2844 *arg = *arg + 1;
2818 2845
2819 // Allow for following comment, after at least one space. 2846 // Allow for following comment, after at least one space.
2820 if (VIM_ISWHITE(**arg) && *skipwhite(*arg) == '"') 2847 p = skipwhite(*arg);
2848 if (VIM_ISWHITE(**arg) && (*p == '"' || comment_start(p)))
2821 *arg += STRLEN(*arg); 2849 *arg += STRLEN(*arg);
2822 2850
2823 dict_unref(d); 2851 dict_unref(d);
2824 return generate_NEWDICT(cctx, count); 2852 return generate_NEWDICT(cctx, count);
2825 2853
3420 vim_strncpy(buf, op, 1); 3448 vim_strncpy(buf, op, 1);
3421 semsg(_(e_white_both), buf); 3449 semsg(_(e_white_both), buf);
3422 return FAIL; 3450 return FAIL;
3423 } 3451 }
3424 *arg = skipwhite(op + 1); 3452 *arg = skipwhite(op + 1);
3425 if (may_get_next_line(arg, cctx) == FAIL) 3453 if (may_get_next_line(op + 1, arg, cctx) == FAIL)
3426 return FAIL; 3454 return FAIL;
3427 3455
3428 // get the second variable 3456 // get the second variable
3429 if (compile_expr7(arg, cctx) == FAIL) 3457 if (compile_expr7(arg, cctx) == FAIL)
3430 return FAIL; 3458 return FAIL;
3468 semsg(_(e_white_both), buf); 3496 semsg(_(e_white_both), buf);
3469 return FAIL; 3497 return FAIL;
3470 } 3498 }
3471 3499
3472 *arg = skipwhite(op + oplen); 3500 *arg = skipwhite(op + oplen);
3473 if (may_get_next_line(arg, cctx) == FAIL) 3501 if (may_get_next_line(op + oplen, arg, cctx) == FAIL)
3474 return FAIL; 3502 return FAIL;
3475 3503
3476 // get the second variable 3504 // get the second variable
3477 if (compile_expr6(arg, cctx) == FAIL) 3505 if (compile_expr6(arg, cctx) == FAIL)
3478 return FAIL; 3506 return FAIL;
3606 return FAIL; 3634 return FAIL;
3607 } 3635 }
3608 3636
3609 // get the second variable 3637 // get the second variable
3610 *arg = skipwhite(p + len); 3638 *arg = skipwhite(p + len);
3611 if (may_get_next_line(arg, cctx) == FAIL) 3639 if (may_get_next_line(p + len, arg, cctx) == FAIL)
3612 return FAIL; 3640 return FAIL;
3613 3641
3614 if (compile_expr5(arg, cctx) == FAIL) 3642 if (compile_expr5(arg, cctx) == FAIL)
3615 return FAIL; 3643 return FAIL;
3616 3644
3656 generate_JUMP(cctx, opchar == '|' 3684 generate_JUMP(cctx, opchar == '|'
3657 ? JUMP_AND_KEEP_IF_TRUE : JUMP_AND_KEEP_IF_FALSE, 0); 3685 ? JUMP_AND_KEEP_IF_TRUE : JUMP_AND_KEEP_IF_FALSE, 0);
3658 3686
3659 // eval the next expression 3687 // eval the next expression
3660 *arg = skipwhite(p + 2); 3688 *arg = skipwhite(p + 2);
3661 if (may_get_next_line(arg, cctx) == FAIL) 3689 if (may_get_next_line(p + 2, arg, cctx) == FAIL)
3662 return FAIL; 3690 return FAIL;
3663 3691
3664 if ((opchar == '|' ? compile_expr3(arg, cctx) 3692 if ((opchar == '|' ? compile_expr3(arg, cctx)
3665 : compile_expr4(arg, cctx)) == FAIL) 3693 : compile_expr4(arg, cctx)) == FAIL)
3666 { 3694 {
3769 3797
3770 generate_JUMP(cctx, JUMP_IF_FALSE, 0); 3798 generate_JUMP(cctx, JUMP_IF_FALSE, 0);
3771 3799
3772 // evaluate the second expression; any type is accepted 3800 // evaluate the second expression; any type is accepted
3773 *arg = skipwhite(p + 1); 3801 *arg = skipwhite(p + 1);
3774 if (may_get_next_line(arg, cctx) == FAIL) 3802 if (may_get_next_line(p + 1, arg, cctx) == FAIL)
3775 return FAIL; 3803 return FAIL;
3776 3804
3777 if (compile_expr1(arg, cctx) == FAIL) 3805 if (compile_expr1(arg, cctx) == FAIL)
3778 return FAIL; 3806 return FAIL;
3779 3807
3801 return FAIL; 3829 return FAIL;
3802 } 3830 }
3803 3831
3804 // evaluate the third expression 3832 // evaluate the third expression
3805 *arg = skipwhite(p + 1); 3833 *arg = skipwhite(p + 1);
3806 if (may_get_next_line(arg, cctx) == FAIL) 3834 if (may_get_next_line(p + 1, arg, cctx) == FAIL)
3807 return FAIL; 3835 return FAIL;
3808 3836
3809 if (compile_expr1(arg, cctx) == FAIL) 3837 if (compile_expr1(arg, cctx) == FAIL)
3810 return FAIL; 3838 return FAIL;
3811 3839