From 0cb0c306183be94b9d42c3fae22b805850f87584 Mon Sep 17 00:00:00 2001 From: Austen LeBeau Date: Sun, 10 Jul 2022 11:27:44 -0500 Subject: [PATCH] add fortran language (#3025) --- book/src/generated/lang-support.md | 1 + languages.toml | 14 ++ runtime/queries/fortran/folds.scm | 11 ++ runtime/queries/fortran/highlights.scm | 171 +++++++++++++++++++++++++ runtime/queries/fortran/indents.scm | 27 ++++ 5 files changed, 224 insertions(+) create mode 100644 runtime/queries/fortran/folds.scm create mode 100644 runtime/queries/fortran/highlights.scm create mode 100644 runtime/queries/fortran/indents.scm diff --git a/book/src/generated/lang-support.md b/book/src/generated/lang-support.md index 85e42b159..085d92a8f 100644 --- a/book/src/generated/lang-support.md +++ b/book/src/generated/lang-support.md @@ -22,6 +22,7 @@ | erb | ✓ | | | | | erlang | ✓ | ✓ | | `erlang_ls` | | fish | ✓ | ✓ | ✓ | | +| fortran | ✓ | | ✓ | `fortls` | | gdscript | ✓ | | ✓ | | | git-attributes | ✓ | | | | | git-commit | ✓ | | | | diff --git a/languages.toml b/languages.toml index 56abf3f8a..3be20ab35 100644 --- a/languages.toml +++ b/languages.toml @@ -1514,3 +1514,17 @@ roots = [] comment-token = "--" indent = { tab-width = 2, unit = " " } language-server = { command = "idris2-lsp" } + +[[language]] +name = "fortran" +scope = "source.fortran" +injection-regex = "fortran" +file-types = ["f", "for", "f90", "f95", "f03"] +roots = ["fpm.toml"] +comment-token = "!" +indent = { tab-width = 4, unit = " "} +language-server = { command = "fortls", args = ["--lowercase_intrinsics"] } + +[[grammar]] +name = "fortran" +source = { git = "https://github.com/stadelmanma/tree-sitter-fortran", rev = "f0f2f100952a353e64e26b0fa710b4c296d7af13" } \ No newline at end of file diff --git a/runtime/queries/fortran/folds.scm b/runtime/queries/fortran/folds.scm new file mode 100644 index 000000000..f62d9dd7b --- /dev/null +++ b/runtime/queries/fortran/folds.scm @@ -0,0 +1,11 @@ +;; by @oponkork +[ + (if_statement) + (where_statement) + (enum_statement) + (do_loop_statement) + (derived_type_definition) + (function) + (subroutine) + (interface) +] @fold \ No newline at end of file diff --git a/runtime/queries/fortran/highlights.scm b/runtime/queries/fortran/highlights.scm new file mode 100644 index 000000000..90f4ecd0e --- /dev/null +++ b/runtime/queries/fortran/highlights.scm @@ -0,0 +1,171 @@ +[ + (intrinsic_type) + "dimension" + "intent" + "in" + "out" + "inout" + "type" + "endtype" + "attributes" + "global" + "device" + "host" + "grid_global" + "pointer" +] @keyword.storage.modifier + +[ + "contains" + "public" + "private" +] @keyword.directive + +[ +"implicit" +(none) +] @attribute + +[ + "function" + "endfunction" + "endprogram" + "subroutine" + "endsubroutine" +] @keyword.storage + +[ + "module" + "endmodule" + "bind" + "call" + "class" + "continue" + "cycle" + "enumerator" + "equivalence" + "exit" + "format" + "goto" + "include" + "interface" + "endinterface" + "only" + "parameter" + "procedure" + "print" + "program" + "endprogram" + "read" + "return" + "result" + "stop" + "use" + "write" + "enum" + "endenum" + (default) + (procedure_qualifier) +] @keyword + +[ + "if" + "then" + "else" + "elseif" + "endif" + "where" + "endwhere" +] @keyword.control.conditional + +[ + "do" + "enddo" + "while" + "forall" +] @keyword.control.repeat + +[ + "*" + "**" + "+" + "-" + "/" + "=" + "<" + ">" + "<=" + ">=" + "==" + "/=" +] @operator + +[ + "\\.and\\." + "\\.or\\." + "\\.lt\\." + "\\.gt\\." + "\\.ge\\." + "\\.le\\." + "\\.eq\\." + "\\.eqv\\." + "\\.neqv\\." +] @keyword.operator + + ;; Brackets + [ + "(" + ")" + "[" + "]" + ] @punctuation.bracket + + ;; Delimiter + [ + "::" + "," + "%" + ] @punctuation.delimiter + +(parameters + (identifier) @variable.parameter) + +(program_statement + (name) @namespace) + +(module_statement + (name) @namespace) + +(function_statement + (name) @function) + +(subroutine_statement + (name) @function) + +(end_program_statement + (name) @namespace) + +(end_module_statement + (name) @namespace) + +(end_function_statement + (name) @function) + +(end_subroutine_statement + (name) @function) + +(subroutine_call + (name) @function) + +(keyword_argument + name: (identifier) @keyword) + +(derived_type_member_expression + (type_member) @variable.other.member) + +(identifier) @variable +(string_literal) @string +(number_literal) @constant.numeric +(boolean_literal) @constant.builtin.boolean +(comment) @comment + diff --git a/runtime/queries/fortran/indents.scm b/runtime/queries/fortran/indents.scm new file mode 100644 index 000000000..daa8bac10 --- /dev/null +++ b/runtime/queries/fortran/indents.scm @@ -0,0 +1,27 @@ +[ + (module) + (program) + (subroutine) + (function) + ; (interface) + (if_statement) + (do_loop_statement) + (where_statement) + (derived_type_definition) + (enum) +] @indent + +[ + (end_module_statement) + (end_program_statement) + (end_subroutine_statement) + (end_function_statement) + ; (end_interface_statement) + (end_if_statement) + (end_do_loop_statement) + (else_clause) + (elseif_clause) + (end_type_statement) + (end_enum_statement) + (end_where_statement) +] @outdent \ No newline at end of file