robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
757800bc64
master
1#include <assert.h> 2#include <stdbool.h> 3#include <stddef.h> 4#include <stdint.h> 5#include <stdlib.h> 6#include <string.h> 7 8#include "klib/kvec.h" 9#include "nvim/api/keysets_defs.h" 10#include "nvim/api/private/converter.h" 11#include "nvim/api/private/defs.h" 12#include "nvim/api/private/helpers.h" 13#include "nvim/api/private/validate.h" 14#include "nvim/api/vimscript.h" 15#include "nvim/ascii_defs.h" 16#include "nvim/buffer_defs.h" 17#include "nvim/eval.h" 18#include "nvim/eval/typval.h" 19#include "nvim/eval/typval_defs.h" 20#include "nvim/eval/userfunc.h" 21#include "nvim/ex_docmd.h" 22#include "nvim/garray.h" 23#include "nvim/garray_defs.h" 24#include "nvim/globals.h" 25#include "nvim/memory.h" 26#include "nvim/memory_defs.h" 27#include "nvim/runtime.h" 28#include "nvim/vim_defs.h" 29#include "nvim/viml/parser/expressions.h" 30#include "nvim/viml/parser/parser.h" 31#include "nvim/viml/parser/parser_defs.h" 32 33#include "api/vimscript.c.generated.h" 34 35/// Executes Vimscript (multiline block of Ex commands), like anonymous 36/// |:source|. 37/// 38/// Unlike |nvim_command()| this function supports heredocs, script-scope (s:), 39/// etc. 40/// 41/// On execution error: fails with Vimscript error, updates v:errmsg. 42/// 43/// @see |execute()| 44/// @see |nvim_command()| 45/// @see |nvim_cmd()| 46/// 47/// @param src Vimscript code 48/// @param opts Optional parameters. 49/// - output: (boolean, default false) Whether to capture and return 50/// all (non-error, non-shell |:!|) output. 51/// @param[out] err Error details (Vim error), if any 52/// @return Dict containing information about execution, with these keys: 53/// - output: (string|nil) Output if `opts.output` is true. 54Dict nvim_exec2 (uint64_t channel_id ,String src ,Dict (exec_opts )* opts ,Error * err ) 55FUNC_API_SINCE (11 )FUNC_API_RET_ALLOC 56{ 57Dict result = ARRAY_DICT_INIT ; 58 59String output = exec_impl (channel_id ,src ,opts ,err ); 60if (ERROR_SET (err )) { 61return result ; 62 } 63 64if (opts -> output ) { 65PUT (result ,"output" ,STRING_OBJ (output )); 66 } 67 68return result ; 69} 70 71String exec_impl (uint64_t channel_id ,String src ,Dict (exec_opts )* opts ,Error * err ) 72{ 73const int save_msg_silent = msg_silent ; 74const bool save_redir_off = redir_off ; 75garray_T * const save_capture_ga = capture_ga ; 76const int save_msg_col = msg_col ; 77garray_T capture_local ; 78if (opts -> output ) { 79ga_init (& capture_local ,1 ,80 ); 80capture_ga = & capture_local ; 81 } 82 83TRY_WRAP (err , { 84if (opts -> output ) { 85msg_silent ++ ; 86redir_off = false; 87msg_col = 0 ;// prevent leading spaces 88 } 89 90const sctx_T save_current_sctx = api_set_sctx (channel_id ); 91 92do_source_str (src .data ,"nvim_exec2()" ); 93if (opts -> output ) { 94capture_ga = save_capture_ga ; 95msg_silent = save_msg_silent ; 96redir_off = save_redir_off ; 97// Put msg_col back where it was, since nothing should have been written. 98msg_col = save_msg_col ; 99 } 100 101current_sctx = save_current_sctx ; 102 }); 103 104if (ERROR_SET (err )) { 105 gototheend ; 106 } 107 108if (opts -> output && capture_local .ga_len > 1 ) { 109String s = (String ){ 110 .data = capture_local .ga_data , 111 .size = (size_t )capture_local .ga_len , 112 }; 113// redir usually (except :echon) prepends a newline. 114if (s .data [0 ]== '\n' ) { 115memmove (s .data ,s .data + 1 ,s .size - 1 ); 116s .data [s .size - 1 ]= NUL ; 117s .size = s .size - 1 ; 118 } 119return s ;// Caller will free the memory. 120 } 121theend : 122if (opts -> output ) { 123ga_clear (& capture_local ); 124 } 125return (String )STRING_INIT ; 126} 127 128/// Executes an Ex command. 129/// 130/// On execution error: fails with Vimscript error, updates v:errmsg. 131/// 132/// Prefer |nvim_cmd()| or |nvim_exec2()| instead. To modify an Ex command in a structured way 133/// before executing it, modify the result of |nvim_parse_cmd()| then pass it to |nvim_cmd()|. 134/// 135/// @param cmd Ex command string 136/// @param[out] err Error details (Vim error), if any 137void nvim_command (String cmd ,Error * err ) 138FUNC_API_SINCE (1 ) 139{ 140TRY_WRAP (err , { 141do_cmdline_cmd (cmd .data ); 142 }); 143} 144 145/// Evaluates a Vimscript |expression|. Dicts and Lists are recursively expanded. 146/// 147/// On execution error: fails with Vimscript error, updates v:errmsg. 148/// 149/// @param expr Vimscript expression string 150/// @param[out] err Error details, if any 151/// @return Evaluation result or expanded object 152Object nvim_eval (String expr ,Arena * arena ,Error * err ) 153FUNC_API_SINCE (1 ) 154{ 155static int recursive = 0 ;// recursion depth 156Object rv = OBJECT_INIT ; 157 158// Initialize `force_abort` and `suppress_errthrow` at the top level. 159if (!recursive ) { 160force_abort = false; 161suppress_errthrow = false; 162did_throw = false; 163// `did_emsg` is set by emsg(), which cancels execution. 164did_emsg = false; 165 } 166 167recursive ++ ; 168 169typval_T rettv ; 170int ok ; 171 172TRY_WRAP (err , { 173ok = eval0 (expr .data ,& rettv ,NULL ,& EVALARG_EVALUATE ); 174clear_evalarg (& EVALARG_EVALUATE ,NULL ); 175 }); 176 177if (!ERROR_SET (err )) { 178if (ok == FAIL ) { 179// Should never happen, try_end() (in TRY_WRAP) should get the error. #8371 180api_set_error (err ,kErrorTypeException , 181"Failed to evaluate expression: '%.*s'" ,256 ,expr .data ); 182 }else { 183rv = vim_to_object (& rettv ,arena , false); 184 } 185 } 186 187tv_clear (& rettv ); 188recursive -- ; 189 190return rv ; 191} 192 193/// Calls a Vimscript function. 194/// 195/// @param fn Function name 196/// @param args Function arguments 197/// @param self `self` dict, or NULL for non-dict functions 198/// @param[out] err Error details, if any 199/// @return Result of the function call 200static Object _call_function (uint64_t channel_id ,String fn ,Array args ,dict_T * self ,Arena * arena , 201Error * err ) 202{ 203static int recursive = 0 ;// recursion depth 204Object rv = OBJECT_INIT ; 205 206if (args .size > MAX_FUNC_ARGS ) { 207api_set_error (err ,kErrorTypeValidation , 208"Function called with too many arguments" ); 209return rv ; 210 } 211 212// Convert the arguments in args from Object to typval_T values 213typval_T vim_args [MAX_FUNC_ARGS + 1 ]; 214size_t i = 0 ;// also used for freeing the variables 215for (;i < args .size ;i ++ ) { 216object_to_vim (args .items [i ],& vim_args [i ],err ); 217 } 218 219// Initialize `force_abort` and `suppress_errthrow` at the top level. 220if (!recursive ) { 221force_abort = false; 222suppress_errthrow = false; 223did_throw = false; 224// `did_emsg` is set by emsg(), which cancels execution. 225did_emsg = false; 226 } 227recursive ++ ; 228 229typval_T rettv ; 230funcexe_T funcexe = FUNCEXE_INIT ; 231funcexe .fe_firstline = curwin -> w_cursor .lnum ; 232funcexe .fe_lastline = curwin -> w_cursor .lnum ; 233funcexe .fe_evaluate = true; 234funcexe .fe_selfdict = self ; 235 236TRY_WRAP (err , { 237const sctx_T save_current_sctx = api_set_sctx (channel_id ); 238// call_func() retval is deceptive, ignore it. Instead TRY_WRAP sets `msg_list` to capture 239// abort-causing non-exception errors. 240 (void )call_func (fn .data , (int )fn .size ,& rettv , (int )args .size ,vim_args ,& funcexe ); 241current_sctx = save_current_sctx ; 242 }); 243 244if (!ERROR_SET (err )) { 245rv = vim_to_object (& rettv ,arena , false); 246 } 247 248tv_clear (& rettv ); 249recursive -- ; 250 251while (i > 0 ) { 252tv_clear (& vim_args [-- i ]); 253 } 254 255return rv ; 256} 257 258/// Calls a Vimscript function with the given arguments. 259/// 260/// On execution error: fails with Vimscript error, updates v:errmsg. 261/// 262/// @param fn Function to call 263/// @param args Function arguments packed in an Array 264/// @param[out] err Error details, if any 265/// @return Result of the function call 266Object nvim_call_function (uint64_t channel_id ,String fn ,Array args ,Arena * arena ,Error * err ) 267FUNC_API_SINCE (1 ) 268{ 269return _call_function (channel_id ,fn ,args ,NULL ,arena ,err ); 270} 271 272/// Calls a Vimscript |Dictionary-function| with the given arguments. 273/// 274/// On execution error: fails with Vimscript error, updates v:errmsg. 275/// 276/// @param dict Dict, or String evaluating to a Vimscript |self| dict 277/// @param fn Name of the function defined on the Vimscript dict 278/// @param args Function arguments packed in an Array 279/// @param[out] err Error details, if any 280/// @return Result of the function call 281Object nvim_call_dict_function (uint64_t channel_id ,Object dict ,String fn ,Array args , 282Arena * arena ,Error * err ) 283FUNC_API_SINCE (4 ) 284{ 285Object rv = OBJECT_INIT ; 286 287typval_T rettv ; 288bool mustfree = false; 289switch (dict .type ) { 290case kObjectTypeString : { 291int eval_ret ; 292TRY_WRAP (err , { 293eval_ret = eval0 (dict .data .string .data ,& rettv ,NULL ,& EVALARG_EVALUATE ); 294clear_evalarg (& EVALARG_EVALUATE ,NULL ); 295 }); 296if (ERROR_SET (err )) { 297return rv ; 298 } 299if (eval_ret != OK ) { 300abort ();// Should not happen. 301 } 302// Evaluation of the string arg created a new dict or increased the 303// refcount of a dict. Not necessary for a RPC dict. 304mustfree = true; 305break ; 306 } 307case kObjectTypeDict : 308object_to_vim (dict ,& rettv ,err ); 309break ; 310default : 311VALIDATE_EXP (false,"dict argument" ,"String or Dict" ,NULL , { 312return rv ; 313 }); 314 } 315dict_T * self_dict = rettv .vval .v_dict ; 316if (rettv .v_type != VAR_DICT || !self_dict ) { 317api_set_error (err ,kErrorTypeValidation ,"dict not found" ); 318 gotoend ; 319 } 320 321if (fn .data && fn .size > 0 && dict .type != kObjectTypeDict ) { 322dictitem_T * const di = tv_dict_find (self_dict ,fn .data , (ptrdiff_t )fn .size ); 323VALIDATE (di != NULL ,"Not found: %s" ,fn .data , { 324 gotoend ; 325 }); 326if (di -> di_tv .v_type == VAR_PARTIAL ) { 327api_set_error (err ,kErrorTypeValidation , 328"partial function not supported" ); 329 gotoend ; 330 } 331VALIDATE ((di -> di_tv .v_type == VAR_FUNC ),"Not a function: %s" ,fn .data , { 332 gotoend ; 333 }); 334fn = (String ) { 335 .data = di -> di_tv .vval .v_string , 336 .size = strlen (di -> di_tv .vval .v_string ), 337 }; 338 } 339 340VALIDATE ((fn .data && fn .size >=1 ),"Invalid function name: %s" ,"(empty)" , { 341 gotoend ; 342 }); 343 344rv = _call_function (channel_id ,fn ,args ,self_dict ,arena ,err ); 345end : 346if (mustfree ) { 347tv_clear (& rettv ); 348 } 349 350return rv ; 351} 352 353typedef struct { 354ExprASTNode ** node_p ; 355Object * ret_node_p ; 356}ExprASTConvStackItem ; 357 358typedef kvec_withinit_t (ExprASTConvStackItem ,16 )ExprASTConvStack ; 359 360/// Parse a Vimscript expression. 361/// 362/// @param[in] expr Expression to parse. Always treated as a single line. 363/// @param[in] flags Flags: 364/// - "E" if EOC tokens are not allowed (determines whether 365/// they will stop parsing process or be recognized as an 366/// operator/space, though also yielding an error). 367/// - "l" when needing to start parsing with lvalues for 368/// ":let" or ":for". 369/// - "m" if multiple expressions in a row are allowed (only 370/// the first one will be parsed), 371/// - Common flag sets: 372/// - "E" to parse like for `"<C-r>="`. 373/// - "lm" to parse for ":let". 374/// - "m" to parse like for `":echo"`. 375/// - empty string for ":call". 376/// @param[in] hl If true, return value will also include "highlight" 377/// key containing array of 4-tuples (arrays) (Integer, 378/// Integer, Integer, String), where first three numbers 379/// define the highlighted region and represent line, 380/// starting column and ending column (latter exclusive: 381/// one should highlight region [start_col, end_col)). 382/// 383/// @return 384/// - AST: top-level dict with these keys: 385/// - "error": Dict with error, present only if parser saw some 386/// error. Contains the following keys: 387/// - "message": String, error message in printf format, translated. 388/// Must contain exactly one `%.*s`. 389/// - "arg": String, error message argument. 390/// - "len": Amount of bytes successfully parsed. With flags equal to "" 391/// that should be equal to the length of expr string. 392/// ("Successfully parsed" here means "participated in AST 393/// creation", not "till the first error".) 394/// - "ast": AST, either nil or a dict with these keys: 395/// - "type": node type, one of the value names from ExprASTNodeType 396/// stringified without "kExprNode" prefix. 397/// - "start": a pair `[line, column]` describing where node is "started" 398/// where "line" is always 0 (will not be 0 if you will be 399/// using this API on e.g. ":let", but that is not 400/// present yet). Both elements are Integers. 401/// - "len": “length” of the node. This and "start" are there for 402/// debugging purposes primary (debugging parser and providing 403/// debug information). 404/// - "children": a list of nodes described in top/"ast". There always 405/// is zero, one or two children, key will not be present 406/// if node has no children. Maximum number of children 407/// may be found in node_maxchildren array. 408/// - Local values (present only for certain nodes): 409/// - "scope": a single Integer, specifies scope for "Option" and 410/// "PlainIdentifier" nodes. For "Option" it is one of 411/// ExprOptScope values, for "PlainIdentifier" it is one of 412/// ExprVarScope values. 413/// - "ident": identifier (without scope, if any), present for "Option", 414/// "PlainIdentifier", "PlainKey" and "Environment" nodes. 415/// - "name": Integer, register name (one character) or -1. Only present 416/// for "Register" nodes. 417/// - "cmp_type": String, comparison type, one of the value names from 418/// ExprComparisonType, stringified without "kExprCmp" 419/// prefix. Only present for "Comparison" nodes. 420/// - "ccs_strategy": String, case comparison strategy, one of the 421/// value names from ExprCaseCompareStrategy, 422/// stringified without "kCCStrategy" prefix. Only 423/// present for "Comparison" nodes. 424/// - "augmentation": String, augmentation type for "Assignment" nodes. 425/// Is either an empty string, "Add", "Subtract" or 426/// "Concat" for "=", "+=", "-=" or ".=" respectively. 427/// - "invert": Boolean, true if result of comparison needs to be 428/// inverted. Only present for "Comparison" nodes. 429/// - "ivalue": Integer, integer value for "Integer" nodes. 430/// - "fvalue": Float, floating-point value for "Float" nodes. 431/// - "svalue": String, value for "SingleQuotedString" and 432/// "DoubleQuotedString" nodes. 433/// @param[out] err Error details, if any 434Dict nvim_parse_expression (String expr ,String flags ,Boolean hl ,Arena * arena ,Error * err ) 435FUNC_API_SINCE (4 )FUNC_API_FAST 436{ 437int pflags = 0 ; 438for (size_t i = 0 ;i < flags .size ;i ++ ) { 439switch (flags .data [i ]) { 440case 'm' : 441pflags |=kExprFlagsMulti ;break ; 442case 'E' : 443pflags |=kExprFlagsDisallowEOC ;break ; 444case 'l' : 445pflags |=kExprFlagsParseLet ;break ; 446case NUL : 447api_set_error (err ,kErrorTypeValidation ,"Invalid flag: '\\0' (%u)" , 448 (unsigned )flags .data [i ]); 449return (Dict )ARRAY_DICT_INIT ; 450default : 451api_set_error (err ,kErrorTypeValidation ,"Invalid flag: '%c' (%u)" , 452flags .data [i ], (unsigned )flags .data [i ]); 453return (Dict )ARRAY_DICT_INIT ; 454 } 455 } 456ParserLine parser_lines []= { 457 { 458 .data = expr .data , 459 .size = expr .size , 460 .allocated = false, 461 }, 462 {NULL ,0 , false }, 463 }; 464ParserLine * plines_p = parser_lines ; 465ParserHighlight colors ; 466kvi_init (colors ); 467ParserHighlight * const colors_p = (hl ?& colors :NULL ); 468ParserState pstate ; 469viml_parser_init (& pstate ,parser_simple_get_line ,& plines_p ,colors_p ); 470ExprAST east = viml_pexpr_parse (& pstate ,pflags ); 471 472const size_t ret_size = (2 // "ast", "len" 473+ (size_t )(east .err .msg != NULL )// "error" 474+ (size_t )hl // "highlight" 475+ 0 ); 476 477Dict ret = arena_dict (arena ,ret_size ); 478PUT_C (ret ,"len" ,INTEGER_OBJ ((Integer )(pstate .pos .line == 1 479 ?parser_lines [0 ].size 480 :pstate .pos .col ))); 481if (east .err .msg != NULL ) { 482Dict err_dict = arena_dict (arena ,2 ); 483PUT_C (err_dict ,"message" ,CSTR_TO_ARENA_OBJ (arena ,east .err .msg )); 484PUT_C (err_dict ,"arg" ,CBUF_TO_ARENA_OBJ (arena ,east .err .arg , (size_t )east .err .arg_len )); 485PUT_C (ret ,"error" ,DICT_OBJ (err_dict )); 486 } 487if (hl ) { 488Array hl_arr = arena_array (arena ,kv_size (colors )); 489for (size_t i = 0 ;i < kv_size (colors );i ++ ) { 490const ParserHighlightChunk chunk = kv_A (colors ,i ); 491Array chunk_arr = arena_array (arena ,4 ); 492ADD_C (chunk_arr ,INTEGER_OBJ ((Integer )chunk .start .line )); 493ADD_C (chunk_arr ,INTEGER_OBJ ((Integer )chunk .start .col )); 494ADD_C (chunk_arr ,INTEGER_OBJ ((Integer )chunk .end_col )); 495ADD_C (chunk_arr ,CSTR_AS_OBJ (chunk .group )); 496 497ADD_C (hl_arr ,ARRAY_OBJ (chunk_arr )); 498 } 499PUT_C (ret ,"highlight" ,ARRAY_OBJ (hl_arr )); 500 } 501kvi_destroy (colors ); 502 503// Walk over the AST, freeing nodes in process. 504ExprASTConvStack ast_conv_stack ; 505kvi_init (ast_conv_stack ); 506Object ast = NIL ; 507kvi_push (ast_conv_stack , ((ExprASTConvStackItem ) { 508 .node_p = & east .root , 509 .ret_node_p = & ast , 510 })); 511while (kv_size (ast_conv_stack )) { 512ExprASTConvStackItem cur_item = kv_last (ast_conv_stack ); 513ExprASTNode * const node = * cur_item .node_p ; 514if (node == NULL ) { 515assert (kv_size (ast_conv_stack )== 1 ); 516kv_drop (ast_conv_stack ,1 ); 517 }else { 518if (cur_item .ret_node_p -> type == kObjectTypeNil ) { 519size_t items_size = (size_t )(3 // "type", "start" and "len" // NOLINT(bugprone-misplaced-widening-cast) 520+ (node -> children != NULL )// "children" 521+ (node -> type == kExprNodeOption 522|| node -> type == kExprNodePlainIdentifier )// "scope" 523+ (node -> type == kExprNodeOption 524|| node -> type == kExprNodePlainIdentifier 525|| node -> type == kExprNodePlainKey 526|| node -> type == kExprNodeEnvironment )// "ident" 527+ (node -> type == kExprNodeRegister )// "name" 528+ (3 // "cmp_type", "ccs_strategy", "invert" 529* (node -> type == kExprNodeComparison )) 530+ (node -> type == kExprNodeInteger )// "ivalue" 531+ (node -> type == kExprNodeFloat )// "fvalue" 532+ (node -> type == kExprNodeDoubleQuotedString 533|| node -> type == kExprNodeSingleQuotedString )// "svalue" 534+ (node -> type == kExprNodeAssignment )// "augmentation" 535+ 0 ); 536Dict ret_node = arena_dict (arena ,items_size ); 537* cur_item .ret_node_p = DICT_OBJ (ret_node ); 538 } 539Dict * ret_node = & cur_item .ret_node_p -> data .dict ; 540if (node -> children != NULL ) { 541const size_t num_children = 1 + (node -> children -> next != NULL ); 542Array children_array = arena_array (arena ,num_children ); 543for (size_t i = 0 ;i < num_children ;i ++ ) { 544ADD_C (children_array ,NIL ); 545 } 546PUT_C (* ret_node ,"children" ,ARRAY_OBJ (children_array )); 547kvi_push (ast_conv_stack , ((ExprASTConvStackItem ) { 548 .node_p = & node -> children , 549 .ret_node_p = & children_array .items [0 ], 550 })); 551 }else if (node -> next != NULL ) { 552// ret_node_p + 1 is valid: we're in a children_array (root node never 553// has "next"). kv_size > 1 confirms we're not at root. 554assert (kv_size (ast_conv_stack )> 1 ); 555kvi_push (ast_conv_stack , ((ExprASTConvStackItem ) { 556 .node_p = & node -> next , 557 .ret_node_p = cur_item .ret_node_p + 1 , 558 })); 559 }else { 560kv_drop (ast_conv_stack ,1 ); 561PUT_C (* ret_node ,"type" ,CSTR_AS_OBJ (east_node_type_tab [node -> type ])); 562Array start_array = arena_array (arena ,2 ); 563ADD_C (start_array ,INTEGER_OBJ ((Integer )node -> start .line )); 564ADD_C (start_array ,INTEGER_OBJ ((Integer )node -> start .col )); 565PUT_C (* ret_node ,"start" ,ARRAY_OBJ (start_array )); 566 567PUT_C (* ret_node ,"len" ,INTEGER_OBJ ((Integer )node -> len )); 568switch (node -> type ) { 569case kExprNodeDoubleQuotedString : 570case kExprNodeSingleQuotedString : { 571Object str = CBUF_TO_ARENA_OBJ (arena ,node -> data .str .value ,node -> data .str .size ); 572PUT_C (* ret_node ,"svalue" ,str ); 573xfree (node -> data .str .value ); 574break ; 575 } 576case kExprNodeOption : 577PUT_C (* ret_node ,"scope" ,INTEGER_OBJ (node -> data .opt .scope )); 578PUT_C (* ret_node ,"ident" ,CBUF_TO_ARENA_OBJ (arena ,node -> data .opt .ident , 579node -> data .opt .ident_len )); 580break ; 581case kExprNodePlainIdentifier : 582PUT_C (* ret_node ,"scope" ,INTEGER_OBJ (node -> data .var .scope )); 583PUT_C (* ret_node ,"ident" ,CBUF_TO_ARENA_OBJ (arena ,node -> data .var .ident , 584node -> data .var .ident_len )); 585break ; 586case kExprNodePlainKey : 587PUT_C (* ret_node ,"ident" ,CBUF_TO_ARENA_OBJ (arena ,node -> data .var .ident , 588node -> data .var .ident_len )); 589break ; 590case kExprNodeEnvironment : 591PUT_C (* ret_node ,"ident" ,CBUF_TO_ARENA_OBJ (arena ,node -> data .env .ident , 592node -> data .env .ident_len )); 593break ; 594case kExprNodeRegister : 595PUT_C (* ret_node ,"name" ,INTEGER_OBJ (node -> data .reg .name )); 596break ; 597case kExprNodeComparison : 598PUT_C (* ret_node ,"cmp_type" ,CSTR_AS_OBJ (eltkn_cmp_type_tab [node -> data .cmp .type ])); 599PUT_C (* ret_node ,"ccs_strategy" ,CSTR_AS_OBJ (ccs_tab [node -> data .cmp .ccs ])); 600PUT_C (* ret_node ,"invert" ,BOOLEAN_OBJ (node -> data .cmp .inv )); 601break ; 602case kExprNodeFloat : 603PUT_C (* ret_node ,"fvalue" ,FLOAT_OBJ (node -> data .flt .value )); 604break ; 605case kExprNodeInteger : 606PUT_C (* ret_node ,"ivalue" ,INTEGER_OBJ ((Integer )(node -> data .num .value > API_INTEGER_MAX 607 ?API_INTEGER_MAX 608 : (Integer )node -> data .num .value ))); 609break ; 610case kExprNodeAssignment : { 611const ExprAssignmentType asgn_type = node -> data .ass .type ; 612String str = (asgn_type == kExprAsgnPlain 613 ? (String )STRING_INIT :cstr_as_string (expr_asgn_type_tab [asgn_type ])); 614PUT_C (* ret_node ,"augmentation" ,STRING_OBJ (str )); 615break ; 616 } 617case kExprNodeMissing : 618case kExprNodeOpMissing : 619case kExprNodeTernary : 620case kExprNodeTernaryValue : 621case kExprNodeSubscript : 622case kExprNodeListLiteral : 623case kExprNodeUnaryPlus : 624case kExprNodeBinaryPlus : 625case kExprNodeNested : 626case kExprNodeCall : 627case kExprNodeComplexIdentifier : 628case kExprNodeUnknownFigure : 629case kExprNodeLambda : 630case kExprNodeDictLiteral : 631case kExprNodeCurlyBracesIdentifier : 632case kExprNodeComma : 633case kExprNodeColon : 634case kExprNodeArrow : 635case kExprNodeConcat : 636case kExprNodeConcatOrSubscript : 637case kExprNodeOr : 638case kExprNodeAnd : 639case kExprNodeUnaryMinus : 640case kExprNodeBinaryMinus : 641case kExprNodeNot : 642case kExprNodeMultiplication : 643case kExprNodeDivision : 644case kExprNodeMod : 645break ; 646 } 647assert (cur_item .ret_node_p -> data .dict .size == cur_item .ret_node_p -> data .dict .capacity ); 648xfree (* cur_item .node_p ); 649* cur_item .node_p = NULL ; 650 } 651 } 652 } 653kvi_destroy (ast_conv_stack ); 654PUT_C (ret ,"ast" ,ast ); 655 656assert (ret .size == ret .capacity ); 657// Should be a no-op actually, leaving it in case non-nodes will need to be 658// freed later. 659viml_pexpr_free_ast (east ); 660viml_parser_destroy (& pstate ); 661return ret ; 662}