Open
Conversation
Parse core Vim9Script constructs into proper AST nodes so that downstream tools can analyze Vim9Script code without errors. New node types: NODE_VIM9SCRIPT, NODE_DEF, NODE_ENDDEF, NODE_VAR, NODE_FINAL, NODE_EXPORT, NODE_IMPORT. Parsers for vim9script, def/enddef (with typed parameters, return types, default values, variadics), var/final (with type annotations), export (wrapping inner commands), and import. The # comment syntax is supported when vim9script mode is active. Also fix JS transpiler heuristic for subscript assignments in compile_let to check for [ in addition to . when deciding whether to add var prefix. Fixes vim-jp#194
Author
|
I started on this before seeing #204. The approach in that PR is clearly a much better solution than this. (I hadn’t even known yet about https://github.com/vim-jp/vim-vim9parser.) But I figured I’d go ahead and raise this anyway — in case it happens to be of any interest, or might be a possible interim solution until #204 gets merged. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
parse_cmd_common, so downstream tools can analyze Vim9Script code without errors#comment support whenvim9scriptmode is activecompile_letheuristic that incorrectly addedvarprefix to subscript assignments likenamed[pname] = 1Motivation
Tools that depend on
vim-vimlparser— such as vint and vim-language-server (which vendors the JS output directly) — report unexpected errors on valid Vim9Script code because the parser doesn't recognize constructs likedef, typed parameters, or#comments. This adds structured parsing for the core Vim9Script syntax so these tools can handle Vim9Script files correctly.Details
New node types:
NODE_VIM9SCRIPT,NODE_DEF,NODE_ENDDEF,NODE_VAR,NODE_FINAL,NODE_EXPORT,NODE_IMPORT.vim9script— sets a mode flag that enables#comments throughout the parser (inparse_one_cmd,parse_command,parse_comment,parse_trail,ends_excmds,separate_nextcmd).def/enddef— parses typed parameters (name: type), default values (name: type = expr), variadic params (...name: type), and return type annotations (: returntype). Reads parameter names directly from the reader rather than usingExprTokenizer, since:is a valid name character in VimL identifiers and would causex:to be tokenized as a single identifier.var/final— parses variable declarations with optional type annotations. Same direct-reader approach to avoid the:tokenization issue.export— wraps the inner command (def, var, etc.) by delegating tofind_command+_parse_command, then moving the resulting nodes into the export node's body.import— captures the import specification as a string.Fixes #194