From d74270c9370e48b2e654120daace9f7c3aef02cf Mon Sep 17 00:00:00 2001 From: mkorje Date: Sat, 31 Aug 2024 23:21:39 +1000 Subject: [PATCH] Add Prolog tree-sitter grammar --- book/src/generated/lang-support.md | 2 +- languages.toml | 6 +++- runtime/queries/prolog/folds.scm | 6 ++++ runtime/queries/prolog/highlights.scm | 46 +++++++++++++++++++++++++++ runtime/queries/prolog/indents.scm | 16 ++++++++++ runtime/queries/prolog/injections.scm | 2 ++ 6 files changed, 76 insertions(+), 2 deletions(-) create mode 100644 runtime/queries/prolog/folds.scm create mode 100644 runtime/queries/prolog/highlights.scm create mode 100644 runtime/queries/prolog/indents.scm create mode 100644 runtime/queries/prolog/injections.scm diff --git a/book/src/generated/lang-support.md b/book/src/generated/lang-support.md index cb1c815f2..b7c995df2 100644 --- a/book/src/generated/lang-support.md +++ b/book/src/generated/lang-support.md @@ -159,7 +159,7 @@ | ponylang | ✓ | ✓ | ✓ | | | powershell | ✓ | | | | | prisma | ✓ | ✓ | | `prisma-language-server` | -| prolog | | | | `swipl` | +| prolog | ✓ | | ✓ | `swipl` | | protobuf | ✓ | ✓ | ✓ | `bufls`, `pb` | | prql | ✓ | | | | | purescript | ✓ | ✓ | | `purescript-language-server` | diff --git a/languages.toml b/languages.toml index cc437f78c..be601852e 100644 --- a/languages.toml +++ b/languages.toml @@ -1380,6 +1380,10 @@ comment-token = "%" block-comment-tokens = { start = "/*", end = "*/" } language-servers = [ "swipl" ] +[[grammar]] +name = "prolog" +source = { git = "https://codeberg.org/foxy/tree-sitter-prolog", subpath = "grammars/prolog", rev = "93c69d2f84d8a167c0a3f4a8d51ccefe365a4dc8" } + [[language]] name = "tsq" scope = "source.tsq" @@ -3785,4 +3789,4 @@ indent = { tab-width = 2, unit = " " } [[grammar]] name = "thrift" -source = { git = "https://github.com/tree-sitter-grammars/tree-sitter-thrift" , rev = "68fd0d80943a828d9e6f49c58a74be1e9ca142cf" } \ No newline at end of file +source = { git = "https://github.com/tree-sitter-grammars/tree-sitter-thrift" , rev = "68fd0d80943a828d9e6f49c58a74be1e9ca142cf" } diff --git a/runtime/queries/prolog/folds.scm b/runtime/queries/prolog/folds.scm new file mode 100644 index 000000000..70a401511 --- /dev/null +++ b/runtime/queries/prolog/folds.scm @@ -0,0 +1,6 @@ +[ + (directive_term) + (clause_term) + (arg_list) + (list_notation) +] @fold diff --git a/runtime/queries/prolog/highlights.scm b/runtime/queries/prolog/highlights.scm new file mode 100644 index 000000000..a078b8185 --- /dev/null +++ b/runtime/queries/prolog/highlights.scm @@ -0,0 +1,46 @@ +(comment) @comment @spell + +(atom) @constant + +((atom) @boolean + (#eq? @boolean "true")) + +((atom) @boolean + (#eq? @boolean "false")) + +(functional_notation + function: (atom) @function.call) + +(integer) @number + +(float_number) @number.float + +(directive_head) @operator + +(operator_notation + operator: _ @operator) + +[ + (open) + (open_ct) + (close) + (open_list) + "|" + (close_list) + (open_curly) + (close_curly) +] @punctuation.bracket + +[ + (arg_list_separator) + (comma) + (end) + (list_notation_separator) +] @punctuation.delimiter + +(operator_notation + operator: (semicolon) @punctuation.delimiter) + +(double_quoted_list_notation) @string + +(variable_term) @variable diff --git a/runtime/queries/prolog/indents.scm b/runtime/queries/prolog/indents.scm new file mode 100644 index 000000000..a7f9b0383 --- /dev/null +++ b/runtime/queries/prolog/indents.scm @@ -0,0 +1,16 @@ +(directive_term) @indent.zero + +(clause_term) @indent.zero + +(functional_notation + (atom) + (open_ct) @indent.begin + (close) @indent.end) + +(list_notation + (open_list) @indent.begin + (close_list) @indent.end) + +(curly_bracketed_notation + (open_curly) @indent.begin + (close_curly) @indent.end) diff --git a/runtime/queries/prolog/injections.scm b/runtime/queries/prolog/injections.scm new file mode 100644 index 000000000..2f0e58eb6 --- /dev/null +++ b/runtime/queries/prolog/injections.scm @@ -0,0 +1,2 @@ +((comment) @injection.content + (#set! injection.language "comment"))