Tree-sitter grammar for the Surreal language - a Rust-like syntax with Erlang/BEAM concurrency semantics.
- Rust-like syntax (functions, structs, enums, traits, impl blocks)
- Erlang-style concurrency primitives (
spawn,send !,receive) - Pattern matching with guards
- Atoms (
:ok,:error) - Pipe operator (
|>) - Bitstring expressions (
<<value:size/specifiers>>)
npm install
npx tree-sitter generatenpx tree-sitter parse path/to/file.surrealMake sure you have nvim-treesitter installed.
Add this to your Neovim config:
local parser_config = require("nvim-treesitter.parsers").get_parser_configs()
parser_config.surreal = {
install_info = {
url = "https://github.com/scrogson/tree-sitter-surreal",
files = { "src/parser.c" },
generate_requires_npm = true,
},
filetype = "surreal",
}Create ~/.config/nvim/ftdetect/surreal.vim:
au BufRead,BufNewFile *.surreal set filetype=surrealOr in Lua:
vim.filetype.add({
extension = {
surreal = "surreal",
},
})mkdir -p ~/.config/nvim/queries/surreal
cp queries/*.scm ~/.config/nvim/queries/surreal/In Neovim:
:TSInstall surrealOpen a .surreal file and run:
:InspectTreemod counter {
pub fn start() -> Pid {
spawn || {
loop(0)
}
}
fn loop(count: int) {
receive {
:increment => loop(count + 1),
(:get, sender) => {
sender ! count;
loop(count)
}
}
}
}The grammar provides highlighting for:
- Keywords (
fn,let,if,match,struct,enum,spawn,receive, etc.) - Operators (
+,-,*,/,==,!=,&&,||,!,|>, etc.) - Bitstring syntax (
<<,>>,big,little,signed,unsigned, etc.) - Literals (integers, strings, atoms, booleans)
- Types (type identifiers, primitives)
- Functions (definitions and calls)
- Comments (line
//and block/* */)
MIT