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.2.tar.gz (125.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.2-cp310-abi3-win_arm64.whl (64.1 kB view details)

Uploaded CPython 3.10+Windows ARM64

tree_sitter_matlab-1.2.2-cp310-abi3-win_amd64.whl (65.7 kB view details)

Uploaded CPython 3.10+Windows x86-64

tree_sitter_matlab-1.2.2-cp310-abi3-win32.whl (64.7 kB view details)

Uploaded CPython 3.10+Windows x86

tree_sitter_matlab-1.2.2-cp310-abi3-musllinux_1_2_x86_64.whl (94.8 kB view details)

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

tree_sitter_matlab-1.2.2-cp310-abi3-musllinux_1_2_i686.whl (95.4 kB view details)

Uploaded CPython 3.10+musllinux: musl 1.2+ i686

tree_sitter_matlab-1.2.2-cp310-abi3-musllinux_1_2_aarch64.whl (97.9 kB view details)

Uploaded CPython 3.10+musllinux: musl 1.2+ ARM64

tree_sitter_matlab-1.2.2-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (99.7 kB view details)

Uploaded CPython 3.10+manylinux: glibc 2.17+ ARM64

tree_sitter_matlab-1.2.2-cp310-abi3-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (97.4 kB view details)

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

tree_sitter_matlab-1.2.2-cp310-abi3-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (97.2 kB view details)

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

tree_sitter_matlab-1.2.2-cp310-abi3-macosx_11_0_arm64.whl (68.4 kB view details)

Uploaded CPython 3.10+macOS 11.0+ ARM64

File details

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

File metadata

  • Download URL: tree_sitter_matlab-1.2.2.tar.gz
  • Upload date:
  • Size: 125.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.2.tar.gz
Algorithm Hash digest
SHA256 b2fb657862622b65519efd328d5cb9426739e3a7a3c1b54e6cf7ca33368687f0
MD5 0e9382f9dd038ac83f26dea45f128746
BLAKE2b-256 3f408d7b2e61d7f68aa483a6e5058fa05f4259343ef5db8162e669aea24613b4

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for tree_sitter_matlab-1.2.2-cp310-abi3-win_arm64.whl
Algorithm Hash digest
SHA256 74fd48da9347e9f2938a731011e620933877bd8530434d23153cedf1ea5ced5f
MD5 c9b69810d05b185456b87944fccda11a
BLAKE2b-256 b89c49ffca33a4cf6ed1f8cc09a8b181a6202146be0f394a671fdc248278eea4

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for tree_sitter_matlab-1.2.2-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 83de50a2d8e9fad8e4125fcdf9b5187e16e11fffe8203144a22c558fab5e3430
MD5 cf6878b787bf646d57acd118f4d41c29
BLAKE2b-256 d9dc988e27eb276c3e1cc273419ee600f1d9995b57e06573f1e2b06079632e8d

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for tree_sitter_matlab-1.2.2-cp310-abi3-win32.whl
Algorithm Hash digest
SHA256 eac4b4f32754d75b49534ff90fb94b1a4993452b6e9552599bb47f5c9d65dbdd
MD5 0a42748d333db57dc42a58f721b1bf34
BLAKE2b-256 5d556883b8957d4bc2a61217ab6ff611578ecbb5edfb29338786aa7f2707495a

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for tree_sitter_matlab-1.2.2-cp310-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 e641b3669a94900bdfad2ed66efbd783b660a87cb0ae192aada708723e6e4c73
MD5 cd752f8f7d4fcd67ff8d4ad1ef1ef7d2
BLAKE2b-256 fc21a8d9d9e4e7f0b8219d848e922520225e11caa7c82b527be48d4d6cf1f9c2

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for tree_sitter_matlab-1.2.2-cp310-abi3-musllinux_1_2_i686.whl
Algorithm Hash digest
SHA256 6b6f95a8699f5f57b5cd2986bfe52b5192f86ada1c3900f2b097b0779d2fb585
MD5 bcfd693b69aede42e97a532afe320d5c
BLAKE2b-256 e249d6fd008a76aa5f70700a4e1aeccfea3a5577b2a11acf359394144502d1c3

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for tree_sitter_matlab-1.2.2-cp310-abi3-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 472cbaedbd9d17030f4563e78d3367871f1cdeb2d2697bcd99bd159b8aa20feb
MD5 5aa4afd6f5c985f5747e7b01701a0f20
BLAKE2b-256 ca18ba5a5a8bb279ed9e9734b9b8d14094ebb2949824d02cd319ec1de832a1bf

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for tree_sitter_matlab-1.2.2-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 07a63144648d64888a02e0f649755c0f58461b6634b433e111a0a43b7ee48bc5
MD5 3a9117ec7dd47c3405fa0307a18e1e3e
BLAKE2b-256 667d59df3c2b3885797da69d3629c7d7808e055fda299fd051103d3a36fcf3d5

See more details on using hashes here.

Provenance

The following attestation bundles were made for tree_sitter_matlab-1.2.2-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.2-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.2-cp310-abi3-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 5d06e5d40cb8ef03a8d150eda91269dc39107b3e2c8e3bf84873bf01a15fef6f
MD5 183398cce2bd792a33a44c9a79afe789
BLAKE2b-256 7e6f746f27ae8e6fe5986e7a1d80a8ff0aafd58820e9faa2b4e9a4d50a800405

See more details on using hashes here.

Provenance

The following attestation bundles were made for tree_sitter_matlab-1.2.2-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.2-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.2-cp310-abi3-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 0cea63202e51cc6fee8b170a5500d6f6bdce2cdda91d2c019d44679cd0bcd29b
MD5 525383d2684f5263d3e6f7e1d5e33be1
BLAKE2b-256 f06373fc6b98c470322535da2bfd256f2b83599954908d6477648ed35bf551b5

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for tree_sitter_matlab-1.2.2-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 8f4ff2136c5519e4b5cb1b6b322c8fb5218b199a99117aa1ef187bf3f5b36f74
MD5 6682b23c3d62b885dc8f8583b94f2e39
BLAKE2b-256 c70e3fb0cee11fedc024cd75af4a6955b15b6c2f40f7e6fd1547fd19a5c3cadc

See more details on using hashes here.

Provenance

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