Skip to content

feat: add missing Vim 9.x syntax support - #209

Open
MindTooth wants to merge 3 commits into
vim-jp:masterfrom
MindTooth:vim92-syntax-fixes
Open

MindTooth wants to merge 3 commits into
vim-jp:masterfrom
MindTooth:vim92-syntax-fixes

Conversation

@MindTooth

@MindTooth MindTooth commented Nov 28, 2026 •

Copy link
Copy Markdown

Summary

This PR closes five remaining Vim 9.0–9.2 syntax gaps verified against Vim 9.2.1417, regenerates js/vimlparser.js and py/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.

  • Route TOKEN_POPEN in ExprParser.parse_expr9() through parse_vim9_paren() for both legacy and Vim9 modes.
  • Keep is_vim9_lambda() gated on self.vim9 so 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>).

  • Update 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 optional func(?T) argument types (e.g. Id<func(?number): void>).
  • Extract ExprParser.read_generic_args() and use it in parse_expr8() for:
    • Generic function calls (Func<T>(...)) and generic funcrefs (Func<T>, obj.Func<T>), attaching .type_args to the target node when not followed by (.
    • Generic method calls (expr->Func<T>(...)) in the TOKEN_ARROW branch.
  • Emit .type_args in Compiler.compile_identifier() and Compiler.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).

  • Extend the 0x/0X, 0b/0B, and 0o/0O branches in ExprTokenizer.get() to consume ' followed by a valid digit in the respective base when self.vim9 is active.

4. Interface heredoc trim modifier (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() treated trim EOF as the end marker and swallowed the remainder of the file.

  • Parse optional trim in VimLParser.parse_cmd_lua(), compute the allowed indentation prefix with self.heredoc_prefix() before advancing past trim, read the end marker with read_nonwhite() (ignoring trailing whitespace and comments, " in legacy script and # in Vim9 script, defaulting to .), and match either m or prefix . m when trim is set.
  • Route :pythonx / :pyx through parse_cmd_lua() like :python3. They used parse_cmd_common, so the lines of a pythonx << EOF block were parsed as Vim commands (import os became :import).
  • This also fixes heredocs with a trailing comment, which previously swallowed the remainder of the file: lua << EOF " comment now ends at EOF, and lua << " comment ends at ., as in Vim.
  • Escape embedded \n as \n in Compiler.compile_excmd() so multiline NODE_EXCMD nodes produce identical output in Vim (writefile() encodes embedded \n as NUL) as in JavaScript and Python.

5. Rebuilt transpiled parsers

  • Regenerated js/vimlparser.js and py/vimlparser.py via make all.

6. Code comments

  • Keep the expr8 grammar comment on parse_expr8() (it had ended up above the new read_generic_args()) and list the Vim9 generic forms.
  • Note in the 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:

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), and pythonx << trim EOF / pyx << EOF.
  • test/test_vim9number.{vim,ok} — added 0xff'ff, 0b1010'0101, and 0o77'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.out diff check
  • flake8 py
  • PYTHONPATH=py vint autoload py/pycompiler.vim

The 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

MindTooth and others added 3 commits November 29, 2026 00:31
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support . (dot) as end marker for heredoc

1 participant