diff options
| author | Elwardi <elwardifadeli@gmail.com> | 2021-12-14 13:45:56 +0100 |
|---|---|---|
| committer | Stephan Seitz <stephan.seitz@fau.de> | 2022-01-08 13:20:52 +0100 |
| commit | 16e77495c45a2e3794af72f09de717f81ea418a2 (patch) | |
| tree | f1a295c58ae112e0d2b28b31558857add5c7472b | |
| parent | Improve Haskell highlighting (diff) | |
| download | nvim-treesitter-16e77495c45a2e3794af72f09de717f81ea418a2.tar nvim-treesitter-16e77495c45a2e3794af72f09de717f81ea418a2.tar.gz nvim-treesitter-16e77495c45a2e3794af72f09de717f81ea418a2.tar.bz2 nvim-treesitter-16e77495c45a2e3794af72f09de717f81ea418a2.tar.lz nvim-treesitter-16e77495c45a2e3794af72f09de717f81ea418a2.tar.xz nvim-treesitter-16e77495c45a2e3794af72f09de717f81ea418a2.tar.zst nvim-treesitter-16e77495c45a2e3794af72f09de717f81ea418a2.zip | |
Add OpenFOAM parser
| -rw-r--r-- | README.md | 1 | ||||
| -rw-r--r-- | after/ftdetect/foam.vim | 13 | ||||
| -rw-r--r-- | lua/nvim-treesitter/parsers.lua | 15 | ||||
| -rw-r--r-- | queries/foam/folds.scm | 7 | ||||
| -rw-r--r-- | queries/foam/highlights.scm | 61 | ||||
| -rw-r--r-- | queries/foam/indents.scm | 11 | ||||
| -rw-r--r-- | queries/foam/injections.scm | 9 | ||||
| -rw-r--r-- | queries/foam/locals.scm | 6 | ||||
| -rw-r--r-- | queries/foam/textobjects.scm | 8 |
9 files changed, 131 insertions, 0 deletions
@@ -178,6 +178,7 @@ We are looking for maintainers to add more parsers and to write query files for - [x] [erlang](https://github.com/AbstractMachinesLab/tree-sitter-erlang) (maintained by @ostera) - [x] [fennel](https://github.com/travonted/tree-sitter-fennel) (maintained by @TravonteD) - [x] [fish](https://github.com/ram02z/tree-sitter-fish) (maintained by @ram02z) +- [x] [foam](https://github.com/FoamScience/tree-sitter-foam) (maintained by @FoamScience) - [ ] [fortran](https://github.com/stadelmanma/tree-sitter-fortran) - [x] [fusion](https://gitlab.com/jirgn/tree-sitter-fusion.git) (maintained by @jirgn) - [x] [Godot (gdscript)](https://github.com/PrestonKnopp/tree-sitter-gdscript) (maintained by @Shatur95) diff --git a/after/ftdetect/foam.vim b/after/ftdetect/foam.vim new file mode 100644 index 000000000..0ae2a6512 --- /dev/null +++ b/after/ftdetect/foam.vim @@ -0,0 +1,13 @@ +" Last Change: 2021 Dec 13 + +function! s:foamFile(path) + let l:lines = getline(1, 10) + for line in lines + if match(line, 'FoamFile') >= 0 + set filetype=foam + endif + endfor +endfunction + +autocmd BufNewFile,BufRead * call s:foamFile(expand("%")) +autocmd FileType cpp call s:foamFile(expand("%")) diff --git a/lua/nvim-treesitter/parsers.lua b/lua/nvim-treesitter/parsers.lua index d71655f6c..a2927917f 100644 --- a/lua/nvim-treesitter/parsers.lua +++ b/lua/nvim-treesitter/parsers.lua @@ -846,6 +846,21 @@ list.rasi = { maintainers = { "@Fymyte" }, } +list.foam = { + install_info = { + url = "https://github.com/FoamScience/tree-sitter-foam", + branch = "master", + files = {"src/parser.c", "src/scanner.cc"}, + generate_requires_npm = true, + }, + maintainers = { "@FoamScience" }, + filetype = "foam", + used_by = {"OpenFOAM"}, + -- Queries might change over time on the grammar's side + -- Otherwise everything runs fine + experimental = true, +} + local M = { list = list, } diff --git a/queries/foam/folds.scm b/queries/foam/folds.scm new file mode 100644 index 000000000..2e499c2e2 --- /dev/null +++ b/queries/foam/folds.scm @@ -0,0 +1,7 @@ +[ + (comment) + (list) + (dict_core) +] @fold + +(code (code_body)* @fold) diff --git a/queries/foam/highlights.scm b/queries/foam/highlights.scm new file mode 100644 index 000000000..ea895cf9b --- /dev/null +++ b/queries/foam/highlights.scm @@ -0,0 +1,61 @@ +;; Comments +(comment) @comment + +;; Generic Key-value pairs and dictionary keywords +(key_value + keyword: (identifier) @function +) +(dict + key: (identifier) @type +) + +;; Macros +(macro + "$" @conditional + (prev_scope)* @conditional + (identifier)* @namespace +) + + +;; Directives +"#" @conditional +(preproc_call + directive: (identifier)* @conditional + argument: (identifier)* @namespace +) +( + (preproc_call + argument: (identifier)* @namespace + ) @conditional + (#match? @conditional "ifeq") +) +( + (preproc_call) @conditional + (#match? @conditional "(else|endif)") +) + +;; Literal numbers and strings +(number_literal) @float +(string_literal) @string +(escape_sequence) @escape + +;; Treat [m^2 s^-2] the same as if it was put in numbers format +(dimensions dimension: (identifier) @float) + +;; Punctuation +[ + "(" + ")" + "[" + "]" + "{" + "}" + "#{" + "#}" + ";" +] @punctuation + +;; Special identifiers +([(identifier) "on" "off" "true" "false" "yes" "no"] @attribute +(#match? @attribute "^(uniform|non-uniform|and|or|on|off|true|false|yes|no)$") +) diff --git a/queries/foam/indents.scm b/queries/foam/indents.scm new file mode 100644 index 000000000..033700c17 --- /dev/null +++ b/queries/foam/indents.scm @@ -0,0 +1,11 @@ +[ + "{" + "}" +] @branch + +[(dict) (key_value)] @indent + + +[ + (comment) +] @ignore diff --git a/queries/foam/injections.scm b/queries/foam/injections.scm new file mode 100644 index 000000000..08d10721c --- /dev/null +++ b/queries/foam/injections.scm @@ -0,0 +1,9 @@ +;; Pass code blocks to Cpp highlighter +(code (code_body) @cpp) + +;; Pass identifiers to Go highlighter (Cheating I know) +;;((identifier) @lua) + +;; Highlight regex syntax inside literal strings +((string_literal) @regex) + diff --git a/queries/foam/locals.scm b/queries/foam/locals.scm new file mode 100644 index 000000000..2abe743dd --- /dev/null +++ b/queries/foam/locals.scm @@ -0,0 +1,6 @@ +(dict) @scope + +(dict key: (_) @definition.type) + +(key_value keyword: (_) @definition.parameter) +(key_value value: (macro (identifier)*)* @reference) diff --git a/queries/foam/textobjects.scm b/queries/foam/textobjects.scm new file mode 100644 index 000000000..6dfab06f7 --- /dev/null +++ b/queries/foam/textobjects.scm @@ -0,0 +1,8 @@ +(dict) @class.outer +((dict_core) @class.inner) +((key_value value: _? @_start (_)* _? @parameter.inner) + (#make-range! "function.inner" @_start @parameter.inner)) @function.outer +(code (_)* @class.inner) @class.outer +((comment) @_start ((comment)+) @_end + (#make-range! "comment.outer" @_start @_end)) +(comment) @comment.inner |
