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.8.tar.gz (98.7 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.8-cp310-abi3-win_amd64.whl (55.4 kB view details)

Uploaded CPython 3.10+Windows x86-64

tree_sitter_matlab-1.0.8-cp310-abi3-win32.whl (54.4 kB view details)

Uploaded CPython 3.10+Windows x86

tree_sitter_matlab-1.0.8-cp310-abi3-musllinux_1_2_x86_64.whl (81.0 kB view details)

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

tree_sitter_matlab-1.0.8-cp310-abi3-musllinux_1_2_i686.whl (83.5 kB view details)

Uploaded CPython 3.10+musllinux: musl 1.2+ i686

tree_sitter_matlab-1.0.8-cp310-abi3-musllinux_1_2_aarch64.whl (84.1 kB view details)

Uploaded CPython 3.10+musllinux: musl 1.2+ ARM64

tree_sitter_matlab-1.0.8-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (86.2 kB view details)

Uploaded CPython 3.10+manylinux: glibc 2.17+ ARM64

tree_sitter_matlab-1.0.8-cp310-abi3-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (83.9 kB view details)

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

tree_sitter_matlab-1.0.8-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.8-cp310-abi3-macosx_11_0_arm64.whl (56.6 kB view details)

Uploaded CPython 3.10+macOS 11.0+ ARM64

File details

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

File metadata

  • Download URL: tree_sitter_matlab-1.0.8.tar.gz
  • Upload date:
  • Size: 98.7 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.8.tar.gz
Algorithm Hash digest
SHA256 ada6db58f11fb594aa554d8c6d498bdbc3495090ca38f905e589d6ca5c98b598
MD5 89bb87bf90d6898cbda8d1ffeae1ae68
BLAKE2b-256 15773d4bcb3fb782974a08fa8c7c7cfbf62791cf761a69880c47db3d140f7692

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for tree_sitter_matlab-1.0.8-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 9db37338f621be5b2d17787c924e200fea7b71921f705bfa5e2787d65881a32e
MD5 ed20b53fd9981a947dbd763fdeb34166
BLAKE2b-256 39e959629b45b1b3a4faf506a339654dc5991e854bc70fd8429d60d8f1598cbb

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for tree_sitter_matlab-1.0.8-cp310-abi3-win32.whl
Algorithm Hash digest
SHA256 6d75d53e72dc82fca074233f8629a631bb349826be118a10bc0efbaa7a47be3f
MD5 fa41be0f8ec9f48b61e595d7f4ec1cb1
BLAKE2b-256 bb9e8a7b921b369422ca3017b8529d53b23d758c60c0c18adfb50230d2615115

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for tree_sitter_matlab-1.0.8-cp310-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 ec4a536dd8374f4e1dcc143f1fd62441c6c480f4e3a0d37f8f7e3750255f334c
MD5 c8d1f2ec553bd654faa123f7ea7acf47
BLAKE2b-256 4beb52dd67a747b99503e7d18e54e7355d5ebe8c46e7fc23d3b7c4512483a107

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for tree_sitter_matlab-1.0.8-cp310-abi3-musllinux_1_2_i686.whl
Algorithm Hash digest
SHA256 999edba42c02a04060ce139a1866aef4bc8832c596d653bab81b733bc37fd33e
MD5 1c12e104a4dc0f97513f4f7e21400780
BLAKE2b-256 8cfd7cc250b2468be8cca4c911492abf9c4b70c8b9349276ae7e1e50558f4916

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for tree_sitter_matlab-1.0.8-cp310-abi3-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 57b1f4c12444f4ab27467b07117f336c227a3ac94a35b3bc41f5f675b3feaf51
MD5 049a59f876cc898bd784eb73a94e84a5
BLAKE2b-256 89140bac1b94fed4940800ba34a543d23b1bd25280011db0252004b2d5a744b7

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for tree_sitter_matlab-1.0.8-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 55a77586a9e3f01cadd24eadc5ffbab6ceb82b20ef0561bff8ae8ec11e72a7f6
MD5 2aa8b441566aecadac42fb6e161beee8
BLAKE2b-256 00ec0e24c9a32984167e8e0ee9a72dffb930b9033d8ffbbfc7524b6704f48038

See more details on using hashes here.

Provenance

The following attestation bundles were made for tree_sitter_matlab-1.0.8-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.8-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.8-cp310-abi3-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 2af563a2c81eca728294a9ec82bbc06deb0f20b6a8c864851638be58bb6cfa42
MD5 cd8735bfda1d4ec6e3be1ee97bae5bf3
BLAKE2b-256 b920968495131e5dfc0d4ab2ba0d9aa20454048f6fd0d224760d69dc411763ec

See more details on using hashes here.

Provenance

The following attestation bundles were made for tree_sitter_matlab-1.0.8-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.8-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.8-cp310-abi3-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 f769213e8c37c44b03a9f4d76b40bef7dbade98b10c61e97056ea22d63d2424f
MD5 88140dc0496cbab9af1ac0f6fb8b120d
BLAKE2b-256 6f0176c050798f9980a74069306410259e4ed6cf6ff1f1b53b09ad661cbeebbf

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for tree_sitter_matlab-1.0.8-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 296fb87fb1032c7a4b000e7d805139aea6e5288b2d1f96f03e04cf8d716a320b
MD5 b3da25e53252e5683ea0e9286f5ced55
BLAKE2b-256 77851712e366618cf3470085dd4162e2c199953b7eab614a133a1fbcad0dbedd

See more details on using hashes here.

Provenance

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