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.6.tar.gz (174.4 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.6-cp310-abi3-win_arm64.whl (82.8 kB view details)

Uploaded CPython 3.10+Windows ARM64

tree_sitter_matlab-1.2.6-cp310-abi3-win_amd64.whl (84.2 kB view details)

Uploaded CPython 3.10+Windows x86-64

tree_sitter_matlab-1.2.6-cp310-abi3-win32.whl (83.5 kB view details)

Uploaded CPython 3.10+Windows x86

tree_sitter_matlab-1.2.6-cp310-abi3-musllinux_1_2_x86_64.whl (114.6 kB view details)

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

tree_sitter_matlab-1.2.6-cp310-abi3-musllinux_1_2_i686.whl (116.7 kB view details)

Uploaded CPython 3.10+musllinux: musl 1.2+ i686

tree_sitter_matlab-1.2.6-cp310-abi3-musllinux_1_2_aarch64.whl (117.5 kB view details)

Uploaded CPython 3.10+musllinux: musl 1.2+ ARM64

tree_sitter_matlab-1.2.6-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (119.4 kB view details)

Uploaded CPython 3.10+manylinux: glibc 2.17+ ARM64

tree_sitter_matlab-1.2.6-cp310-abi3-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (117.0 kB view details)

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

tree_sitter_matlab-1.2.6-cp310-abi3-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (118.1 kB view details)

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

tree_sitter_matlab-1.2.6-cp310-abi3-macosx_11_0_arm64.whl (88.5 kB view details)

Uploaded CPython 3.10+macOS 11.0+ ARM64

File details

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

File metadata

  • Download URL: tree_sitter_matlab-1.2.6.tar.gz
  • Upload date:
  • Size: 174.4 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.6.tar.gz
Algorithm Hash digest
SHA256 78cce57e0e779e89164522d238b319991c964a16f4964b47cba79170f676d9f1
MD5 772e830b807db888d829bed617127dc8
BLAKE2b-256 875b578b4866e90ff1faf19de67049f5d77e0e3e93604f24d4627a5f884e12e4

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for tree_sitter_matlab-1.2.6-cp310-abi3-win_arm64.whl
Algorithm Hash digest
SHA256 443214cff04816cde284aa3db73cc8419fd2008767df8afcaaaa86ea02bf0e46
MD5 bf6b63e2d493cbc90adf51405d2c4eea
BLAKE2b-256 65ba56cf294aeaeff0d9e8731c72b5e6499ba28289041492633e5f03c6a07385

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for tree_sitter_matlab-1.2.6-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 108eec77c97f7036917040642ca31c6f80029a22d3b2f189f21bff9348c70cb6
MD5 6ee88a71d6db73ee5b161bfe5b2339a0
BLAKE2b-256 7532c47b259164225c68d0c5061b5ab2ebcf295ded2f294d7e628ae84f122be7

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for tree_sitter_matlab-1.2.6-cp310-abi3-win32.whl
Algorithm Hash digest
SHA256 20a645478aa1a711b6a97edf0b1631b5e6e4746d0ba51ae0968f4598133f6e93
MD5 e069f6090a995efe50dba8190a970b7d
BLAKE2b-256 535c4b8d34e1e0d59d2e2d33132e5d29075933a66c1342965b501a01d6e4d54e

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for tree_sitter_matlab-1.2.6-cp310-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 995e33ef77f4ef162c821911433008649ef1091c5433e893c3827b07a44d20cd
MD5 f087ba77223c402b5d3341d7ff169734
BLAKE2b-256 c414a1dab9f9765691a4bf23a705675eb6e9fc8cc29be0786b7a9ed5bdf83423

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for tree_sitter_matlab-1.2.6-cp310-abi3-musllinux_1_2_i686.whl
Algorithm Hash digest
SHA256 45a9d943e19ab701395401db1c6c3928229f82cb8a9e0613101d86831b531faf
MD5 43ded44d95fd3743a03b13cdc7054864
BLAKE2b-256 634a5dec83ba859616173888040c9a1638034d61cd149dfe5150c532904dc6e1

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for tree_sitter_matlab-1.2.6-cp310-abi3-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 2e1901404211f5e593891d49084abf043770b785129b3e7b73f79faf949b88ad
MD5 70a22160643efb63db9a4fe51c65064a
BLAKE2b-256 5f8162805be044067fe0dec60906daaf439dd8982c1a9e674bdd17b22e2c8d00

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for tree_sitter_matlab-1.2.6-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 185a20ee103bf83822617637003b3ab49dc8e763d22960be2823ab7b83b603a5
MD5 1e59436056c9f511ec0ed1b6204074b2
BLAKE2b-256 5f1efd4a9b86242fd03f2ff764483e994745b1741245ae4ef2fbe5becb91c988

See more details on using hashes here.

Provenance

The following attestation bundles were made for tree_sitter_matlab-1.2.6-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.6-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.6-cp310-abi3-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 38688af0160c005fbb25688ca2e052b20565e281e3854367585e728930583759
MD5 e56b2f08688d0f1dd8efba2680f54d5b
BLAKE2b-256 3862c756fa4b6a0de67db6fed8074574b8c138561c67c4590a185def5832317c

See more details on using hashes here.

Provenance

The following attestation bundles were made for tree_sitter_matlab-1.2.6-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.6-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.6-cp310-abi3-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 8d24cf4dc48feb071090b6f7dc31abb3a93634a08aaeb3284d0b77c666f73da9
MD5 4571ff52ebf61ef938b3109514b77459
BLAKE2b-256 fc993a4dcbe857e84a9a16f9adcfecb394f61dd00b5c3aa98bcec15c582865a2

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for tree_sitter_matlab-1.2.6-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 a476a78b84a243d97ce62b38ccd20bc6a4b3f41f2d59b6dd45544fb90542a77a
MD5 f3c1fbf5e5aa718cf3c0a8449a70c801
BLAKE2b-256 758bbea64395f6987e93a159f73d669964af58975feeeab2e19b7bb5bd9b81a4

See more details on using hashes here.

Provenance

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