From 4f406ae891113fc1bfda308052c835a185188670 Mon Sep 17 00:00:00 2001 From: tiyn Date: Fri, 20 Feb 2026 07:27:32 +0100 Subject: [PATCH] initial push --- README.md | 6 +++++- lua/viper/init.lua | 45 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 lua/viper/init.lua diff --git a/README.md b/README.md index 380db6c..8020488 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,6 @@ # viper.nvim -Simple highlighting tool for the verification language viper. + +viper.nvim is a simple plugin that adds basic highlighting capabilities to NeoVim for the +verification language [Viper](https://github.com/viperproject). + +Currently it uses simple parsing and word matching for this and does not use any tree structures. diff --git a/lua/viper/init.lua b/lua/viper/init.lua new file mode 100644 index 0000000..8a001e2 --- /dev/null +++ b/lua/viper/init.lua @@ -0,0 +1,45 @@ +local M = {} + +function M.setup() + local group = vim.api.nvim_create_augroup("ViperSyntax", { clear = true }) + + local function enable_viper_syntax() + if vim.b.viper_syntax_loaded then + return + end + vim.b.viper_syntax_loaded = true + + vim.cmd("syntax enable") + vim.cmd("syntax clear") + + vim.cmd([[ + syntax keyword viperKeyword method function returns requires ensures invariant + syntax keyword viperKeyword if else while var field predicate + syntax keyword viperKeyword assert assume inhale exhale fold unfold + + syntax keyword viperType Int Bool Ref + + syntax match viperComment "//.*$" + syntax match viperNumber "\v\d+" + ]]) + + vim.api.nvim_set_hl(0, "viperKeyword", { link = "Keyword" }) + vim.api.nvim_set_hl(0, "viperType", { link = "Type" }) + vim.api.nvim_set_hl(0, "viperComment", { link = "Comment" }) + vim.api.nvim_set_hl(0, "viperNumber", { link = "Number" }) + end + + vim.api.nvim_create_autocmd("FileType", { + group = group, + pattern = "viper", + callback = enable_viper_syntax, + }) + + vim.api.nvim_create_autocmd({ "BufRead", "BufNewFile" }, { + group = group, + pattern = "*.vpr", + callback = enable_viper_syntax, + }) +end + +return M