Skip to main content

MATLAB tree-sitter parser

Project description

MATLAB grammar for tree-sitter.

There are screenshots at the end of this README :)

This parser has the objective of generating a tree that is as correct as possible (but sometimes just convenient) with what MATLAB itself executes. It is not intended only for syntax highlight, but also to be used by scripts to whatever it may be needed. In fact, I wrote it because I'm a Neovim/Doom Emacs user and love having text-objects, and was really missing a text object for matrices rows/cells.

Being as correct as possible means that some things are done correctly, for example:

  • Commands are parsed the same way MATLAB does it, by treating arguments as literals, grouping them correctly and only starting comments when allowed. It should perfectly match what MATLAB does.

  • Assignment has its own token, and multiple-variable assignment is NOT an assignment to a matrix (and returning an error is the correct thing to do, as it allows the user to see that something is off with the highlight, meaning something is probably off with the code):

% (assignment (multioutput_variable (identifier) (identifier)) (identifier))
[a,b] = d

% this is WRONG:
[a;b] = d
  • Inside a matrix, 1 + 1 and 1 +1 are different things:
a = 1 + 1 % 2
a = 1 +1 %2
[1 + 1] == [2]
[1 +1]  == [1 1]

Being convenient means that sometimes the difference between what is acceptable and what is not acceptable lives in the semantics, so we can't know. In such cases I just accept semantically wrong but syntax correct things and group them in the same token (first example). I do the same when the overhead of generating a specific token would not really pay off (second example).

  • Function calls and Matrix Indexing are the same in MATLAB: A(1) can be any of them and you cannot tell them apart unless you know for sure what A is referring to. So for convenience I just generate a function_call for them and also for cell indexing A{1}. The "problem" with that is that this is a valid indexing but an invalid function call: A(:). However I don't distinguish at all and say that all of them are function_call.

  • Function definitions, when inside a class, accepts a special syntax for the name of the function, allowing it to be preceded by either get. or set., like function get.name(). I could have a method_definition that would allow that to only be valid in the class context, but I doubt that would be worth it. So any function anywhere can have those and be recognize as correct still. Given the existence of external method definition, maybe that is even the correct thing to do, since we don't know if the current file is inside a special class folder.

Known problems

Newlines, just like whitespaces, are mostly ignored. In the case of spaces, it allows abs( a ) and abs(a) to be described by the same, simple rule. In the case of newlines, it allows many multiline constructs (like, if, while, function) to be expressed the same way.

This creates the undesired side-effect that some constructs, which are not accepted by MATLAB, are correctly parsed, like:

function (
  a
)
end

This, however, is hard to fix. The assumption that newlines are ignored by default is all over the grammar and changing it requires making changes to too many rules, which also make them all more complex and fragile. Therefore, this change won't be made.

Installation

This parser is now the default for the following editors:

  • Emacs: Through the tree-sitter-langs package.
  • Helix: Builtin, now in master and will be available in the next release (whatever comes after 23.05).
  • Neovim: Through the nvim-treesitter plugin.

Screenshots

