tree-sitter-ada 0.1.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_ada-0.1.0/LICENSE.txt +21 -0
- tree_sitter_ada-0.1.0/PKG-INFO +178 -0
- tree_sitter_ada-0.1.0/README.md +136 -0
- tree_sitter_ada-0.1.0/bindings/python/tree_sitter_ada/__init__.py +42 -0
- tree_sitter_ada-0.1.0/bindings/python/tree_sitter_ada/__init__.pyi +10 -0
- tree_sitter_ada-0.1.0/bindings/python/tree_sitter_ada/binding.c +35 -0
- tree_sitter_ada-0.1.0/bindings/python/tree_sitter_ada/py.typed +0 -0
- tree_sitter_ada-0.1.0/bindings/python/tree_sitter_ada.egg-info/PKG-INFO +178 -0
- tree_sitter_ada-0.1.0/bindings/python/tree_sitter_ada.egg-info/SOURCES.txt +15 -0
- tree_sitter_ada-0.1.0/bindings/python/tree_sitter_ada.egg-info/dependency_links.txt +1 -0
- tree_sitter_ada-0.1.0/bindings/python/tree_sitter_ada.egg-info/not-zip-safe +1 -0
- tree_sitter_ada-0.1.0/bindings/python/tree_sitter_ada.egg-info/requires.txt +5 -0
- tree_sitter_ada-0.1.0/bindings/python/tree_sitter_ada.egg-info/top_level.txt +2 -0
- tree_sitter_ada-0.1.0/pyproject.toml +33 -0
- tree_sitter_ada-0.1.0/queries/folds.scm +15 -0
- tree_sitter_ada-0.1.0/queries/highlights.scm +196 -0
- tree_sitter_ada-0.1.0/queries/locals.scm +33 -0
- tree_sitter_ada-0.1.0/queries/textobjects.scm +23 -0
- tree_sitter_ada-0.1.0/setup.cfg +4 -0
- tree_sitter_ada-0.1.0/setup.py +77 -0
- tree_sitter_ada-0.1.0/src/parser.c +68925 -0
- tree_sitter_ada-0.1.0/src/tree_sitter/alloc.h +54 -0
- tree_sitter_ada-0.1.0/src/tree_sitter/array.h +291 -0
- tree_sitter_ada-0.1.0/src/tree_sitter/parser.h +286 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 Emmanuel Briot
|
|
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,178 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: tree-sitter-ada
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Ada grammar for tree-sitter
|
|
5
|
+
Author: Emmanuel Briot
|
|
6
|
+
License: MIT License
|
|
7
|
+
|
|
8
|
+
Copyright (c) 2023 Emmanuel Briot
|
|
9
|
+
|
|
10
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
11
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
12
|
+
in the Software without restriction, including without limitation the rights
|
|
13
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
14
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
15
|
+
furnished to do so, subject to the following conditions:
|
|
16
|
+
|
|
17
|
+
The above copyright notice and this permission notice shall be included in all
|
|
18
|
+
copies or substantial portions of the Software.
|
|
19
|
+
|
|
20
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
21
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
22
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
23
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
24
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
25
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
26
|
+
SOFTWARE.
|
|
27
|
+
|
|
28
|
+
Project-URL: Homepage, https://github.com/briot/tree-sitter-ada
|
|
29
|
+
Keywords: incremental,parsing,tree-sitter,ada
|
|
30
|
+
Classifier: Intended Audience :: Developers
|
|
31
|
+
Classifier: Topic :: Software Development :: Compilers
|
|
32
|
+
Classifier: Topic :: Text Processing :: Linguistic
|
|
33
|
+
Classifier: Typing :: Typed
|
|
34
|
+
Requires-Python: >=3.10
|
|
35
|
+
Description-Content-Type: text/markdown
|
|
36
|
+
License-File: LICENSE.txt
|
|
37
|
+
Requires-Dist: build>=1.3.0
|
|
38
|
+
Requires-Dist: twine>=6.2.0
|
|
39
|
+
Provides-Extra: core
|
|
40
|
+
Requires-Dist: tree-sitter~=0.24; extra == "core"
|
|
41
|
+
Dynamic: license-file
|
|
42
|
+
|
|
43
|
+
# Tree-Sitter parser for Ada
|
|
44
|
+
|
|
45
|
+
The grammar is adapted from the work done by Stephen Leak for the
|
|
46
|
+
Emacs ada-mode. It was translated (partially for now) to tree-sitter
|
|
47
|
+
syntax, and slightly changed to reduce some conflicts. Tree-sitter
|
|
48
|
+
doesn't need a full syntax tree, so we can take some shortcuts in
|
|
49
|
+
the grammar.
|
|
50
|
+
|
|
51
|
+
## Installation
|
|
52
|
+
|
|
53
|
+
You will need neovim at least version 8.0 (not tested with earlier version).
|
|
54
|
+
|
|
55
|
+
Installation is very manual at this stage, until we can integrate this package
|
|
56
|
+
inside nvim-treesitter itself. At the moment, assuming you are using lua
|
|
57
|
+
configuration and Packer for your package management:
|
|
58
|
+
|
|
59
|
+
```lua
|
|
60
|
+
-- file: ~/.config/nvim/init.lua
|
|
61
|
+
|
|
62
|
+
-- Merge this with any existing Packer configuration you might already
|
|
63
|
+
-- have. This loads packer itself, then loads the new `ada.nvim` package.
|
|
64
|
+
require('packer').startup(function(use)
|
|
65
|
+
use(require('mytreesitter.nvim'))
|
|
66
|
+
end)
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
Then create a new file to setup treesitter (or merge with an existing
|
|
70
|
+
configuration of course).
|
|
71
|
+
```lua
|
|
72
|
+
-- file: ~/.config/nvim/mytreesitter.nvim
|
|
73
|
+
|
|
74
|
+
return {
|
|
75
|
+
'nvim-treesitter/nvim-treesitter',
|
|
76
|
+
requires = {
|
|
77
|
+
'nvim-treesitter/nvim-treesitter-textobjects'
|
|
78
|
+
},
|
|
79
|
+
run=function()
|
|
80
|
+
require('nvim-treesitter.install').update({ with_sync = true })
|
|
81
|
+
end,
|
|
82
|
+
config=function()
|
|
83
|
+
|
|
84
|
+
-- Add support for our Ada parser
|
|
85
|
+
|
|
86
|
+
local parsers = require "nvim-treesitter.parsers"
|
|
87
|
+
local parser_config = parsers.get_parser_configs()
|
|
88
|
+
parser_config.ada = {
|
|
89
|
+
install_info = {
|
|
90
|
+
url = "https://github.com/briot/tree-sitter-ada",
|
|
91
|
+
files = {"src/parser.c"},
|
|
92
|
+
generate_requires_npm = false,
|
|
93
|
+
requires_generate_from_grammar = false,
|
|
94
|
+
},
|
|
95
|
+
filetype = "ada",
|
|
96
|
+
}
|
|
97
|
+
end,
|
|
98
|
+
}
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
Finally, we need to install the Ada parser with:
|
|
102
|
+
```vim
|
|
103
|
+
:PackerSync " to install treesitter itself
|
|
104
|
+
:TSInstall ada " to install Ada support
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
However, the above part only installs the parser itself (to generate a syntax
|
|
108
|
+
tree from your source files). We now need to install queries, i.e. pattern
|
|
109
|
+
matching against that tree to provide various capabilities like syntax
|
|
110
|
+
highlighting, folding, indentation, smart textobject selection,...
|
|
111
|
+
|
|
112
|
+
For this, and until we can merge with nvim-treesitter itself, you will have
|
|
113
|
+
to clone this github repository, then copy the `queries/` directory to
|
|
114
|
+
```
|
|
115
|
+
~/.local/share/nvim/site/pack/packer/start/nvim-treesitter/queries/
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
## Usage
|
|
119
|
+
|
|
120
|
+
### Syntax highlighting
|
|
121
|
+
|
|
122
|
+
The above default configuration will replace the default regular
|
|
123
|
+
expressions-based syntax highlighting in vim. Instead, the highlighting is
|
|
124
|
+
based on the tree build every time you type something.
|
|
125
|
+
|
|
126
|
+
The default highlighting looks pretty much like the one from the standard
|
|
127
|
+
Ada mode. However, the tree-based approach potentially opens the door for
|
|
128
|
+
smart highlighting, like "Use a different background color for a subprogram
|
|
129
|
+
specification", "show constant definitions in blue" or other high-level
|
|
130
|
+
approaches.
|
|
131
|
+
|
|
132
|
+
WIP: document how users can do this in their own configuration files.
|
|
133
|
+
The current approach is to modify queries/highlights.scm
|
|
134
|
+
|
|
135
|
+
Potentially (though it seems to be disabled in neovim at the moment), the
|
|
136
|
+
highlighting can also get smarter. Going back to the "show constants in
|
|
137
|
+
blue" example above, the queries/locals.scm file adds a simple approach so
|
|
138
|
+
that references to those constants can point to the definition, and therefore
|
|
139
|
+
use the same blue highlighting.
|
|
140
|
+
|
|
141
|
+
Because neovim also has support for language servers (LSP), it is likely
|
|
142
|
+
better to rely on the language server here.
|
|
143
|
+
|
|
144
|
+
### Block folding
|
|
145
|
+
|
|
146
|
+
If you press <kbd>za</kbd> now, this will toggle the folding of the
|
|
147
|
+
"current block".
|
|
148
|
+
This is defined in queries/folds.scm, and currently knows about package
|
|
149
|
+
specifications, package bodies, subprograms bodies, if statements and loops.
|
|
150
|
+
Other semantic blocks could be added.
|
|
151
|
+
|
|
152
|
+
### Smart Selection
|
|
153
|
+
|
|
154
|
+
The file queries/textobjects.scm defines a function textobjects, so that
|
|
155
|
+
you can now use commands like
|
|
156
|
+
|
|
157
|
+
- <kbd>vaf</kbd> (v)isually select (a) (f)unction or subprogram
|
|
158
|
+
- <kbd>vif</kbd> (v)isually select (i)nside a (f)unction or subprogram
|
|
159
|
+
- <kbd>vai</kbd> (v)isually select (a) (i)f statement (or loop)
|
|
160
|
+
- <kbd>vii</kbd> (v)isually select (i)nside an (i)f statement (or loop)
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
## Development
|
|
164
|
+
|
|
165
|
+
Execute the following commands:
|
|
166
|
+
```bash
|
|
167
|
+
npm install
|
|
168
|
+
npm run test
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
## Documentation
|
|
172
|
+
|
|
173
|
+
The grammar itself is fully described in the file grammar.js.
|
|
174
|
+
When it processes it, TreeSitter generates src/grammar.json, which can be
|
|
175
|
+
converted to a EBNF format via https://github.com/mingodad/plgh/blob/main/json2ebnf.js
|
|
176
|
+
and rendered into a diagram on https://www.bottlecaps.de/rr/ui if you
|
|
177
|
+
prefer graphical visualization (you can also copy-paste from issue #1 a
|
|
178
|
+
pre-processed version of grammar.json).
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
# Tree-Sitter parser for Ada
|
|
2
|
+
|
|
3
|
+
The grammar is adapted from the work done by Stephen Leak for the
|
|
4
|
+
Emacs ada-mode. It was translated (partially for now) to tree-sitter
|
|
5
|
+
syntax, and slightly changed to reduce some conflicts. Tree-sitter
|
|
6
|
+
doesn't need a full syntax tree, so we can take some shortcuts in
|
|
7
|
+
the grammar.
|
|
8
|
+
|
|
9
|
+
## Installation
|
|
10
|
+
|
|
11
|
+
You will need neovim at least version 8.0 (not tested with earlier version).
|
|
12
|
+
|
|
13
|
+
Installation is very manual at this stage, until we can integrate this package
|
|
14
|
+
inside nvim-treesitter itself. At the moment, assuming you are using lua
|
|
15
|
+
configuration and Packer for your package management:
|
|
16
|
+
|
|
17
|
+
```lua
|
|
18
|
+
-- file: ~/.config/nvim/init.lua
|
|
19
|
+
|
|
20
|
+
-- Merge this with any existing Packer configuration you might already
|
|
21
|
+
-- have. This loads packer itself, then loads the new `ada.nvim` package.
|
|
22
|
+
require('packer').startup(function(use)
|
|
23
|
+
use(require('mytreesitter.nvim'))
|
|
24
|
+
end)
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
Then create a new file to setup treesitter (or merge with an existing
|
|
28
|
+
configuration of course).
|
|
29
|
+
```lua
|
|
30
|
+
-- file: ~/.config/nvim/mytreesitter.nvim
|
|
31
|
+
|
|
32
|
+
return {
|
|
33
|
+
'nvim-treesitter/nvim-treesitter',
|
|
34
|
+
requires = {
|
|
35
|
+
'nvim-treesitter/nvim-treesitter-textobjects'
|
|
36
|
+
},
|
|
37
|
+
run=function()
|
|
38
|
+
require('nvim-treesitter.install').update({ with_sync = true })
|
|
39
|
+
end,
|
|
40
|
+
config=function()
|
|
41
|
+
|
|
42
|
+
-- Add support for our Ada parser
|
|
43
|
+
|
|
44
|
+
local parsers = require "nvim-treesitter.parsers"
|
|
45
|
+
local parser_config = parsers.get_parser_configs()
|
|
46
|
+
parser_config.ada = {
|
|
47
|
+
install_info = {
|
|
48
|
+
url = "https://github.com/briot/tree-sitter-ada",
|
|
49
|
+
files = {"src/parser.c"},
|
|
50
|
+
generate_requires_npm = false,
|
|
51
|
+
requires_generate_from_grammar = false,
|
|
52
|
+
},
|
|
53
|
+
filetype = "ada",
|
|
54
|
+
}
|
|
55
|
+
end,
|
|
56
|
+
}
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
Finally, we need to install the Ada parser with:
|
|
60
|
+
```vim
|
|
61
|
+
:PackerSync " to install treesitter itself
|
|
62
|
+
:TSInstall ada " to install Ada support
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
However, the above part only installs the parser itself (to generate a syntax
|
|
66
|
+
tree from your source files). We now need to install queries, i.e. pattern
|
|
67
|
+
matching against that tree to provide various capabilities like syntax
|
|
68
|
+
highlighting, folding, indentation, smart textobject selection,...
|
|
69
|
+
|
|
70
|
+
For this, and until we can merge with nvim-treesitter itself, you will have
|
|
71
|
+
to clone this github repository, then copy the `queries/` directory to
|
|
72
|
+
```
|
|
73
|
+
~/.local/share/nvim/site/pack/packer/start/nvim-treesitter/queries/
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
## Usage
|
|
77
|
+
|
|
78
|
+
### Syntax highlighting
|
|
79
|
+
|
|
80
|
+
The above default configuration will replace the default regular
|
|
81
|
+
expressions-based syntax highlighting in vim. Instead, the highlighting is
|
|
82
|
+
based on the tree build every time you type something.
|
|
83
|
+
|
|
84
|
+
The default highlighting looks pretty much like the one from the standard
|
|
85
|
+
Ada mode. However, the tree-based approach potentially opens the door for
|
|
86
|
+
smart highlighting, like "Use a different background color for a subprogram
|
|
87
|
+
specification", "show constant definitions in blue" or other high-level
|
|
88
|
+
approaches.
|
|
89
|
+
|
|
90
|
+
WIP: document how users can do this in their own configuration files.
|
|
91
|
+
The current approach is to modify queries/highlights.scm
|
|
92
|
+
|
|
93
|
+
Potentially (though it seems to be disabled in neovim at the moment), the
|
|
94
|
+
highlighting can also get smarter. Going back to the "show constants in
|
|
95
|
+
blue" example above, the queries/locals.scm file adds a simple approach so
|
|
96
|
+
that references to those constants can point to the definition, and therefore
|
|
97
|
+
use the same blue highlighting.
|
|
98
|
+
|
|
99
|
+
Because neovim also has support for language servers (LSP), it is likely
|
|
100
|
+
better to rely on the language server here.
|
|
101
|
+
|
|
102
|
+
### Block folding
|
|
103
|
+
|
|
104
|
+
If you press <kbd>za</kbd> now, this will toggle the folding of the
|
|
105
|
+
"current block".
|
|
106
|
+
This is defined in queries/folds.scm, and currently knows about package
|
|
107
|
+
specifications, package bodies, subprograms bodies, if statements and loops.
|
|
108
|
+
Other semantic blocks could be added.
|
|
109
|
+
|
|
110
|
+
### Smart Selection
|
|
111
|
+
|
|
112
|
+
The file queries/textobjects.scm defines a function textobjects, so that
|
|
113
|
+
you can now use commands like
|
|
114
|
+
|
|
115
|
+
- <kbd>vaf</kbd> (v)isually select (a) (f)unction or subprogram
|
|
116
|
+
- <kbd>vif</kbd> (v)isually select (i)nside a (f)unction or subprogram
|
|
117
|
+
- <kbd>vai</kbd> (v)isually select (a) (i)f statement (or loop)
|
|
118
|
+
- <kbd>vii</kbd> (v)isually select (i)nside an (i)f statement (or loop)
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
## Development
|
|
122
|
+
|
|
123
|
+
Execute the following commands:
|
|
124
|
+
```bash
|
|
125
|
+
npm install
|
|
126
|
+
npm run test
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
## Documentation
|
|
130
|
+
|
|
131
|
+
The grammar itself is fully described in the file grammar.js.
|
|
132
|
+
When it processes it, TreeSitter generates src/grammar.json, which can be
|
|
133
|
+
converted to a EBNF format via https://github.com/mingodad/plgh/blob/main/json2ebnf.js
|
|
134
|
+
and rendered into a diagram on https://www.bottlecaps.de/rr/ui if you
|
|
135
|
+
prefer graphical visualization (you can also copy-paste from issue #1 a
|
|
136
|
+
pre-processed version of grammar.json).
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"""Ada 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_ada(void);
|
|
6
|
+
|
|
7
|
+
static PyObject* _binding_language(PyObject *Py_UNUSED(self), PyObject *Py_UNUSED(args)) {
|
|
8
|
+
return PyCapsule_New(tree_sitter_ada(), "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,178 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: tree-sitter-ada
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Ada grammar for tree-sitter
|
|
5
|
+
Author: Emmanuel Briot
|
|
6
|
+
License: MIT License
|
|
7
|
+
|
|
8
|
+
Copyright (c) 2023 Emmanuel Briot
|
|
9
|
+
|
|
10
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
11
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
12
|
+
in the Software without restriction, including without limitation the rights
|
|
13
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
14
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
15
|
+
furnished to do so, subject to the following conditions:
|
|
16
|
+
|
|
17
|
+
The above copyright notice and this permission notice shall be included in all
|
|
18
|
+
copies or substantial portions of the Software.
|
|
19
|
+
|
|
20
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
21
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
22
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
23
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
24
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
25
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
26
|
+
SOFTWARE.
|
|
27
|
+
|
|
28
|
+
Project-URL: Homepage, https://github.com/briot/tree-sitter-ada
|
|
29
|
+
Keywords: incremental,parsing,tree-sitter,ada
|
|
30
|
+
Classifier: Intended Audience :: Developers
|
|
31
|
+
Classifier: Topic :: Software Development :: Compilers
|
|
32
|
+
Classifier: Topic :: Text Processing :: Linguistic
|
|
33
|
+
Classifier: Typing :: Typed
|
|
34
|
+
Requires-Python: >=3.10
|
|
35
|
+
Description-Content-Type: text/markdown
|
|
36
|
+
License-File: LICENSE.txt
|
|
37
|
+
Requires-Dist: build>=1.3.0
|
|
38
|
+
Requires-Dist: twine>=6.2.0
|
|
39
|
+
Provides-Extra: core
|
|
40
|
+
Requires-Dist: tree-sitter~=0.24; extra == "core"
|
|
41
|
+
Dynamic: license-file
|
|
42
|
+
|
|
43
|
+
# Tree-Sitter parser for Ada
|
|
44
|
+
|
|
45
|
+
The grammar is adapted from the work done by Stephen Leak for the
|
|
46
|
+
Emacs ada-mode. It was translated (partially for now) to tree-sitter
|
|
47
|
+
syntax, and slightly changed to reduce some conflicts. Tree-sitter
|
|
48
|
+
doesn't need a full syntax tree, so we can take some shortcuts in
|
|
49
|
+
the grammar.
|
|
50
|
+
|
|
51
|
+
## Installation
|
|
52
|
+
|
|
53
|
+
You will need neovim at least version 8.0 (not tested with earlier version).
|
|
54
|
+
|
|
55
|
+
Installation is very manual at this stage, until we can integrate this package
|
|
56
|
+
inside nvim-treesitter itself. At the moment, assuming you are using lua
|
|
57
|
+
configuration and Packer for your package management:
|
|
58
|
+
|
|
59
|
+
```lua
|
|
60
|
+
-- file: ~/.config/nvim/init.lua
|
|
61
|
+
|
|
62
|
+
-- Merge this with any existing Packer configuration you might already
|
|
63
|
+
-- have. This loads packer itself, then loads the new `ada.nvim` package.
|
|
64
|
+
require('packer').startup(function(use)
|
|
65
|
+
use(require('mytreesitter.nvim'))
|
|
66
|
+
end)
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
Then create a new file to setup treesitter (or merge with an existing
|
|
70
|
+
configuration of course).
|
|
71
|
+
```lua
|
|
72
|
+
-- file: ~/.config/nvim/mytreesitter.nvim
|
|
73
|
+
|
|
74
|
+
return {
|
|
75
|
+
'nvim-treesitter/nvim-treesitter',
|
|
76
|
+
requires = {
|
|
77
|
+
'nvim-treesitter/nvim-treesitter-textobjects'
|
|
78
|
+
},
|
|
79
|
+
run=function()
|
|
80
|
+
require('nvim-treesitter.install').update({ with_sync = true })
|
|
81
|
+
end,
|
|
82
|
+
config=function()
|
|
83
|
+
|
|
84
|
+
-- Add support for our Ada parser
|
|
85
|
+
|
|
86
|
+
local parsers = require "nvim-treesitter.parsers"
|
|
87
|
+
local parser_config = parsers.get_parser_configs()
|
|
88
|
+
parser_config.ada = {
|
|
89
|
+
install_info = {
|
|
90
|
+
url = "https://github.com/briot/tree-sitter-ada",
|
|
91
|
+
files = {"src/parser.c"},
|
|
92
|
+
generate_requires_npm = false,
|
|
93
|
+
requires_generate_from_grammar = false,
|
|
94
|
+
},
|
|
95
|
+
filetype = "ada",
|
|
96
|
+
}
|
|
97
|
+
end,
|
|
98
|
+
}
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
Finally, we need to install the Ada parser with:
|
|
102
|
+
```vim
|
|
103
|
+
:PackerSync " to install treesitter itself
|
|
104
|
+
:TSInstall ada " to install Ada support
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
However, the above part only installs the parser itself (to generate a syntax
|
|
108
|
+
tree from your source files). We now need to install queries, i.e. pattern
|
|
109
|
+
matching against that tree to provide various capabilities like syntax
|
|
110
|
+
highlighting, folding, indentation, smart textobject selection,...
|
|
111
|
+
|
|
112
|
+
For this, and until we can merge with nvim-treesitter itself, you will have
|
|
113
|
+
to clone this github repository, then copy the `queries/` directory to
|
|
114
|
+
```
|
|
115
|
+
~/.local/share/nvim/site/pack/packer/start/nvim-treesitter/queries/
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
## Usage
|
|
119
|
+
|
|
120
|
+
### Syntax highlighting
|
|
121
|
+
|
|
122
|
+
The above default configuration will replace the default regular
|
|
123
|
+
expressions-based syntax highlighting in vim. Instead, the highlighting is
|
|
124
|
+
based on the tree build every time you type something.
|
|
125
|
+
|
|
126
|
+
The default highlighting looks pretty much like the one from the standard
|
|
127
|
+
Ada mode. However, the tree-based approach potentially opens the door for
|
|
128
|
+
smart highlighting, like "Use a different background color for a subprogram
|
|
129
|
+
specification", "show constant definitions in blue" or other high-level
|
|
130
|
+
approaches.
|
|
131
|
+
|
|
132
|
+
WIP: document how users can do this in their own configuration files.
|
|
133
|
+
The current approach is to modify queries/highlights.scm
|
|
134
|
+
|
|
135
|
+
Potentially (though it seems to be disabled in neovim at the moment), the
|
|
136
|
+
highlighting can also get smarter. Going back to the "show constants in
|
|
137
|
+
blue" example above, the queries/locals.scm file adds a simple approach so
|
|
138
|
+
that references to those constants can point to the definition, and therefore
|
|
139
|
+
use the same blue highlighting.
|
|
140
|
+
|
|
141
|
+
Because neovim also has support for language servers (LSP), it is likely
|
|
142
|
+
better to rely on the language server here.
|
|
143
|
+
|
|
144
|
+
### Block folding
|
|
145
|
+
|
|
146
|
+
If you press <kbd>za</kbd> now, this will toggle the folding of the
|
|
147
|
+
"current block".
|
|
148
|
+
This is defined in queries/folds.scm, and currently knows about package
|
|
149
|
+
specifications, package bodies, subprograms bodies, if statements and loops.
|
|
150
|
+
Other semantic blocks could be added.
|
|
151
|
+
|
|
152
|
+
### Smart Selection
|
|
153
|
+
|
|
154
|
+
The file queries/textobjects.scm defines a function textobjects, so that
|
|
155
|
+
you can now use commands like
|
|
156
|
+
|
|
157
|
+
- <kbd>vaf</kbd> (v)isually select (a) (f)unction or subprogram
|
|
158
|
+
- <kbd>vif</kbd> (v)isually select (i)nside a (f)unction or subprogram
|
|
159
|
+
- <kbd>vai</kbd> (v)isually select (a) (i)f statement (or loop)
|
|
160
|
+
- <kbd>vii</kbd> (v)isually select (i)nside an (i)f statement (or loop)
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
## Development
|
|
164
|
+
|
|
165
|
+
Execute the following commands:
|
|
166
|
+
```bash
|
|
167
|
+
npm install
|
|
168
|
+
npm run test
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
## Documentation
|
|
172
|
+
|
|
173
|
+
The grammar itself is fully described in the file grammar.js.
|
|
174
|
+
When it processes it, TreeSitter generates src/grammar.json, which can be
|
|
175
|
+
converted to a EBNF format via https://github.com/mingodad/plgh/blob/main/json2ebnf.js
|
|
176
|
+
and rendered into a diagram on https://www.bottlecaps.de/rr/ui if you
|
|
177
|
+
prefer graphical visualization (you can also copy-paste from issue #1 a
|
|
178
|
+
pre-processed version of grammar.json).
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
LICENSE.txt
|
|
2
|
+
README.md
|
|
3
|
+
pyproject.toml
|
|
4
|
+
setup.py
|
|
5
|
+
bindings/python/tree_sitter_ada/__init__.py
|
|
6
|
+
bindings/python/tree_sitter_ada/__init__.pyi
|
|
7
|
+
bindings/python/tree_sitter_ada/binding.c
|
|
8
|
+
bindings/python/tree_sitter_ada/py.typed
|
|
9
|
+
bindings/python/tree_sitter_ada.egg-info/PKG-INFO
|
|
10
|
+
bindings/python/tree_sitter_ada.egg-info/SOURCES.txt
|
|
11
|
+
bindings/python/tree_sitter_ada.egg-info/dependency_links.txt
|
|
12
|
+
bindings/python/tree_sitter_ada.egg-info/not-zip-safe
|
|
13
|
+
bindings/python/tree_sitter_ada.egg-info/requires.txt
|
|
14
|
+
bindings/python/tree_sitter_ada.egg-info/top_level.txt
|
|
15
|
+
src/parser.c
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=62.4.0", "wheel"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "tree-sitter-ada"
|
|
7
|
+
description = "Ada grammar for tree-sitter"
|
|
8
|
+
version = "0.1.0"
|
|
9
|
+
keywords = ["incremental", "parsing", "tree-sitter", "ada"]
|
|
10
|
+
classifiers = [
|
|
11
|
+
"Intended Audience :: Developers",
|
|
12
|
+
"Topic :: Software Development :: Compilers",
|
|
13
|
+
"Topic :: Text Processing :: Linguistic",
|
|
14
|
+
"Typing :: Typed",
|
|
15
|
+
]
|
|
16
|
+
authors = [{ name = "Emmanuel Briot" }]
|
|
17
|
+
requires-python = ">=3.10"
|
|
18
|
+
license = { file = "LICENSE.txt" }
|
|
19
|
+
readme = "README.md"
|
|
20
|
+
dependencies = [
|
|
21
|
+
"build>=1.3.0",
|
|
22
|
+
"twine>=6.2.0",
|
|
23
|
+
]
|
|
24
|
+
|
|
25
|
+
[project.urls]
|
|
26
|
+
Homepage = "https://github.com/briot/tree-sitter-ada"
|
|
27
|
+
|
|
28
|
+
[project.optional-dependencies]
|
|
29
|
+
core = ["tree-sitter~=0.24"]
|
|
30
|
+
|
|
31
|
+
[tool.cibuildwheel]
|
|
32
|
+
build = "cp310-*"
|
|
33
|
+
build-frontend = "build"
|