tree-sitter-matlab 1.0.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.
@@ -0,0 +1,19 @@
1
+ Copyright (c) 2023 Álan Crístoffer
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
4
+ this software and associated documentation files (the "Software"), to deal in
5
+ the Software without restriction, including without limitation the rights to
6
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
7
+ of the Software, and to permit persons to whom the Software is furnished to do
8
+ so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in all
11
+ copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19
+ SOFTWARE.
@@ -0,0 +1,93 @@
1
+ Metadata-Version: 2.1
2
+ Name: tree-sitter-matlab
3
+ Version: 1.0.0
4
+ Summary: Matlab grammar for tree-sitter
5
+ License: MIT
6
+ Project-URL: Homepage, https://github.com/tree-sitter/tree-sitter-matlab
7
+ Keywords: incremental,parsing,tree-sitter,matlab
8
+ Classifier: Intended Audience :: Developers
9
+ Classifier: License :: OSI Approved :: MIT License
10
+ Classifier: Topic :: Software Development :: Compilers
11
+ Classifier: Topic :: Text Processing :: Linguistic
12
+ Classifier: Typing :: Typed
13
+ Requires-Python: >=3.8
14
+ Description-Content-Type: text/markdown
15
+ License-File: LICENSE
16
+ Provides-Extra: core
17
+ Requires-Dist: tree-sitter~=0.21; extra == "core"
18
+
19
+ # MATLAB grammar for tree-sitter.
20
+
21
+ There are screenshots at the end of this README :)
22
+
23
+ This parser has the objective of generating a tree that is as correct as
24
+ possible (but sometimes just convenient) with what MATLAB itself executes. It
25
+ is not intended only for syntax highlight, but also to be used by scripts to
26
+ whatever it may be needed. In fact, I wrote it because I'm a Neovim/Doom Emacs
27
+ user and love having text-objects, and was really missing a text object for
28
+ matrices rows/cells.
29
+
30
+ Being as correct as possible means that some things are done correctly, for
31
+ example:
32
+
33
+ - Commands are parsed the same way MATLAB does it, by treating arguments as
34
+ literals, grouping them correctly and only starting comments when allowed. It
35
+ should perfectly match what MATLAB does.
36
+
37
+ - Assignment has its own token, and multiple-variable assignment is NOT an
38
+ assignment to a matrix (and returning an error is the correct thing to do, as
39
+ it allows the user to see that something is off with the highlight, meaning
40
+ something is probably off with the code):
41
+
42
+ ```matlab
43
+ % (assignment (multioutput_variable (identifier) (identifier)) (identifier))
44
+ [a,b] = d
45
+
46
+ % this is WRONG:
47
+ [a;b] = d
48
+ ```
49
+
50
+ - Inside a matrix, `1 + 1` and `1 +1` are different things:
51
+
52
+ ```matlab
53
+ a = 1 + 1 % 2
54
+ a = 1 +1 %2
55
+ [1 + 1] == [2]
56
+ [1 +1] == [1 1]
57
+ ```
58
+
59
+ Being convenient means that sometimes the difference between what is acceptable
60
+ and what is not acceptable lives in the semantics, so we can't know. In such
61
+ cases I just accept semantically wrong but syntax correct things and group them
62
+ in the same token (first example). I do the same when the overhead of
63
+ generating a specific token would not really pay off (second example).
64
+
65
+ - Function calls and Matrix Indexing are the same in MATLAB: `A(1)` can be any
66
+ of them and you cannot tell them apart unless you know for sure what `A` is
67
+ referring to. So for convenience I just generate a `function_call` for them and
68
+ also for cell indexing `A{1}`. The "problem" with that is that this is a valid
69
+ indexing but an invalid function call: `A(:)`. However I don't distinguish at
70
+ all and say that all of them are `function_call`.
71
+
72
+ - Function definitions, when inside a class, accepts a special syntax for the
73
+ name of the function, allowing it to be preceded by either `get.` or `set.`,
74
+ like `function get.name()`. I could have a `method_definition` that would allow
75
+ that to only be valid in the class context, but I doubt that would be worth it.
76
+ So any function anywhere can have those and be recognize as correct still.
77
+ Given the existence of external method definition, maybe that is even the
78
+ correct thing to do, since we don't know if the current file is inside a
79
+ special class folder.
80
+
81
+ # Installation
82
+
83
+ This parser is now the default for the following editors:
84
+
85
+ - Emacs: Through the `tree-sitter-langs` package.
86
+ - Helix: Builtin, now in master and will be available in the next release (whatever comes after 23.05).
87
+ - Neovim: Through the `nvim-treesitter` plugin.
88
+
89
+ # Screenshots
90
+
91
+ ![First Screenshot](https://raw.githubusercontent.com/acristoffers/tree-sitter-matlab/screenshots/s1.png)
92
+ ![Second Screenshot](https://raw.githubusercontent.com/acristoffers/tree-sitter-matlab/screenshots/s2.png)
93
+ ![Third Screenshot](https://raw.githubusercontent.com/acristoffers/tree-sitter-matlab/screenshots/s3.png)
@@ -0,0 +1,75 @@
1
+ # MATLAB grammar for tree-sitter.
2
+
3
+ There are screenshots at the end of this README :)
4
+
5
+ This parser has the objective of generating a tree that is as correct as
6
+ possible (but sometimes just convenient) with what MATLAB itself executes. It
7
+ is not intended only for syntax highlight, but also to be used by scripts to
8
+ whatever it may be needed. In fact, I wrote it because I'm a Neovim/Doom Emacs
9
+ user and love having text-objects, and was really missing a text object for
10
+ matrices rows/cells.
11
+
12
+ Being as correct as possible means that some things are done correctly, for
13
+ example:
14
+
15
+ - Commands are parsed the same way MATLAB does it, by treating arguments as
16
+ literals, grouping them correctly and only starting comments when allowed. It
17
+ should perfectly match what MATLAB does.
18
+
19
+ - Assignment has its own token, and multiple-variable assignment is NOT an
20
+ assignment to a matrix (and returning an error is the correct thing to do, as
21
+ it allows the user to see that something is off with the highlight, meaning
22
+ something is probably off with the code):
23
+
24
+ ```matlab
25
+ % (assignment (multioutput_variable (identifier) (identifier)) (identifier))
26
+ [a,b] = d
27
+
28
+ % this is WRONG:
29
+ [a;b] = d
30
+ ```
31
+
32
+ - Inside a matrix, `1 + 1` and `1 +1` are different things:
33
+
34
+ ```matlab
35
+ a = 1 + 1 % 2
36
+ a = 1 +1 %2
37
+ [1 + 1] == [2]
38
+ [1 +1] == [1 1]
39
+ ```
40
+
41
+ Being convenient means that sometimes the difference between what is acceptable
42
+ and what is not acceptable lives in the semantics, so we can't know. In such
43
+ cases I just accept semantically wrong but syntax correct things and group them
44
+ in the same token (first example). I do the same when the overhead of
45
+ generating a specific token would not really pay off (second example).
46
+
47
+ - Function calls and Matrix Indexing are the same in MATLAB: `A(1)` can be any
48
+ of them and you cannot tell them apart unless you know for sure what `A` is
49
+ referring to. So for convenience I just generate a `function_call` for them and
50
+ also for cell indexing `A{1}`. The "problem" with that is that this is a valid
51
+ indexing but an invalid function call: `A(:)`. However I don't distinguish at
52
+ all and say that all of them are `function_call`.
53
+
54
+ - Function definitions, when inside a class, accepts a special syntax for the
55
+ name of the function, allowing it to be preceded by either `get.` or `set.`,
56
+ like `function get.name()`. I could have a `method_definition` that would allow
57
+ that to only be valid in the class context, but I doubt that would be worth it.
58
+ So any function anywhere can have those and be recognize as correct still.
59
+ Given the existence of external method definition, maybe that is even the
60
+ correct thing to do, since we don't know if the current file is inside a
61
+ special class folder.
62
+
63
+ # Installation
64
+
65
+ This parser is now the default for the following editors:
66
+
67
+ - Emacs: Through the `tree-sitter-langs` package.
68
+ - Helix: Builtin, now in master and will be available in the next release (whatever comes after 23.05).
69
+ - Neovim: Through the `nvim-treesitter` plugin.
70
+
71
+ # Screenshots
72
+
73
+ ![First Screenshot](https://raw.githubusercontent.com/acristoffers/tree-sitter-matlab/screenshots/s1.png)
74
+ ![Second Screenshot](https://raw.githubusercontent.com/acristoffers/tree-sitter-matlab/screenshots/s2.png)
75
+ ![Third Screenshot](https://raw.githubusercontent.com/acristoffers/tree-sitter-matlab/screenshots/s3.png)
@@ -0,0 +1,5 @@
1
+ "Matlab grammar for tree-sitter"
2
+
3
+ from ._binding import language
4
+
5
+ __all__ = ["language"]
@@ -0,0 +1 @@
1
+ def language() -> int: ...
@@ -0,0 +1,27 @@
1
+ #include <Python.h>
2
+
3
+ typedef struct TSLanguage TSLanguage;
4
+
5
+ TSLanguage *tree_sitter_matlab(void);
6
+
7
+ static PyObject* _binding_language(PyObject *self, PyObject *args) {
8
+ return PyLong_FromVoidPtr(tree_sitter_matlab());
9
+ }
10
+
11
+ static PyMethodDef methods[] = {
12
+ {"language", _binding_language, METH_NOARGS,
13
+ "Get the tree-sitter language for this grammar."},
14
+ {NULL, NULL, 0, NULL}
15
+ };
16
+
17
+ static struct PyModuleDef module = {
18
+ .m_base = PyModuleDef_HEAD_INIT,
19
+ .m_name = "_binding",
20
+ .m_doc = NULL,
21
+ .m_size = -1,
22
+ .m_methods = methods
23
+ };
24
+
25
+ PyMODINIT_FUNC PyInit__binding(void) {
26
+ return PyModule_Create(&module);
27
+ }
@@ -0,0 +1,93 @@
1
+ Metadata-Version: 2.1
2
+ Name: tree-sitter-matlab
3
+ Version: 1.0.0
4
+ Summary: Matlab grammar for tree-sitter
5
+ License: MIT
6
+ Project-URL: Homepage, https://github.com/tree-sitter/tree-sitter-matlab
7
+ Keywords: incremental,parsing,tree-sitter,matlab
8
+ Classifier: Intended Audience :: Developers
9
+ Classifier: License :: OSI Approved :: MIT License
10
+ Classifier: Topic :: Software Development :: Compilers
11
+ Classifier: Topic :: Text Processing :: Linguistic
12
+ Classifier: Typing :: Typed
13
+ Requires-Python: >=3.8
14
+ Description-Content-Type: text/markdown
15
+ License-File: LICENSE
16
+ Provides-Extra: core
17
+ Requires-Dist: tree-sitter~=0.21; extra == "core"
18
+
19
+ # MATLAB grammar for tree-sitter.
20
+
21
+ There are screenshots at the end of this README :)
22
+
23
+ This parser has the objective of generating a tree that is as correct as
24
+ possible (but sometimes just convenient) with what MATLAB itself executes. It
25
+ is not intended only for syntax highlight, but also to be used by scripts to
26
+ whatever it may be needed. In fact, I wrote it because I'm a Neovim/Doom Emacs
27
+ user and love having text-objects, and was really missing a text object for
28
+ matrices rows/cells.
29
+
30
+ Being as correct as possible means that some things are done correctly, for
31
+ example:
32
+
33
+ - Commands are parsed the same way MATLAB does it, by treating arguments as
34
+ literals, grouping them correctly and only starting comments when allowed. It
35
+ should perfectly match what MATLAB does.
36
+
37
+ - Assignment has its own token, and multiple-variable assignment is NOT an
38
+ assignment to a matrix (and returning an error is the correct thing to do, as
39
+ it allows the user to see that something is off with the highlight, meaning
40
+ something is probably off with the code):
41
+
42
+ ```matlab
43
+ % (assignment (multioutput_variable (identifier) (identifier)) (identifier))
44
+ [a,b] = d
45
+
46
+ % this is WRONG:
47
+ [a;b] = d
48
+ ```
49
+
50
+ - Inside a matrix, `1 + 1` and `1 +1` are different things:
51
+
52
+ ```matlab
53
+ a = 1 + 1 % 2
54
+ a = 1 +1 %2
55
+ [1 + 1] == [2]
56
+ [1 +1] == [1 1]
57
+ ```
58
+
59
+ Being convenient means that sometimes the difference between what is acceptable
60
+ and what is not acceptable lives in the semantics, so we can't know. In such
61
+ cases I just accept semantically wrong but syntax correct things and group them
62
+ in the same token (first example). I do the same when the overhead of
63
+ generating a specific token would not really pay off (second example).
64
+
65
+ - Function calls and Matrix Indexing are the same in MATLAB: `A(1)` can be any
66
+ of them and you cannot tell them apart unless you know for sure what `A` is
67
+ referring to. So for convenience I just generate a `function_call` for them and
68
+ also for cell indexing `A{1}`. The "problem" with that is that this is a valid
69
+ indexing but an invalid function call: `A(:)`. However I don't distinguish at
70
+ all and say that all of them are `function_call`.
71
+
72
+ - Function definitions, when inside a class, accepts a special syntax for the
73
+ name of the function, allowing it to be preceded by either `get.` or `set.`,
74
+ like `function get.name()`. I could have a `method_definition` that would allow
75
+ that to only be valid in the class context, but I doubt that would be worth it.
76
+ So any function anywhere can have those and be recognize as correct still.
77
+ Given the existence of external method definition, maybe that is even the
78
+ correct thing to do, since we don't know if the current file is inside a
79
+ special class folder.
80
+
81
+ # Installation
82
+
83
+ This parser is now the default for the following editors:
84
+
85
+ - Emacs: Through the `tree-sitter-langs` package.
86
+ - Helix: Builtin, now in master and will be available in the next release (whatever comes after 23.05).
87
+ - Neovim: Through the `nvim-treesitter` plugin.
88
+
89
+ # Screenshots
90
+
91
+ ![First Screenshot](https://raw.githubusercontent.com/acristoffers/tree-sitter-matlab/screenshots/s1.png)
92
+ ![Second Screenshot](https://raw.githubusercontent.com/acristoffers/tree-sitter-matlab/screenshots/s2.png)
93
+ ![Third Screenshot](https://raw.githubusercontent.com/acristoffers/tree-sitter-matlab/screenshots/s3.png)
@@ -0,0 +1,16 @@
1
+ LICENSE
2
+ README.md
3
+ pyproject.toml
4
+ setup.py
5
+ bindings/python/tree_sitter_matlab/__init__.py
6
+ bindings/python/tree_sitter_matlab/__init__.pyi
7
+ bindings/python/tree_sitter_matlab/binding.c
8
+ bindings/python/tree_sitter_matlab/py.typed
9
+ bindings/python/tree_sitter_matlab.egg-info/PKG-INFO
10
+ bindings/python/tree_sitter_matlab.egg-info/SOURCES.txt
11
+ bindings/python/tree_sitter_matlab.egg-info/dependency_links.txt
12
+ bindings/python/tree_sitter_matlab.egg-info/not-zip-safe
13
+ bindings/python/tree_sitter_matlab.egg-info/requires.txt
14
+ bindings/python/tree_sitter_matlab.egg-info/top_level.txt
15
+ src/parser.c
16
+ src/scanner.c
@@ -0,0 +1,2 @@
1
+ _binding
2
+ tree_sitter_matlab
@@ -0,0 +1,29 @@
1
+ [build-system]
2
+ requires = ["setuptools>=42", "wheel"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "tree-sitter-matlab"
7
+ description = "Matlab grammar for tree-sitter"
8
+ version = "1.0.0"
9
+ keywords = ["incremental", "parsing", "tree-sitter", "matlab"]
10
+ classifiers = [
11
+ "Intended Audience :: Developers",
12
+ "License :: OSI Approved :: MIT License",
13
+ "Topic :: Software Development :: Compilers",
14
+ "Topic :: Text Processing :: Linguistic",
15
+ "Typing :: Typed"
16
+ ]
17
+ requires-python = ">=3.8"
18
+ license.text = "MIT"
19
+ readme = "README.md"
20
+
21
+ [project.urls]
22
+ Homepage = "https://github.com/tree-sitter/tree-sitter-matlab"
23
+
24
+ [project.optional-dependencies]
25
+ core = ["tree-sitter~=0.21"]
26
+
27
+ [tool.cibuildwheel]
28
+ build = "cp38-*"
29
+ build-frontend = "build"
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,60 @@
1
+ from os.path import isdir, join
2
+ from platform import system
3
+
4
+ from setuptools import Extension, find_packages, setup
5
+ from setuptools.command.build import build
6
+ from wheel.bdist_wheel import bdist_wheel
7
+
8
+
9
+ class Build(build):
10
+ def run(self):
11
+ if isdir("queries"):
12
+ dest = join(self.build_lib, "tree_sitter_matlab", "queries")
13
+ self.copy_tree("queries", dest)
14
+ super().run()
15
+
16
+
17
+ class BdistWheel(bdist_wheel):
18
+ def get_tag(self):
19
+ python, abi, platform = super().get_tag()
20
+ if python.startswith("cp"):
21
+ python, abi = "cp38", "abi3"
22
+ return python, abi, platform
23
+
24
+
25
+ setup(
26
+ packages=find_packages("bindings/python"),
27
+ package_dir={"": "bindings/python"},
28
+ package_data={
29
+ "tree_sitter_matlab": ["*.pyi", "py.typed"],
30
+ "tree_sitter_matlab.queries": ["*.scm"],
31
+ },
32
+ ext_package="tree_sitter_matlab",
33
+ ext_modules=[
34
+ Extension(
35
+ name="_binding",
36
+ sources=[
37
+ "bindings/python/tree_sitter_matlab/binding.c",
38
+ "src/parser.c",
39
+ "src/scanner.c"
40
+ ],
41
+ extra_compile_args=[
42
+ "-std=c11",
43
+ ] if system() != "Windows" else [
44
+ "/std:c11",
45
+ "/utf-8",
46
+ ],
47
+ define_macros=[
48
+ ("Py_LIMITED_API", "0x03080000"),
49
+ ("PY_SSIZE_T_CLEAN", None)
50
+ ],
51
+ include_dirs=["src"],
52
+ py_limited_api=True,
53
+ )
54
+ ],
55
+ cmdclass={
56
+ "build": Build,
57
+ "bdist_wheel": BdistWheel
58
+ },
59
+ zip_safe=False
60
+ )