Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 56 additions & 5 deletions tree-sitter-ora/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ From repo root:
Add parser config:

```lua
local parser_config = require("nvim-treesitter.parsers").get_parser_configs()
local parsers = require("nvim-treesitter.parsers")

parser_config.ora = {
parsers.ora = {
install_info = {
url = "/Users/logic/Ora/Ora/tree-sitter-ora",
files = { "src/parser.c" },
Expand All @@ -59,9 +59,8 @@ parser_config.ora = {

vim.filetype.add({ extension = { ora = "ora" } })

require("nvim-treesitter.configs").setup({
highlight = { enable = true },
})
require("nvim-treesitter").setup({})
require("nvim-treesitter").install({ "ora" })
```

Then run in Neovim:
Expand All @@ -70,6 +69,58 @@ Then run in Neovim:
:TSInstall ora
```

## Highlight coverage

`queries/highlights.scm` includes captures for:

- Core language: contracts, structs, enums, errors, functions, operators.
- Regions: `storage`, `memory`, `tstore`, `calldata` with dedicated variable captures.
- Formal verification: `requires`, `ensures`, `invariant`, `decreases`, quantifiers.
- Comptime: comptime keyword, comptime parameters, and comptime functions.
- Builtins: `std.*` namespaces (`constants`, `msg`, `transaction`, `block`) and intrinsic calls (`@addWithOverflow`, `@lock`, etc.).
- Ghost and verification constructs.

Useful custom links in Neovim:

```lua
vim.api.nvim_set_hl(0, "@function.comptime.ora", { bold = true })
vim.api.nvim_set_hl(0, "@module.builtin.ora", { italic = true })
vim.api.nvim_set_hl(0, "@function.builtin.ora", { bold = true })
vim.api.nvim_set_hl(0, "@constant.builtin.ora", { bold = true })
vim.api.nvim_set_hl(0, "@keyword.fv.ora", { italic = true })
vim.api.nvim_set_hl(0, "@keyword.ghost.ora", { italic = true })
```

## Shareable Neovim Highlight File

Full example file:

- `examples/nvim/ora_highlights.lua`

Usage from your `init.lua`:

```lua
local ora_hl = dofile("/absolute/path/to/tree-sitter-ora/examples/nvim/ora_highlights.lua")
ora_hl.autocmd()
```

Optional palette override:

```lua
local ora_hl = dofile("/absolute/path/to/tree-sitter-ora/examples/nvim/ora_highlights.lua")
ora_hl.autocmd({
palette = {
red = "#ff6b6b",
cyan = "#63e6be",
},
})
```

Notes:

- By default, highlights are scoped to `.ora` captures only (`@capture.ora`).
- Pass `{ global = true }` to also set non-language-scoped captures (affects other filetypes).

## Project layout

- `grammar.js`: grammar definition
Expand Down
4 changes: 4 additions & 0 deletions tree-sitter-ora/canary-files.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
ora-example/smoke.ora
ora-example/apps/counter.ora
ora-example/comptime/comptime_param_probe.ora
ora-example/apps/erc20_bitfield_comptime_generics.ora
ora-example/switch/switch_labeled.ora
ora-example/smt/verification/assume_havoc.ora
93 changes: 93 additions & 0 deletions tree-sitter-ora/examples/nvim/ora_highlights.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
local M = {}

M.default_palette = {
red = "#E67E80",
orange = "#E69875",
yellow = "#DBBC7F",
green = "#A7C080",
aqua = "#83C092",
cyan = "#7FBBB3",
blue = "#7F9FB3",
purple = "#D699B6",
fg = "#D3C6AA",
}

local function merge_palette(overrides)
if type(vim) == "table" and vim.tbl_extend then
return vim.tbl_extend("force", M.default_palette, overrides or {})
end

local out = {}
for k, v in pairs(M.default_palette) do
out[k] = v
end
for k, v in pairs(overrides or {}) do
out[k] = v
end
return out
end

local function set_capture(group, spec, opts)
vim.api.nvim_set_hl(0, group .. ".ora", spec)
if opts.global then
vim.api.nvim_set_hl(0, group, spec)
end
end

function M.setup(opts)
opts = opts or {}
local c = merge_palette(opts.palette)

-- Core language polish
set_capture("@type", { fg = c.blue }, opts)
set_capture("@type.builtin", { fg = c.aqua }, opts)
set_capture("@function", { fg = c.blue }, opts)
set_capture("@function.call", { fg = c.blue }, opts)
set_capture("@property", { fg = c.fg }, opts)
set_capture("@label", { fg = c.aqua, bold = true }, opts)
set_capture("@string.special", { fg = c.orange }, opts)

-- Comptime
set_capture("@keyword.comptime", { fg = c.orange, bold = true }, opts)
set_capture("@function.comptime", { fg = c.red, bold = true }, opts)
set_capture("@variable.parameter.comptime", { fg = c.yellow, italic = true }, opts)

-- Builtins and intrinsics
set_capture("@module.builtin", { fg = c.cyan, italic = true }, opts)
set_capture("@function.builtin", { fg = c.green, bold = true }, opts)
set_capture("@constant.builtin", { fg = c.aqua, bold = true }, opts)
set_capture("@variable.builtin", { fg = c.cyan }, opts)
set_capture("@keyword.directive", { fg = c.red, bold = true }, opts)

-- Formal verification and ghosts
set_capture("@keyword.fv", { fg = c.green, italic = true }, opts)
set_capture("@keyword.ghost", { fg = c.purple, italic = true }, opts)
set_capture("@function.ghost", { fg = c.purple }, opts)
set_capture("@variable.ghost", { fg = c.purple }, opts)

-- Region-specific cues
set_capture("@keyword.storage", { fg = c.yellow, bold = true }, opts)
set_capture("@variable.storage", { fg = c.yellow }, opts)

set_capture("@keyword.memory", { fg = c.green, bold = true }, opts)
set_capture("@variable.memory", { fg = c.green }, opts)

set_capture("@keyword.tstore", { fg = c.red, bold = true }, opts)
set_capture("@variable.tstore", { fg = c.red }, opts)

set_capture("@keyword.calldata", { fg = c.cyan, bold = true }, opts)
set_capture("@variable.calldata", { fg = c.cyan }, opts)
end

function M.autocmd(opts)
local group = vim.api.nvim_create_augroup("OraHighlights", { clear = true })
vim.api.nvim_create_autocmd("ColorScheme", {
group = group,
callback = function()
M.setup(opts)
end,
})
M.setup(opts)
end

return M
Loading
Loading