Add OpenFOAM parser

This commit is contained in:
Elwardi 2021-12-14 13:45:56 +01:00 committed by Stephan Seitz
parent 50fee51d35
commit 16e77495c4
9 changed files with 131 additions and 0 deletions

7
queries/foam/folds.scm Normal file
View file

@ -0,0 +1,7 @@
[
(comment)
(list)
(dict_core)
] @fold
(code (code_body)* @fold)

View file

@ -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)$")
)

11
queries/foam/indents.scm Normal file
View file

@ -0,0 +1,11 @@
[
"{"
"}"
] @branch
[(dict) (key_value)] @indent
[
(comment)
] @ignore

View file

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

6
queries/foam/locals.scm Normal file
View file

@ -0,0 +1,6 @@
(dict) @scope
(dict key: (_) @definition.type)
(key_value keyword: (_) @definition.parameter)
(key_value value: (macro (identifier)*)* @reference)

View file

@ -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