Skip to content

Conversation

@mattn
Copy link
Member

@mattn mattn commented Jan 19, 2026

Add Vim9 Script Support via Callback Mechanism

Summary

This PR adds a callback mechanism to seamlessly support Vim9 Script parsing in vim-vimlparser. The parser now detects vim9script, vim9cmd, and def commands and invokes corresponding callbacks, allowing integration with dedicated Vim9 parsers such as vim-vim9parser.

Changes

  • Added callback support to VimLParser constructor (accepts callbacks as second parameter)
  • Implemented invoke_callback() method to trigger registered callbacks
  • Added detection for vim9script and vim9cmd commands
  • Callbacks are invoked when parsing:
    • vim9scriptvim9script_callback
    • vim9cmdvim9cmd_callback
    • defdef_callback
  • Each callback receives the AST node and the command content

Use Case

This enables tools like language servers and linters to:

  1. Parse legacy VimL code using vim-vimlparser
  2. Delegate Vim9 syntax parsing to vim-vim9parser via callbacks
  3. Support both VimL and Vim9 Script in a single codebase without switching parsers

Example

const { VimLParser, StringReader } = require('vimlparser.js');
const { Vim9Parser } = require('vim9parser.js');

const callbacks = {
  vim9script_callback: (node, content) => {
    console.log('Vim9 script detected at line', node.pos.lnum);
  },
  def_callback: (node, content) => {
    const vim9parser = new Vim9Parser();
    const vim9ast = vim9parser.parse(content);
    // Process Vim9 function definition
  }
};

const parser = new VimLParser(false, callbacks);
const ast = parser.parse(reader);

Related

Note

Please note that vim-vim9parser is still under development and does not yet fully support all Vim9 Script features. This callback mechanism provides the foundation for Vim9 support, with parser completeness improving over time.

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.

2 participants