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.2.7.tar.gz (175.9 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.2.7-cp310-abi3-win_arm64.whl (83.5 kB view details)

Uploaded CPython 3.10+Windows ARM64

tree_sitter_matlab-1.2.7-cp310-abi3-win_amd64.whl (85.1 kB view details)

Uploaded CPython 3.10+Windows x86-64

tree_sitter_matlab-1.2.7-cp310-abi3-win32.whl (84.2 kB view details)

Uploaded CPython 3.10+Windows x86

tree_sitter_matlab-1.2.7-cp310-abi3-musllinux_1_2_x86_64.whl (115.6 kB view details)

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

tree_sitter_matlab-1.2.7-cp310-abi3-musllinux_1_2_i686.whl (117.7 kB view details)

Uploaded CPython 3.10+musllinux: musl 1.2+ i686

tree_sitter_matlab-1.2.7-cp310-abi3-musllinux_1_2_aarch64.whl (119.2 kB view details)

Uploaded CPython 3.10+musllinux: musl 1.2+ ARM64

tree_sitter_matlab-1.2.7-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (121.0 kB view details)

Uploaded CPython 3.10+manylinux: glibc 2.17+ ARM64

tree_sitter_matlab-1.2.7-cp310-abi3-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (118.4 kB view details)

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

tree_sitter_matlab-1.2.7-cp310-abi3-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (119.6 kB view details)

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

tree_sitter_matlab-1.2.7-cp310-abi3-macosx_11_0_arm64.whl (89.3 kB view details)

Uploaded CPython 3.10+macOS 11.0+ ARM64

File details

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

File metadata

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

File hashes

Hashes for tree_sitter_matlab-1.2.7.tar.gz
Algorithm Hash digest
SHA256 27069da7843299f73e8ea0585a99332f66f12b2de3efea5d093812721743a1ec
MD5 33bfc4f47dee9b4ebc33f15827799800
BLAKE2b-256 79ce7e18d1d748a6e9a1358ef97dafa21d41f40de80a159f51ec8891cc651a8e

See more details on using hashes here.

Provenance

The following attestation bundles were made for tree_sitter_matlab-1.2.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.2.7-cp310-abi3-win_arm64.whl.

File metadata

File hashes

Hashes for tree_sitter_matlab-1.2.7-cp310-abi3-win_arm64.whl
Algorithm Hash digest
SHA256 40e6a3e4e987f8eba873d05fc1f3dcfaf99c187130847693ee407a6a375e6557
MD5 321e2b0a6d19be75cc86fe9a18e4f1e1
BLAKE2b-256 5562497727e2d69186705102d0f6d9c7d96c91383dc306c63be534b5fb4e305a

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for tree_sitter_matlab-1.2.7-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 b397bb7a40bd988bea0301da37cf70241350b8ff18f47d8b4e950ef9225a766a
MD5 dce523add76ef16c5a929146c3c46b02
BLAKE2b-256 8e61d289d68923568ff9471d966770e1e7fa461cf7f88b189c0ba324b3b2fce8

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for tree_sitter_matlab-1.2.7-cp310-abi3-win32.whl
Algorithm Hash digest
SHA256 77db4d089a6844104eb6072e3e0df363b761f86a8f094bc41972c619452e5960
MD5 c986f179d839e094149e2f83275a0a4b
BLAKE2b-256 3f77d6fbbeba9f74d5d6841769f8da619063e18ea916e82e5ba73ecb7f1a3a57

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for tree_sitter_matlab-1.2.7-cp310-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 d6b80825ee81e0188cde3a0e2e48cb53119380ea22b0ac48bd8330835f08cb62
MD5 60dc084996c369bc7c7f713dd7d88f4d
BLAKE2b-256 4a87ad29f89b9b9728792f9dbab9609ca4829ee6f202403cad1f336fbd9ad508

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for tree_sitter_matlab-1.2.7-cp310-abi3-musllinux_1_2_i686.whl
Algorithm Hash digest
SHA256 dd65a0913f1cdc75506a85c18107c341f2138f631e508e5560244a711492d8b4
MD5 b8308389cd8749256264ef97a8cc9d48
BLAKE2b-256 9d5af7467ff7b37d3742b53d3e0276e69c5e08ae45ddc075526ddd4d89d8172b

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for tree_sitter_matlab-1.2.7-cp310-abi3-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 2b50fc6e2f861e86f4cd97e5e9b6b823f50244f186e3db9f554029a536d9092f
MD5 a70f1cf74eb3a2ee110613029f6f0a3e
BLAKE2b-256 47ce281cdbedd936cd629e1048a8854aba8fccc788fb60ff469d9155b9b98355

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for tree_sitter_matlab-1.2.7-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 f7e7d880a7d53a25b487f9cc5b7460161936b30a0ae35dea69a0ce0bc0b5f7af
MD5 1b5a35bf12c1bb690dde881a4d4d1774
BLAKE2b-256 08b67779444fd0e625617aabd9e5298bd6ffbfddef7a0ca33b1b47f72d89face

See more details on using hashes here.

Provenance

The following attestation bundles were made for tree_sitter_matlab-1.2.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.2.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.2.7-cp310-abi3-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 ea8871a174f991d81530a8c36ace0eda85ab50224307285eee2457e437cdbfa0
MD5 946d4ed0ea322aa9c7ad945bfbce09fe
BLAKE2b-256 e206dce2ad39ab5cfce6c1619d1c0981d30ee34c15e28edeb5abb30cb991ea0e

See more details on using hashes here.

Provenance

The following attestation bundles were made for tree_sitter_matlab-1.2.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.2.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.2.7-cp310-abi3-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 1e8508a857f4fafd5a5ce2fcd698ed540679b29ff7fa48df098f3da9411d72bb
MD5 bb3db9f3358352a73b3b3ae30ea4ee0c
BLAKE2b-256 8f31792906f0dc2cc7d1057e8bb985c17d0c2accfa4a75ea2c135ac8e8bc5aa6

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for tree_sitter_matlab-1.2.7-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 e2d17e8ebd0057bd30751df2c716fc1ac0009c4f2e99696b3abc3a582ae28715
MD5 c6aca60628b9089b84f190defa6ad610
BLAKE2b-256 b095ea13e716eb6ed5439c6c9e1e46d2110eed9a13171074920bfb3940bd03d4

See more details on using hashes here.

Provenance

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