Skip to content

surreal-lang/tree-sitter-surreal

Repository files navigation

tree-sitter-surreal

Tree-sitter grammar for the Surreal language - a Rust-like syntax with Erlang/BEAM concurrency semantics.

Features

  • 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>>)

Building

npm install
npx tree-sitter generate

Testing the Parser

npx tree-sitter parse path/to/file.surreal

Neovim Setup

1. Install nvim-treesitter

Make sure you have nvim-treesitter installed.

2. Register the parser

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",
}

3. Set up filetype detection

Create ~/.config/nvim/ftdetect/surreal.vim:

au BufRead,BufNewFile *.surreal set filetype=surreal

Or in Lua:

vim.filetype.add({
  extension = {
    surreal = "surreal",
  },
})

4. Copy query files

mkdir -p ~/.config/nvim/queries/surreal
cp queries/*.scm ~/.config/nvim/queries/surreal/

5. Install the parser

In Neovim:

:TSInstall surreal

6. Verify

Open a .surreal file and run:

:InspectTree

Example Syntax

mod counter {
    pub fn start() -> Pid {
        spawn || {
            loop(0)
        }
    }

    fn loop(count: int) {
        receive {
            :increment => loop(count + 1),
            (:get, sender) => {
                sender ! count;
                loop(count)
            }
        }
    }
}

Syntax Highlighting

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 /* */)

License

MIT

About

Tree-sitter grammar for the Surreal programming language

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors