tree-sitter-clingo 0.2.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- tree_sitter_clingo-0.2.0/LICENSE +21 -0
- tree_sitter_clingo-0.2.0/PKG-INFO +22 -0
- tree_sitter_clingo-0.2.0/README.md +3 -0
- tree_sitter_clingo-0.2.0/bindings/python/tree_sitter_clingo/__init__.py +42 -0
- tree_sitter_clingo-0.2.0/bindings/python/tree_sitter_clingo/__init__.pyi +10 -0
- tree_sitter_clingo-0.2.0/bindings/python/tree_sitter_clingo/binding.c +35 -0
- tree_sitter_clingo-0.2.0/bindings/python/tree_sitter_clingo/py.typed +0 -0
- tree_sitter_clingo-0.2.0/bindings/python/tree_sitter_clingo.egg-info/PKG-INFO +22 -0
- tree_sitter_clingo-0.2.0/bindings/python/tree_sitter_clingo.egg-info/SOURCES.txt +16 -0
- tree_sitter_clingo-0.2.0/bindings/python/tree_sitter_clingo.egg-info/dependency_links.txt +1 -0
- tree_sitter_clingo-0.2.0/bindings/python/tree_sitter_clingo.egg-info/not-zip-safe +1 -0
- tree_sitter_clingo-0.2.0/bindings/python/tree_sitter_clingo.egg-info/requires.txt +3 -0
- tree_sitter_clingo-0.2.0/bindings/python/tree_sitter_clingo.egg-info/top_level.txt +2 -0
- tree_sitter_clingo-0.2.0/pyproject.toml +32 -0
- tree_sitter_clingo-0.2.0/queries/highlights.scm +294 -0
- tree_sitter_clingo-0.2.0/queries/indents.scm +48 -0
- tree_sitter_clingo-0.2.0/queries/injections.scm +4 -0
- tree_sitter_clingo-0.2.0/queries/textobjects.scm +1 -0
- tree_sitter_clingo-0.2.0/setup.cfg +4 -0
- tree_sitter_clingo-0.2.0/setup.py +77 -0
- tree_sitter_clingo-0.2.0/src/parser.c +26584 -0
- tree_sitter_clingo-0.2.0/src/scanner.c +54 -0
- tree_sitter_clingo-0.2.0/src/tree_sitter/alloc.h +54 -0
- tree_sitter_clingo-0.2.0/src/tree_sitter/array.h +291 -0
- tree_sitter_clingo-0.2.0/src/tree_sitter/parser.h +286 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2022 Sven Thiele
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: tree-sitter-clingo
|
|
3
|
+
Version: 0.2.0
|
|
4
|
+
Summary: Clingo grammar for tree-sitter
|
|
5
|
+
Author: Roland Kaminski, Sven Thiele
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/potassco/tree-sitter-clingo
|
|
8
|
+
Keywords: incremental,parsing,tree-sitter,clingo
|
|
9
|
+
Classifier: Intended Audience :: Developers
|
|
10
|
+
Classifier: Topic :: Software Development :: Compilers
|
|
11
|
+
Classifier: Topic :: Text Processing :: Linguistic
|
|
12
|
+
Classifier: Typing :: Typed
|
|
13
|
+
Requires-Python: >=3.10
|
|
14
|
+
Description-Content-Type: text/markdown
|
|
15
|
+
License-File: LICENSE
|
|
16
|
+
Provides-Extra: core
|
|
17
|
+
Requires-Dist: tree-sitter~=0.25; extra == "core"
|
|
18
|
+
Dynamic: license-file
|
|
19
|
+
|
|
20
|
+
# tree-sitter-clingo [](https://github.com/potassco/tree-sitter-clingo) [](https://crates.io/crates/tree-sitter-clingo) [](https://docs.rs/tree-sitter-clingo)
|
|
21
|
+
|
|
22
|
+
Clingo grammar for [tree-sitter](https://github.com/tree-sitter/tree-sitter)
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
# tree-sitter-clingo [](https://github.com/potassco/tree-sitter-clingo) [](https://crates.io/crates/tree-sitter-clingo) [](https://docs.rs/tree-sitter-clingo)
|
|
2
|
+
|
|
3
|
+
Clingo grammar for [tree-sitter](https://github.com/tree-sitter/tree-sitter)
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"""Clingo grammar for tree-sitter"""
|
|
2
|
+
|
|
3
|
+
from importlib.resources import files as _files
|
|
4
|
+
|
|
5
|
+
from ._binding import language
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def _get_query(name, file):
|
|
9
|
+
query = _files(f"{__package__}.queries") / file
|
|
10
|
+
globals()[name] = query.read_text()
|
|
11
|
+
return globals()[name]
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def __getattr__(name):
|
|
15
|
+
# NOTE: uncomment these to include any queries that this grammar contains:
|
|
16
|
+
|
|
17
|
+
# if name == "HIGHLIGHTS_QUERY":
|
|
18
|
+
# return _get_query("HIGHLIGHTS_QUERY", "highlights.scm")
|
|
19
|
+
# if name == "INJECTIONS_QUERY":
|
|
20
|
+
# return _get_query("INJECTIONS_QUERY", "injections.scm")
|
|
21
|
+
# if name == "LOCALS_QUERY":
|
|
22
|
+
# return _get_query("LOCALS_QUERY", "locals.scm")
|
|
23
|
+
# if name == "TAGS_QUERY":
|
|
24
|
+
# return _get_query("TAGS_QUERY", "tags.scm")
|
|
25
|
+
|
|
26
|
+
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
__all__ = [
|
|
30
|
+
"language",
|
|
31
|
+
# "HIGHLIGHTS_QUERY",
|
|
32
|
+
# "INJECTIONS_QUERY",
|
|
33
|
+
# "LOCALS_QUERY",
|
|
34
|
+
# "TAGS_QUERY",
|
|
35
|
+
]
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def __dir__():
|
|
39
|
+
return sorted(__all__ + [
|
|
40
|
+
"__all__", "__builtins__", "__cached__", "__doc__", "__file__",
|
|
41
|
+
"__loader__", "__name__", "__package__", "__path__", "__spec__",
|
|
42
|
+
])
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
from typing import Final
|
|
2
|
+
|
|
3
|
+
# NOTE: uncomment these to include any queries that this grammar contains:
|
|
4
|
+
|
|
5
|
+
# HIGHLIGHTS_QUERY: Final[str]
|
|
6
|
+
# INJECTIONS_QUERY: Final[str]
|
|
7
|
+
# LOCALS_QUERY: Final[str]
|
|
8
|
+
# TAGS_QUERY: Final[str]
|
|
9
|
+
|
|
10
|
+
def language() -> object: ...
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
#include <Python.h>
|
|
2
|
+
|
|
3
|
+
typedef struct TSLanguage TSLanguage;
|
|
4
|
+
|
|
5
|
+
TSLanguage *tree_sitter_clingo(void);
|
|
6
|
+
|
|
7
|
+
static PyObject* _binding_language(PyObject *Py_UNUSED(self), PyObject *Py_UNUSED(args)) {
|
|
8
|
+
return PyCapsule_New(tree_sitter_clingo(), "tree_sitter.Language", NULL);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
static struct PyModuleDef_Slot slots[] = {
|
|
12
|
+
#ifdef Py_GIL_DISABLED
|
|
13
|
+
{Py_mod_gil, Py_MOD_GIL_NOT_USED},
|
|
14
|
+
#endif
|
|
15
|
+
{0, NULL}
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
static PyMethodDef methods[] = {
|
|
19
|
+
{"language", _binding_language, METH_NOARGS,
|
|
20
|
+
"Get the tree-sitter language for this grammar."},
|
|
21
|
+
{NULL, NULL, 0, NULL}
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
static struct PyModuleDef module = {
|
|
25
|
+
.m_base = PyModuleDef_HEAD_INIT,
|
|
26
|
+
.m_name = "_binding",
|
|
27
|
+
.m_doc = NULL,
|
|
28
|
+
.m_size = 0,
|
|
29
|
+
.m_methods = methods,
|
|
30
|
+
.m_slots = slots,
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
PyMODINIT_FUNC PyInit__binding(void) {
|
|
34
|
+
return PyModuleDef_Init(&module);
|
|
35
|
+
}
|
|
File without changes
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: tree-sitter-clingo
|
|
3
|
+
Version: 0.2.0
|
|
4
|
+
Summary: Clingo grammar for tree-sitter
|
|
5
|
+
Author: Roland Kaminski, Sven Thiele
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/potassco/tree-sitter-clingo
|
|
8
|
+
Keywords: incremental,parsing,tree-sitter,clingo
|
|
9
|
+
Classifier: Intended Audience :: Developers
|
|
10
|
+
Classifier: Topic :: Software Development :: Compilers
|
|
11
|
+
Classifier: Topic :: Text Processing :: Linguistic
|
|
12
|
+
Classifier: Typing :: Typed
|
|
13
|
+
Requires-Python: >=3.10
|
|
14
|
+
Description-Content-Type: text/markdown
|
|
15
|
+
License-File: LICENSE
|
|
16
|
+
Provides-Extra: core
|
|
17
|
+
Requires-Dist: tree-sitter~=0.25; extra == "core"
|
|
18
|
+
Dynamic: license-file
|
|
19
|
+
|
|
20
|
+
# tree-sitter-clingo [](https://github.com/potassco/tree-sitter-clingo) [](https://crates.io/crates/tree-sitter-clingo) [](https://docs.rs/tree-sitter-clingo)
|
|
21
|
+
|
|
22
|
+
Clingo grammar for [tree-sitter](https://github.com/tree-sitter/tree-sitter)
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
README.md
|
|
3
|
+
pyproject.toml
|
|
4
|
+
setup.py
|
|
5
|
+
bindings/python/tree_sitter_clingo/__init__.py
|
|
6
|
+
bindings/python/tree_sitter_clingo/__init__.pyi
|
|
7
|
+
bindings/python/tree_sitter_clingo/binding.c
|
|
8
|
+
bindings/python/tree_sitter_clingo/py.typed
|
|
9
|
+
bindings/python/tree_sitter_clingo.egg-info/PKG-INFO
|
|
10
|
+
bindings/python/tree_sitter_clingo.egg-info/SOURCES.txt
|
|
11
|
+
bindings/python/tree_sitter_clingo.egg-info/dependency_links.txt
|
|
12
|
+
bindings/python/tree_sitter_clingo.egg-info/not-zip-safe
|
|
13
|
+
bindings/python/tree_sitter_clingo.egg-info/requires.txt
|
|
14
|
+
bindings/python/tree_sitter_clingo.egg-info/top_level.txt
|
|
15
|
+
src/parser.c
|
|
16
|
+
src/scanner.c
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=62.4.0", "wheel"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "tree-sitter-clingo"
|
|
7
|
+
description = "Clingo grammar for tree-sitter"
|
|
8
|
+
version = "0.2.0"
|
|
9
|
+
keywords = ["incremental", "parsing", "tree-sitter", "clingo"]
|
|
10
|
+
classifiers = [
|
|
11
|
+
"Intended Audience :: Developers",
|
|
12
|
+
"Topic :: Software Development :: Compilers",
|
|
13
|
+
"Topic :: Text Processing :: Linguistic",
|
|
14
|
+
"Typing :: Typed",
|
|
15
|
+
]
|
|
16
|
+
authors = [
|
|
17
|
+
{ name = "Roland Kaminski" },
|
|
18
|
+
{ name = "Sven Thiele"}
|
|
19
|
+
]
|
|
20
|
+
requires-python = ">=3.10"
|
|
21
|
+
license.text = "MIT"
|
|
22
|
+
readme = "README.md"
|
|
23
|
+
|
|
24
|
+
[project.urls]
|
|
25
|
+
Homepage = "https://github.com/potassco/tree-sitter-clingo"
|
|
26
|
+
|
|
27
|
+
[project.optional-dependencies]
|
|
28
|
+
core = ["tree-sitter~=0.25"]
|
|
29
|
+
|
|
30
|
+
[tool.cibuildwheel]
|
|
31
|
+
build = "cp310-*"
|
|
32
|
+
build-frontend = "build"
|
|
@@ -0,0 +1,294 @@
|
|
|
1
|
+
;; we conform to the neovim highlighting captures
|
|
2
|
+
;; https://neovim.io/doc/user/treesitter.html#_treesitter-syntax-highlighting
|
|
3
|
+
;; which is a superset/extension of the standard tree-sitter highlighting captures
|
|
4
|
+
;; https://github.com/tree-sitter/tree-sitter/blob/34ef1157a65987d53a18a32dbdd04046c263f7e5/crates/highlight/src/highlight.rs#L29
|
|
5
|
+
|
|
6
|
+
;;
|
|
7
|
+
;; keywords
|
|
8
|
+
;;
|
|
9
|
+
[
|
|
10
|
+
"#minimize"
|
|
11
|
+
"#minimise"
|
|
12
|
+
"#maximize"
|
|
13
|
+
"#maximise"
|
|
14
|
+
"#edge"
|
|
15
|
+
"#heuristic"
|
|
16
|
+
"#project"
|
|
17
|
+
"#show"
|
|
18
|
+
"#defined"
|
|
19
|
+
"#external"
|
|
20
|
+
] @keyword.directive
|
|
21
|
+
|
|
22
|
+
[
|
|
23
|
+
"#include"
|
|
24
|
+
] @keyword.import
|
|
25
|
+
|
|
26
|
+
[
|
|
27
|
+
(default_negation)
|
|
28
|
+
(double_default_negation)
|
|
29
|
+
(aggregate_function)
|
|
30
|
+
] @keyword.operator
|
|
31
|
+
|
|
32
|
+
[
|
|
33
|
+
"#const"
|
|
34
|
+
] @keyword.directive.define
|
|
35
|
+
|
|
36
|
+
[
|
|
37
|
+
"#script"
|
|
38
|
+
"#end"
|
|
39
|
+
"#theory"
|
|
40
|
+
"#program"
|
|
41
|
+
] @keyword
|
|
42
|
+
|
|
43
|
+
(theory
|
|
44
|
+
name: (identifier) @keyword)
|
|
45
|
+
|
|
46
|
+
(theory_atom_definition "&" @keyword)
|
|
47
|
+
(theory_atom_definition
|
|
48
|
+
name: (identifier) @keyword)
|
|
49
|
+
|
|
50
|
+
(theory_atom "&" @keyword)
|
|
51
|
+
(theory_atom
|
|
52
|
+
name: (identifier) @keyword)
|
|
53
|
+
|
|
54
|
+
(script language: (identifier) @keyword)
|
|
55
|
+
|
|
56
|
+
[
|
|
57
|
+
(theory_atom_type)
|
|
58
|
+
(const_type)
|
|
59
|
+
(theory_operator_arity)
|
|
60
|
+
(theory_operator_associativity)
|
|
61
|
+
] @keyword
|
|
62
|
+
|
|
63
|
+
;;
|
|
64
|
+
;; comments
|
|
65
|
+
;;
|
|
66
|
+
(line_comment) @comment
|
|
67
|
+
(block_comment) @comment
|
|
68
|
+
|
|
69
|
+
;;
|
|
70
|
+
;; punctuation
|
|
71
|
+
;;
|
|
72
|
+
[
|
|
73
|
+
";"
|
|
74
|
+
","
|
|
75
|
+
"."
|
|
76
|
+
":-"
|
|
77
|
+
":~"
|
|
78
|
+
":"
|
|
79
|
+
(lone_comma)
|
|
80
|
+
] @punctuation.delimiter
|
|
81
|
+
(disjunction "|" @punctuation.delimiter)
|
|
82
|
+
(weight "@" @punctuation.delimiter)
|
|
83
|
+
(signature "/" @punctuation.delimiter)
|
|
84
|
+
(theory_atom_definition "/" @punctuation.delimiter)
|
|
85
|
+
|
|
86
|
+
["(" ")" "{" "}" "[" "]"] @punctuation.bracket
|
|
87
|
+
|
|
88
|
+
;;
|
|
89
|
+
;; operators
|
|
90
|
+
;;
|
|
91
|
+
[
|
|
92
|
+
".."
|
|
93
|
+
"^"
|
|
94
|
+
"?"
|
|
95
|
+
"+"
|
|
96
|
+
"-"
|
|
97
|
+
"*"
|
|
98
|
+
"\\"
|
|
99
|
+
"**"
|
|
100
|
+
"~"
|
|
101
|
+
(theory_operator)
|
|
102
|
+
(relation)
|
|
103
|
+
] @operator
|
|
104
|
+
(abs "|" @operator)
|
|
105
|
+
(binary_operation "/" @operator)
|
|
106
|
+
(binary_operation "&" @operator)
|
|
107
|
+
(unary_operation "-" @operator)
|
|
108
|
+
|
|
109
|
+
;;
|
|
110
|
+
;; other terms
|
|
111
|
+
;;
|
|
112
|
+
(number) @number
|
|
113
|
+
(escape_sequence) @string.escape
|
|
114
|
+
(string) @string
|
|
115
|
+
(fstring) @string
|
|
116
|
+
|
|
117
|
+
(supremum) @constant.builtin
|
|
118
|
+
(infimum) @constant.builtin
|
|
119
|
+
;; We highlight all constants (non-external function symbols with 0
|
|
120
|
+
;; arity) as preprocessor-defined constants, since similarly to a
|
|
121
|
+
;; macro, they are replaced by the given value when there is a #const
|
|
122
|
+
;; statement or -c flag or if they are a parameter of a #program
|
|
123
|
+
;; statement
|
|
124
|
+
(const
|
|
125
|
+
name: (identifier) @constant.macro
|
|
126
|
+
"=" @operator)
|
|
127
|
+
(program
|
|
128
|
+
parameters: (parameters (identifier) @constant.macro))
|
|
129
|
+
(function
|
|
130
|
+
name: (identifier) @constant.macro
|
|
131
|
+
!arguments)
|
|
132
|
+
(theory_function
|
|
133
|
+
name: (identifier) @constant.macro
|
|
134
|
+
!arguments)
|
|
135
|
+
;; External functions are highlighted as preprocessor macros, since
|
|
136
|
+
;; similarly to macros, they are replaced during grounding with the
|
|
137
|
+
;; value computed by an external script. function.macro would be a
|
|
138
|
+
;; better fit, but functions are reserved for highlighting atoms.
|
|
139
|
+
(external_function
|
|
140
|
+
"@" @constant.macro
|
|
141
|
+
name: (identifier) @constant.macro)
|
|
142
|
+
;; we highlight non-zero arity, non external function symbols as data
|
|
143
|
+
;; constructors (as in Haskell). The @function capture is instead
|
|
144
|
+
;; used for atoms
|
|
145
|
+
(function
|
|
146
|
+
name: (identifier) @constructor
|
|
147
|
+
arguments: (_))
|
|
148
|
+
(theory_function
|
|
149
|
+
name: (identifier) @constructor
|
|
150
|
+
arguments: (_))
|
|
151
|
+
|
|
152
|
+
;;
|
|
153
|
+
;; variables
|
|
154
|
+
;;
|
|
155
|
+
(variable) @variable
|
|
156
|
+
(anonymous) @variable.builtin
|
|
157
|
+
|
|
158
|
+
;;
|
|
159
|
+
;; symbolic atoms
|
|
160
|
+
;;
|
|
161
|
+
;; We highlight symbolic atoms as functions, since @function is
|
|
162
|
+
;; usually used to highlight the fundamental building blocks of a
|
|
163
|
+
;; language in tree-sitter, and as this allows us to distinguish
|
|
164
|
+
;; between definitions (atoms in the head) and references (atoms
|
|
165
|
+
;; occurring elsewhere), highlighting them as @function and
|
|
166
|
+
;; @function.call, respectively.
|
|
167
|
+
;;
|
|
168
|
+
;; atom definitions (@function)
|
|
169
|
+
(rule
|
|
170
|
+
head: (literal
|
|
171
|
+
!sign
|
|
172
|
+
atom: (symbolic_atom
|
|
173
|
+
((classical_negation)? (identifier)) @function)))
|
|
174
|
+
|
|
175
|
+
(disjunction
|
|
176
|
+
(literal
|
|
177
|
+
!sign
|
|
178
|
+
atom: (symbolic_atom
|
|
179
|
+
((classical_negation)? (identifier)) @function)))
|
|
180
|
+
|
|
181
|
+
|
|
182
|
+
(disjunction
|
|
183
|
+
(conditional_literal
|
|
184
|
+
literal: (literal
|
|
185
|
+
!sign
|
|
186
|
+
atom: (symbolic_atom
|
|
187
|
+
((classical_negation)? (identifier)) @function))))
|
|
188
|
+
|
|
189
|
+
|
|
190
|
+
(head_aggregate_element
|
|
191
|
+
literal: (literal
|
|
192
|
+
!sign
|
|
193
|
+
atom: (symbolic_atom
|
|
194
|
+
((classical_negation)? (identifier)) @function)))
|
|
195
|
+
|
|
196
|
+
|
|
197
|
+
(rule
|
|
198
|
+
head: (set_aggregate
|
|
199
|
+
elements: (set_aggregate_elements
|
|
200
|
+
(set_aggregate_element
|
|
201
|
+
literal: (literal
|
|
202
|
+
!sign
|
|
203
|
+
atom: (symbolic_atom
|
|
204
|
+
((classical_negation)? (identifier)) @function))))))
|
|
205
|
+
|
|
206
|
+
(external
|
|
207
|
+
atom: (symbolic_atom
|
|
208
|
+
((classical_negation)? (identifier)) @function))
|
|
209
|
+
|
|
210
|
+
;; atom references (@function.call)
|
|
211
|
+
(rule
|
|
212
|
+
head: (literal
|
|
213
|
+
sign: (_)
|
|
214
|
+
atom: (symbolic_atom
|
|
215
|
+
((classical_negation)? (identifier)) @function.call)))
|
|
216
|
+
|
|
217
|
+
(disjunction
|
|
218
|
+
(literal
|
|
219
|
+
sign: (_)
|
|
220
|
+
atom: (symbolic_atom
|
|
221
|
+
((classical_negation)? (identifier)) @function.call)))
|
|
222
|
+
|
|
223
|
+
(disjunction
|
|
224
|
+
(conditional_literal
|
|
225
|
+
literal: (literal
|
|
226
|
+
sign: (_)
|
|
227
|
+
atom: (symbolic_atom
|
|
228
|
+
((classical_negation)? (identifier)) @function.call))))
|
|
229
|
+
|
|
230
|
+
(head_aggregate_element
|
|
231
|
+
literal: (literal
|
|
232
|
+
sign: (_)
|
|
233
|
+
atom: (symbolic_atom
|
|
234
|
+
((classical_negation)? (identifier)) @function.call)))
|
|
235
|
+
|
|
236
|
+
(rule
|
|
237
|
+
head: (set_aggregate
|
|
238
|
+
elements: (set_aggregate_elements
|
|
239
|
+
(set_aggregate_element
|
|
240
|
+
literal: (literal
|
|
241
|
+
sign: (_)
|
|
242
|
+
atom: (symbolic_atom
|
|
243
|
+
((classical_negation)? (identifier)) @function.call))))))
|
|
244
|
+
|
|
245
|
+
(body_literal
|
|
246
|
+
atom: (symbolic_atom
|
|
247
|
+
((classical_negation)? (identifier)) @function.call))
|
|
248
|
+
(body
|
|
249
|
+
(conditional_literal
|
|
250
|
+
literal: (literal
|
|
251
|
+
atom: (symbolic_atom
|
|
252
|
+
((classical_negation)? (identifier)) @function.call))))
|
|
253
|
+
(body_literal
|
|
254
|
+
atom: (set_aggregate
|
|
255
|
+
elements: (set_aggregate_elements
|
|
256
|
+
(set_aggregate_element
|
|
257
|
+
literal: (literal
|
|
258
|
+
atom: (symbolic_atom
|
|
259
|
+
((classical_negation)? (identifier)) @function.call))))))
|
|
260
|
+
(condition
|
|
261
|
+
(literal
|
|
262
|
+
atom: (symbolic_atom
|
|
263
|
+
((classical_negation)? (identifier)) @function.call)))
|
|
264
|
+
(project_atom
|
|
265
|
+
atom: (symbolic_atom
|
|
266
|
+
((classical_negation)? (identifier)) @function.call))
|
|
267
|
+
(heuristic
|
|
268
|
+
atom: (symbolic_atom
|
|
269
|
+
((classical_negation)? (identifier)) @function.call))
|
|
270
|
+
|
|
271
|
+
(signature
|
|
272
|
+
sign: (classical_negation)? @function.call
|
|
273
|
+
name: (identifier) @function.call)
|
|
274
|
+
|
|
275
|
+
;; boolean constant
|
|
276
|
+
(boolean_constant) @boolean
|
|
277
|
+
|
|
278
|
+
;;
|
|
279
|
+
;; types
|
|
280
|
+
;;
|
|
281
|
+
(theory_atom_definition
|
|
282
|
+
theory_term_name: (identifier) @type
|
|
283
|
+
guard: (identifier)? @type)
|
|
284
|
+
|
|
285
|
+
(theory_term_definition
|
|
286
|
+
name: (identifier) @type)
|
|
287
|
+
|
|
288
|
+
;;
|
|
289
|
+
;; modules
|
|
290
|
+
;;
|
|
291
|
+
(include
|
|
292
|
+
(identifier) @module)
|
|
293
|
+
(program
|
|
294
|
+
name: (identifier) @module)
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
; head :- a,
|
|
2
|
+
; b.
|
|
3
|
+
; head :-
|
|
4
|
+
; a,
|
|
5
|
+
; b.
|
|
6
|
+
;
|
|
7
|
+
; We use the error node here to also indent partial rules.
|
|
8
|
+
([(ERROR) (statement)] @indent.align
|
|
9
|
+
(#contains? @indent.align ":-")
|
|
10
|
+
(#set! indent.open_delimiter ":-")
|
|
11
|
+
(#set! indent.close_delimiter ".")
|
|
12
|
+
(#set! indent.increment 3))
|
|
13
|
+
|
|
14
|
+
; similar to rule but for weak constraints
|
|
15
|
+
([(ERROR) (statement)] @indent.align
|
|
16
|
+
(#contains? @indent.align ":~")
|
|
17
|
+
(#set! indent.open_delimiter ":~")
|
|
18
|
+
(#set! indent.close_delimiter ".")
|
|
19
|
+
(#set! indent.increment 3))
|
|
20
|
+
|
|
21
|
+
; similar to rule but for statements with a condition
|
|
22
|
+
([(ERROR) (statement)] @indent.align
|
|
23
|
+
(#not-contains? @indent.align ":-")
|
|
24
|
+
(#not-contains? @indent.align ":~")
|
|
25
|
+
(#set! indent.open_delimiter ":")
|
|
26
|
+
(#set! indent.close_delimiter ".")
|
|
27
|
+
(#set! indent.increment 2))
|
|
28
|
+
|
|
29
|
+
; #minimize { a: a;
|
|
30
|
+
; b: b;
|
|
31
|
+
; c: c;
|
|
32
|
+
; d: d }.
|
|
33
|
+
; Also applies to nested aggregates and theory atoms. We do not treat the error
|
|
34
|
+
; node here. An editor that ensures balanced braces should help.
|
|
35
|
+
([(minimize) (maximize) (set_aggregate) (body_aggregate) (head_aggregate) (theory_atom)] @indent.align
|
|
36
|
+
(#set! indent.open_delimiter "{")
|
|
37
|
+
(#set! indent.close_delimiter "}")
|
|
38
|
+
(#set! indent.increment 2))
|
|
39
|
+
|
|
40
|
+
; indent conditional literals
|
|
41
|
+
((conditional_literal) @indent.align
|
|
42
|
+
(#set! indent.open_delimiter ":")
|
|
43
|
+
(#set! indent.increment 2))
|
|
44
|
+
|
|
45
|
+
; indent conditions
|
|
46
|
+
((_ ":" . (condition))@indent.align
|
|
47
|
+
(#set! indent.open_delimiter ":")
|
|
48
|
+
(#set! indent.increment 2))
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
(statement) @function.outer
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
from os import path
|
|
2
|
+
from platform import system
|
|
3
|
+
from sysconfig import get_config_var
|
|
4
|
+
|
|
5
|
+
from setuptools import Extension, find_packages, setup
|
|
6
|
+
from setuptools.command.build import build
|
|
7
|
+
from setuptools.command.egg_info import egg_info
|
|
8
|
+
from wheel.bdist_wheel import bdist_wheel
|
|
9
|
+
|
|
10
|
+
sources = [
|
|
11
|
+
"bindings/python/tree_sitter_clingo/binding.c",
|
|
12
|
+
"src/parser.c",
|
|
13
|
+
]
|
|
14
|
+
if path.exists("src/scanner.c"):
|
|
15
|
+
sources.append("src/scanner.c")
|
|
16
|
+
|
|
17
|
+
macros: list[tuple[str, str | None]] = [
|
|
18
|
+
("PY_SSIZE_T_CLEAN", None),
|
|
19
|
+
("TREE_SITTER_HIDE_SYMBOLS", None),
|
|
20
|
+
]
|
|
21
|
+
if limited_api := not get_config_var("Py_GIL_DISABLED"):
|
|
22
|
+
macros.append(("Py_LIMITED_API", "0x030A0000"))
|
|
23
|
+
|
|
24
|
+
if system() != "Windows":
|
|
25
|
+
cflags = ["-std=c11", "-fvisibility=hidden"]
|
|
26
|
+
else:
|
|
27
|
+
cflags = ["/std:c11", "/utf-8"]
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
class Build(build):
|
|
31
|
+
def run(self):
|
|
32
|
+
if path.isdir("queries"):
|
|
33
|
+
dest = path.join(self.build_lib, "tree_sitter_clingo", "queries")
|
|
34
|
+
self.copy_tree("queries", dest)
|
|
35
|
+
super().run()
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
class BdistWheel(bdist_wheel):
|
|
39
|
+
def get_tag(self):
|
|
40
|
+
python, abi, platform = super().get_tag()
|
|
41
|
+
if python.startswith("cp"):
|
|
42
|
+
python, abi = "cp310", "abi3"
|
|
43
|
+
return python, abi, platform
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
class EggInfo(egg_info):
|
|
47
|
+
def find_sources(self):
|
|
48
|
+
super().find_sources()
|
|
49
|
+
self.filelist.recursive_include("queries", "*.scm")
|
|
50
|
+
self.filelist.include("src/tree_sitter/*.h")
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
setup(
|
|
54
|
+
packages=find_packages("bindings/python"),
|
|
55
|
+
package_dir={"": "bindings/python"},
|
|
56
|
+
package_data={
|
|
57
|
+
"tree_sitter_clingo": ["*.pyi", "py.typed"],
|
|
58
|
+
"tree_sitter_clingo.queries": ["*.scm"],
|
|
59
|
+
},
|
|
60
|
+
ext_package="tree_sitter_clingo",
|
|
61
|
+
ext_modules=[
|
|
62
|
+
Extension(
|
|
63
|
+
name="_binding",
|
|
64
|
+
sources=sources,
|
|
65
|
+
extra_compile_args=cflags,
|
|
66
|
+
define_macros=macros,
|
|
67
|
+
include_dirs=["src"],
|
|
68
|
+
py_limited_api=limited_api,
|
|
69
|
+
)
|
|
70
|
+
],
|
|
71
|
+
cmdclass={
|
|
72
|
+
"build": Build,
|
|
73
|
+
"bdist_wheel": BdistWheel,
|
|
74
|
+
"egg_info": EggInfo,
|
|
75
|
+
},
|
|
76
|
+
zip_safe=False
|
|
77
|
+
)
|