Repository navigation
Conversation
Close five Vim 9.0-9.2 syntax gaps verified against Vim 9.2.1417: - Parse tuple literals in legacy Vim script as well as Vim9 script - Parse generic method calls (->) and generic funcref instantiations - Support single-quote digit separators in Vim9 hex, binary, and octal literals - Support the trim modifier in interface heredocs (:lua, :python3, etc.) - Escape embedded newlines in Compiler.compile_excmd() for cross-target parity - Regenerate js/vimlparser.js and py/vimlparser.py and add tests
In legacy Vim script, `lua << " comment` has no end marker, so Vim ends the block at ".". The parser only skipped the Vim9 "#" comment and took `"` as the marker, swallowing the rest of the file. Also fix two comments: the expr8 grammar comment had ended up above read_generic_args() and now sits on parse_expr8() again, with the new Vim9 generic forms listed; the parse_vim9_paren() comment now says it is used for legacy script too and that lambdas are Vim9 only. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
:pythonx and :pyx used parse_cmd_common, so the lines of a `pythonx << [trim] EOF` block were parsed as Vim commands (`import os` became a Vim9 :import). Route them through parse_cmd_lua() like :python3, which completes the interface heredoc support from Vim patch 8.2.0578. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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
This PR closes five remaining Vim 9.0–9.2 syntax gaps verified against Vim 9.2.1417, regenerates
js/vimlparser.jsandpy/vimlparser.py, and adds unit tests for each case.Changes
1. Tuples in legacy Vim script (Vim 9.2)
Vim 9.2 supports tuple literals (
(),(1,),(1, 2), multiline tuples, indexing/slicing, and->method calls) in both legacy Vim script and Vim9 script.TOKEN_POPENinExprParser.parse_expr9()throughparse_vim9_paren()for both legacy and Vim9 modes.is_vim9_lambda()gated onself.vim9so legacy parenthesized expressions and tuples work without enabling=>lambdas in legacy mode.2. Generic method calls via
->and generic funcref instantiation (Vim 9.2)Vim 9.2 allows both
1->Id<number>()and instantiating a generic function without an immediate call (var F = Id<number>,var H = obj.Id<number>).VimLParser.is_generic_args(require_paren)to optionally accept generic type arguments not immediately followed by(, require a word character at the start of<...>, and allow?for optionalfunc(?T)argument types (e.g.Id<func(?number): void>).ExprParser.read_generic_args()and use it inparse_expr8()for:Func<T>(...)) and generic funcrefs (Func<T>,obj.Func<T>), attaching.type_argsto the target node when not followed by(.expr->Func<T>(...)) in theTOKEN_ARROWbranch..type_argsinCompiler.compile_identifier()andCompiler.compile_dot().3. Quote digit separators in Vim9 hex, binary, and octal literals
Vim9 script allows single-quote digit separators in non-decimal integer literals (
0xff'ff,0b1010'0101,0o77'00), matching decimal literals (1'000'000).0x/0X,0b/0B, and0o/0Obranches inExprTokenizer.get()to consume'followed by a valid digit in the respective base whenself.vim9is active.4. Interface heredoc
trimmodifier (Vim 9.0+)Interface commands (
:lua,:mzscheme,:perl,:python,:python3,:pythonx,:ruby,:tcl) support<< trim [endmarker](e.g.python3 << trim EOF,lua << trim). Previously,parse_cmd_lua()treatedtrim EOFas the end marker and swallowed the remainder of the file.triminVimLParser.parse_cmd_lua(), compute the allowed indentation prefix withself.heredoc_prefix()before advancing pasttrim, read the end marker withread_nonwhite()(ignoring trailing whitespace and comments,"in legacy script and#in Vim9 script, defaulting to.), and match eithermorprefix . mwhentrimis set.:pythonx/:pyxthroughparse_cmd_lua()like:python3. They usedparse_cmd_common, so the lines of apythonx << EOFblock were parsed as Vim commands (import osbecame:import).lua << EOF " commentnow ends atEOF, andlua << " commentends at., as in Vim.\nas\ninCompiler.compile_excmd()so multilineNODE_EXCMDnodes produce identical output in Vim (writefile()encodes embedded\nas NUL) as in JavaScript and Python.5. Rebuilt transpiled parsers
js/vimlparser.jsandpy/vimlparser.pyviamake all.6. Code comments
expr8grammar comment onparse_expr8()(it had ended up above the newread_generic_args()) and list the Vim9 generic forms.parse_vim9_paren()comment that it now serves legacy script too, and that lambdas are only recognized in Vim9 script.Related issues
Closed by this PR
Closes #172. The issue links Vim patch 8.2.0578 ("heredoc for interfaces does not support 'trim'"), which section 4 implements. The
.default end marker named in the issue title already worked before this PR.Already supported on master (not changed by this PR)
These issues look stale; their examples already parse on
master, so they could be closed separately:??falsy operator):let a = get(g:, "x") ?? 1echo $"Hello, {your_name}!"map()):call map(getbufinfo(), { _, val -> 1})Tests Added
test/test_tuple.{vim,ok}— legacy tuple literals, multiline tuples, indexing/slicing,->calls, destructuring, and parenthesized expressions.test/test_vim9generic.{vim,ok}— generic->method calls, generic funcref instantiation (Id<number>,Id<func(?number): void>,obj.Id<number>, list elements), and<comparison disambiguation.test/test_heredoc_if.{vim,ok}—python3 << trim EOF(unindented, indented, and with Vim9#comment),lua << trim(default.marker), legacy"comments (lua << " comment,lua << EOF " comment), andpythonx << trim EOF/pyx << EOF.test/test_vim9number.{vim,ok}— added0xff'ff,0b1010'0101, and0o77'00.Verification
All checks passed locally against Vim 9.2.1417, including after the follow-up commits:
CI=true test/run.sh(Vim)test/run_command.sh node js/vimlparser.js(JavaScript)test/run_command.sh python3 py/vimlparser.py(Python)test/node_position/test_position.outdiff checkflake8 pyPYTHONPATH=py vint autoload py/pycompiler.vimThe CI jobs for Vim 7.4 and 8.0 were not run locally; they need the workflow approved for this fork PR.
Implemented with Gemini 4 Neon. Follow-up fixes:
🤖 Generated with Claude Code