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.0.7.tar.gz (94.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.0.7-cp310-abi3-win_amd64.whl (54.9 kB view details)

Uploaded CPython 3.10+Windows x86-64

tree_sitter_matlab-1.0.7-cp310-abi3-win32.whl (54.0 kB view details)

Uploaded CPython 3.10+Windows x86

tree_sitter_matlab-1.0.7-cp310-abi3-musllinux_1_2_x86_64.whl (80.7 kB view details)

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

tree_sitter_matlab-1.0.7-cp310-abi3-musllinux_1_2_i686.whl (83.4 kB view details)

Uploaded CPython 3.10+musllinux: musl 1.2+ i686

tree_sitter_matlab-1.0.7-cp310-abi3-musllinux_1_2_aarch64.whl (84.0 kB view details)

Uploaded CPython 3.10+musllinux: musl 1.2+ ARM64

tree_sitter_matlab-1.0.7-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (86.1 kB view details)

Uploaded CPython 3.10+manylinux: glibc 2.17+ ARM64

tree_sitter_matlab-1.0.7-cp310-abi3-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (83.8 kB view details)

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

tree_sitter_matlab-1.0.7-cp310-abi3-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (85.2 kB view details)

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

tree_sitter_matlab-1.0.7-cp310-abi3-macosx_11_0_arm64.whl (56.1 kB view details)

Uploaded CPython 3.10+macOS 11.0+ ARM64

File details

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

File metadata

  • Download URL: tree_sitter_matlab-1.0.7.tar.gz
  • Upload date:
  • Size: 94.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.0.7.tar.gz
Algorithm Hash digest
SHA256 126f6bdc4a88f67e88ffd569e6d69dda85e672f99f0f4e86fd86f2f92410697d
MD5 4605efbf9f564d4efa52bdacffaa60b0
BLAKE2b-256 7f1e5c23d5de3c67c9f34030828b520a5e3ced6643875bf11f3b32eebd26e12f

See more details on using hashes here.

Provenance

The following attestation bundles were made for tree_sitter_matlab-1.0.7.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.0.7-cp310-abi3-win_amd64.whl.

File metadata

File hashes

Hashes for tree_sitter_matlab-1.0.7-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 bb69bb56ec57fe471627d39a05d602961c92c1822a6c9246ce3f5f4654509a99
MD5 647e8cbdec59598365774ac9cf904c9b
BLAKE2b-256 68a0876208cfdb2d06021352811017025a363d3d7701f44023d20f16e31d2f35

See more details on using hashes here.

Provenance

The following attestation bundles were made for tree_sitter_matlab-1.0.7-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.0.7-cp310-abi3-win32.whl.

File metadata

File hashes

Hashes for tree_sitter_matlab-1.0.7-cp310-abi3-win32.whl
Algorithm Hash digest
SHA256 057870f59e4c8ed90f2e61551acc2c7fa38f53824a3c894a944c29ee37d7cb76
MD5 fe5d6c8da52420ad8ae71ff49c27881d
BLAKE2b-256 3484d191756fb048a8adf3a1b3c300c63e36d07e7ff67f3bccbda6389e04f545

See more details on using hashes here.

Provenance

The following attestation bundles were made for tree_sitter_matlab-1.0.7-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.0.7-cp310-abi3-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for tree_sitter_matlab-1.0.7-cp310-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 c902ca4b12c347e28b25058f78184ba7f87ae95c3c6df75706cd574f8db7a08f
MD5 98722f57c167fe31186a0cb673a3819e
BLAKE2b-256 30095a7cc2bddc8db53a58a4f3c03b4595e1c483fc561a66b96c534668528755

See more details on using hashes here.

Provenance

The following attestation bundles were made for tree_sitter_matlab-1.0.7-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.0.7-cp310-abi3-musllinux_1_2_i686.whl.

File metadata

File hashes

Hashes for tree_sitter_matlab-1.0.7-cp310-abi3-musllinux_1_2_i686.whl
Algorithm Hash digest
SHA256 8c9004d07822c1896d941bd8163e93b077971174b98380effafe8cf0c22e02c2
MD5 728758e7565bd4274fa009d588b88b60
BLAKE2b-256 fa3657568fe8a0bbb5315ce7659afd14d2582554a9ef993e4eab9e3a44359eaa

See more details on using hashes here.

Provenance

The following attestation bundles were made for tree_sitter_matlab-1.0.7-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.0.7-cp310-abi3-musllinux_1_2_aarch64.whl.

File metadata

File hashes

Hashes for tree_sitter_matlab-1.0.7-cp310-abi3-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 b50e269123b340917091a4e01f6b3e57e93ebaee8c0ad96cfe893323df68761a
MD5 b5d7726d83088ee519066e8073dd9383
BLAKE2b-256 4ed0e81eed36a12260722b786fb4e506609354131d571c43b8500d538be4a926

See more details on using hashes here.

Provenance

The following attestation bundles were made for tree_sitter_matlab-1.0.7-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.0.7-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for tree_sitter_matlab-1.0.7-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 81dc5eb308af6c6de64ba7f7656cd6caf8787f2061d3f7b3aae74e3efb713007
MD5 f5c10f832c102d5ac9242efc6c1cf1f1
BLAKE2b-256 8ad8d9d4712f1fd34c0b2c1fbc863b566ea0c2ed51c6c971b585a43535e93ea6

See more details on using hashes here.

Provenance

The following attestation bundles were made for tree_sitter_matlab-1.0.7-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.0.7-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.0.7-cp310-abi3-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 1bcec156965d5fe87ba722178731491c0bd7944b96a69fb588a577f7a7b3f2a5
MD5 935bfa03f25484b6194051f109eb77c4
BLAKE2b-256 db31ea2a22b97f63db436424c8af8b65d89631afa49dc503e2f68516c35cf07a

See more details on using hashes here.

Provenance

The following attestation bundles were made for tree_sitter_matlab-1.0.7-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.0.7-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.0.7-cp310-abi3-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 ca0a0721d1f14ba0c396d2d88ec32d7968717733dea59d0c1b0783016e4602be
MD5 fd71eb4acbb808a53342ce8b915e6646
BLAKE2b-256 73db6d3ffc5b890b6d5e8e17b581a51dd1edf9e004c04ddde8e5ccffab8a6fcb

See more details on using hashes here.

Provenance

The following attestation bundles were made for tree_sitter_matlab-1.0.7-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.0.7-cp310-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for tree_sitter_matlab-1.0.7-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 1f0b8334d47567ca18dda8d22bb31aa3d960e9d4ee4ede96cf6875640c50884c
MD5 53df67e08c7081b67c465110d8f46a13
BLAKE2b-256 1e85aaf61f34ce6d44ca4cf6489ba9cc3788cfba7aaa525c87b29c973756b43c

See more details on using hashes here.

Provenance

The following attestation bundles were made for tree_sitter_matlab-1.0.7-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