Skip to content

About

Vim script parser

Resources

Stars

173 stars

Watchers

10 watching

Forks

Latest commit

 

History

644 Commits

Folders and files

Repository files navigation

Vim script parsers

Build Status codecov

This is Vim script language (a.k.a. VimL) parsers.

Features

The parser to make AST (Abstract Syntax Tree)

Supported languages

This parser provide same feature for following languages.

  • Vim script
  • Python
  • JavaScript

Example

All of interfaces are provided from vimlparser module. VimLParser parse into AST using StringReader, and Compiler to compile nodes.

let s:VP = vimlparser#import()
let code = [
\ 'let s:message = printf("hello %d", 1+(2*3))'
\]
let r = s:VP.StringReader.new(code)
let p = s:VP.VimLParser.new()
let c = s:VP.Compiler.new()
echo join(c.compile(p.parse(r)), "\n")

This above code output following.

(let = s:message (printf "hello %d" (+ 1 (* 2 3))))

Vim9 script

Vim9 script is parsed after vim9script, inside :def functions and Vim9 lambdas, and for commands with the :vim9cmd modifier. :function bodies and commands with :legacy use legacy syntax. This includes assignments and function calls without :let and :call, declarations with types, => lambdas with blocks, line continuation without backslash, classes, interfaces, enums, :type, :import and :export.

vim9script
var total: number = [1, 2, 3]
  ->reduce((acc, n) => acc + n)
total += 1
(vim9script)
(var = total: number (method (list 1 2 3) (reduce (lambda (acc n) (+ acc n)))))
(assign += total 1)

The Vim script parser is recursive, deeply nested expressions may need a larger 'maxfuncdepth'.

About project name

We know a name "VimL" is not the common short form of "Vim scripting language". But we choice "VimL" for historical and practical reasons and compatibility.

About

Vim script parser

Resources

Stars

173 stars

Watchers

10 watching

Forks

Releases

Packages

Used by

Contributors

Languages