A Tree-sitter parser for the Seed7 programming language, enabling syntax highlighting, code folding, and parsing for Seed7 code in editors like Neovim.
-
Syntax Support:
- Include directives:
$ include "file";
- Constants:
const proc: name is func ...
- Functions:
func local ... begin ... end func
- Variables:
var string: name is "value";
- Control structures:
if
,else
,elsif
,for
,repeat
,while
,case
(withwhen
and set expressions) - Expressions: Identifiers, strings, integers, function calls, concatenation (
<&
), comparisons (=
,<>
,<
,>
,<=
,>=
), assignments (:=
), arithmetic (+
,-
,*
,/
), set literals ({}
), ranges (..
), set unions (|
) - Types:
proc
,string
,integer
- Comments:
# ...
,(* ... *)
,{* ... *}
- Include directives:
-
Editor Integration: Syntax highlighting for Neovim via
queries/seed7/highlights.scm
.
- Neovim (version 0.9.0 or later recommended).
- Tree-sitter CLI: Install via
npm install -g tree-sitter-cli
. - Node.js and
npm
for Tree-sitter CLI. - nvim-treesitter plugin installed in Neovim.
- Git for cloning the repository.
Since this parser is not yet included in nvim-treesitter
, follow these steps to install it manually:
-
Clone the Repository:
git clone https://github.com/aliqyan-21/tree-sitter-seed7.git ~/.local/share/nvim/site/pack/parser/start/tree-sitter-seed7 cd ~/.local/share/nvim/site/pack/parser/start/tree-sitter-seed7
-
Generate the Parser:
tree-sitter generate
-
Configure Neovim for the Parser: Add the following to your Neovim configuration (e.g.,
~/.config/nvim/init.lua
or a file in~/.config/nvim/lua/
):local parser_config = require("nvim-treesitter.parsers").get_parser_configs() parser_config.seed7 = { install_info = { url = "~/.local/share/nvim/site/pack/parser/start/tree-sitter-seed7", -- Local path to the parser files = { "src/parser.c" }, branch = "main", generate_requires_npm = false, -- Pre-generated parser.c included }, filetype = "sd7", }
-
Set Up Filetype Detection: Since Vim/Neovim does not natively recognize the
sd7
filetype, add the following to~/.config/nvim/ftdetect/seed7.vim
to associate.sd7
files with theseed7
filetype:vim.cmd [[autocmd BufRead,BufNewFile *.sd7 set filetype=seed7]]
For vim:
autocmd BufRead,BufNewFile *.sd7 setfiletype seed7
-
Copy Highlight Queries: Copy the highlighting queries to Neovim’s query directory:
mkdir -p ~/.local/share/nvim/site/queries/seed7 cp ~/.local/share/nvim/site/pack/parser/start/tree-sitter-seed7/queries/seed7.scm ~/.local/share/nvim/site/queries/seed7/highlights.scm
-
Install the Parser in Neovim: Open Neovim and run:
:TSInstall seed7
This compiles and installs the parser for use with
nvim-treesitter
. -
Verify Installation: Open a Seed7 file:
nvim ~/.local/share/nvim/site/pack/parser/start/tree-sitter-seed7/test_case.sd7
Check syntax highlighting with:
:TSHighlightCapturesUnderCursor
If you use a Neovim package manager like packer.nvim
, you can add the parser as a custom repository:
use {
'aliqyan-21/tree-sitter-seed7',
config = function()
local parser_config = require("nvim-treesitter.parsers").get_parser_configs()
parser_config.seed7 = {
install_info = {
url = "~/.local/share/nvim/site/pack/packer/start/tree-sitter-seed7", -- Adjust path based on your package manager
files = { "src/parser.c" },
branch = "main",
generate_requires_npm = false,
},
filetype = "sd7",
}
end
}
After adding, run :PackerSync
(or equivalent) and :TSInstall seed7
.
Test the parser with provided Seed7 test files:
tree-sitter parse test_case.sd7
Verify output shows no ERROR
nodes. Open in Neovim to confirm highlighting:
nvim test_case.sd7
The parser is under active development and has the following limitations:
- Unsupported types:
float
,char
,boolean
. - Unsupported operators:
div
,and
,or
,not
. - Missing features:
- Unary operators.
- Subscripts.
- Type declarations.
- Function parameters (e.g.,
game(in integer: min, in integer: max) is func
). - Constant declarations (treated as identifiers).
- Arrays.
- See Issues for planned enhancements.
Contributions to address these limitations are highly encouraged.
We welcome contributions to improve the parser’s stability and feature set. To contribute:
- Fork the repository:
https://github.com/aliqyan-21/tree-sitter-seed7
. - Create a feature branch:
git checkout -b feature-name
. - Modify
grammar.js
, add test files, or updatequeries/seed7.scm
. - Test changes:
tree-sitter generate tree-sitter parse test_*.sd7
- Submit a pull request with a clear description of changes.
Refer to the Seed7 Manual for syntax accuracy.
- Thomas Mertes and Seed7 Community for developing Seed7.
- Tree-sitter and nvim-treesitter for parsing and highlighting infrastructure.