First Screenshot Second Screenshot Third Screenshot

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tree_sitter_matlab-1.1.0.tar.gz (114.1 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

tree_sitter_matlab-1.1.0-cp310-abi3-win_arm64.whl (59.3 kB view details)

Uploaded CPython 3.10+Windows ARM64

tree_sitter_matlab-1.1.0-cp310-abi3-win_amd64.whl (61.0 kB view details)

Uploaded CPython 3.10+Windows x86-64

tree_sitter_matlab-1.1.0-cp310-abi3-win32.whl (59.8 kB view details)

Uploaded CPython 3.10+Windows x86

tree_sitter_matlab-1.1.0-cp310-abi3-musllinux_1_2_x86_64.whl (89.4 kB view details)

Uploaded CPython 3.10+musllinux: musl 1.2+ x86-64

tree_sitter_matlab-1.1.0-cp310-abi3-musllinux_1_2_i686.whl (91.4 kB view details)

Uploaded CPython 3.10+musllinux: musl 1.2+ i686

tree_sitter_matlab-1.1.0-cp310-abi3-musllinux_1_2_aarch64.whl (92.2 kB view details)

Uploaded CPython 3.10+musllinux: musl 1.2+ ARM64

tree_sitter_matlab-1.1.0-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (94.1 kB view details)

Uploaded CPython 3.10+manylinux: glibc 2.17+ ARM64

tree_sitter_matlab-1.1.0-cp310-abi3-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (92.1 kB view details)

Uploaded CPython 3.10+manylinux: glibc 2.17+ x86-64manylinux: glibc 2.5+ x86-64

tree_sitter_matlab-1.1.0-cp310-abi3-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (93.1 kB view details)

Uploaded CPython 3.10+manylinux: glibc 2.17+ i686manylinux: glibc 2.5+ i686

tree_sitter_matlab-1.1.0-cp310-abi3-macosx_11_0_arm64.whl (62.1 kB view details)

Uploaded CPython 3.10+macOS 11.0+ ARM64

File details

Details for the file tree_sitter_matlab-1.1.0.tar.gz.

File metadata

  • Download URL: tree_sitter_matlab-1.1.0.tar.gz
  • Upload date:
  • Size: 114.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for tree_sitter_matlab-1.1.0.tar.gz
Algorithm Hash digest
SHA256 0499f819055787c6bdb21c591ec42a9ecf0d233c1398e54c2139eadd52a477ef
MD5 e51cce9575efa1c611d63d977aab0eeb
BLAKE2b-256 ec7b003ff0846816a2bb50669eed194b6fd38553aac050708d18c349b39e53bd

See more details on using hashes here.

Provenance

The following attestation bundles were made for tree_sitter_matlab-1.1.0.tar.gz:

Publisher: wheels.yml on acristoffers/tree-sitter-matlab

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file tree_sitter_matlab-1.1.0-cp310-abi3-win_arm64.whl.

File metadata

File hashes

Hashes for tree_sitter_matlab-1.1.0-cp310-abi3-win_arm64.whl
Algorithm Hash digest
SHA256 73c263d02be731a266bfbeaeec0b299d758a9ce35ca0cf954b8cc8e7ee2b329e
MD5 c77c5718b05d3defd8ea8ac9a9ec83ca
BLAKE2b-256 504c7923007c4da65172c43a90f5af329bea9d8d11f8685b5d95c6d717c0b744

See more details on using hashes here.

Provenance

The following attestation bundles were made for tree_sitter_matlab-1.1.0-cp310-abi3-win_arm64.whl:

Publisher: wheels.yml on acristoffers/tree-sitter-matlab

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file tree_sitter_matlab-1.1.0-cp310-abi3-win_amd64.whl.

File metadata

File hashes

Hashes for tree_sitter_matlab-1.1.0-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 202cd57c0e8b35ae1c6d5dcd1fc191d48c789dda0a4bc638084c2832bd74b415
MD5 47f1630909bb8b52115cddae996d0720
BLAKE2b-256 23099037e862f255c4fe57f23dcce884557f6c6addeccb2ae6ea5a15ecd87a2e

See more details on using hashes here.

Provenance

The following attestation bundles were made for tree_sitter_matlab-1.1.0-cp310-abi3-win_amd64.whl:

Publisher: wheels.yml on acristoffers/tree-sitter-matlab

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file tree_sitter_matlab-1.1.0-cp310-abi3-win32.whl.

File metadata

File hashes

Hashes for tree_sitter_matlab-1.1.0-cp310-abi3-win32.whl
Algorithm Hash digest
SHA256 c849efe341a5d0825344ce65924991d89534dfab6b8105ec17a3ffbff891f0f4
MD5 ad65d57f203a6525d4868266f93f3ea6
BLAKE2b-256 7cfbaa26394d10a79ab225b893c1c92834c53325bcd26fa68c0585dbeed35b4b

See more details on using hashes here.

Provenance

The following attestation bundles were made for tree_sitter_matlab-1.1.0-cp310-abi3-win32.whl:

Publisher: wheels.yml on acristoffers/tree-sitter-matlab

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file tree_sitter_matlab-1.1.0-cp310-abi3-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for tree_sitter_matlab-1.1.0-cp310-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 9b316e308468f5b4dd42ca0fb929542ed08e68216864ee80f38eabfe6f65be1f
MD5 142629418e2a456eb12d71e1726b6d19
BLAKE2b-256 caca5392dd98db12b5e7770feb9910b83ca05853397a85d58e644633640249b2

See more details on using hashes here.

Provenance

The following attestation bundles were made for tree_sitter_matlab-1.1.0-cp310-abi3-musllinux_1_2_x86_64.whl:

Publisher: wheels.yml on acristoffers/tree-sitter-matlab

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file tree_sitter_matlab-1.1.0-cp310-abi3-musllinux_1_2_i686.whl.

File metadata

File hashes

Hashes for tree_sitter_matlab-1.1.0-cp310-abi3-musllinux_1_2_i686.whl
Algorithm Hash digest
SHA256 75d29d6ae9a5519c6d22a1b16635b307ef81d7a6d9c03f0820218d8d6de9534f
MD5 3d2b61a5806bd94b5cb06e6c12354b01
BLAKE2b-256 32926d62ce5a1d202fac5d27cd75c5313503e5de335dbd93cf7e9920cc626263

See more details on using hashes here.

Provenance

The following attestation bundles were made for tree_sitter_matlab-1.1.0-cp310-abi3-musllinux_1_2_i686.whl:

Publisher: wheels.yml on acristoffers/tree-sitter-matlab

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file tree_sitter_matlab-1.1.0-cp310-abi3-musllinux_1_2_aarch64.whl.

File metadata

File hashes

Hashes for tree_sitter_matlab-1.1.0-cp310-abi3-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 2f3a25fcf76761240fe12532b215027c4d5344cc8bc9d0e98269a78452c4d561
MD5 0d98486e0073927a5f39639fbb04585d
BLAKE2b-256 f647e27268f8524a55e4be9ebb16c5f182a6e2cc6c4069102763a31ff8d9b581

See more details on using hashes here.

Provenance

The following attestation bundles were made for tree_sitter_matlab-1.1.0-cp310-abi3-musllinux_1_2_aarch64.whl:

Publisher: wheels.yml on acristoffers/tree-sitter-matlab

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file tree_sitter_matlab-1.1.0-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for tree_sitter_matlab-1.1.0-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 50c6149bd8814c08956cfff709194a8288920b9afa019314a27d3a5a861d7de3
MD5 0584bbec16b5c28e91be684b4fb152d4
BLAKE2b-256 5751c52c6a3744e434c667352082bbf18e269cbc1101d8395e836889e42b7ac6

See more details on using hashes here.

Provenance

The following attestation bundles were made for tree_sitter_matlab-1.1.0-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl:

Publisher: wheels.yml on acristoffers/tree-sitter-matlab

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file tree_sitter_matlab-1.1.0-cp310-abi3-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for tree_sitter_matlab-1.1.0-cp310-abi3-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 668a49ff69db86974bca5f59e654de60b0fc42fd2ca6fecbffbf3a5ec9ca9b8b
MD5 0956ea784c333afb4df3d58e36c3277a
BLAKE2b-256 e7c05a4e2a9ed33c789c7d0c926d2baefe923eb0deead461047004914e465598

See more details on using hashes here.

Provenance

The following attestation bundles were made for tree_sitter_matlab-1.1.0-cp310-abi3-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: wheels.yml on acristoffers/tree-sitter-matlab

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file tree_sitter_matlab-1.1.0-cp310-abi3-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl.

File metadata

File hashes

Hashes for tree_sitter_matlab-1.1.0-cp310-abi3-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 ed9f39535255629687e461fb361fb7eda73d090167162f23724795300d24c253
MD5 d8f3156b881ff189ce7e65b29c43201e
BLAKE2b-256 1e60f82acae0ad18970935bbb395f07a6d2202aa364cd4f54a1ba54cbf568e12

See more details on using hashes here.

Provenance

The following attestation bundles were made for tree_sitter_matlab-1.1.0-cp310-abi3-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl:

Publisher: wheels.yml on acristoffers/tree-sitter-matlab

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file tree_sitter_matlab-1.1.0-cp310-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for tree_sitter_matlab-1.1.0-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 0ee228dfc991f275ab33b181700652d2e66351d32f982f273998989b8293b639
MD5 050fcdc2611f07f7c0ee2c1b67016e38
BLAKE2b-256 2e4855e61d0cf6f9db11ea4194989d41a8fc702f4a838dd58259a70459633b5a

See more details on using hashes here.

Provenance

The following attestation bundles were made for tree_sitter_matlab-1.1.0-cp310-abi3-macosx_11_0_arm64.whl:

Publisher: wheels.yml on acristoffers/tree-sitter-matlab

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page