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.1.tar.gz (125.2 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.1-cp310-abi3-win_arm64.whl (64.2 kB view details)

Uploaded CPython 3.10+Windows ARM64

tree_sitter_matlab-1.2.1-cp310-abi3-win_amd64.whl (65.8 kB view details)

Uploaded CPython 3.10+Windows x86-64

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

Uploaded CPython 3.10+Windows x86

tree_sitter_matlab-1.2.1-cp310-abi3-musllinux_1_2_x86_64.whl (94.6 kB view details)

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

tree_sitter_matlab-1.2.1-cp310-abi3-musllinux_1_2_i686.whl (95.1 kB view details)

Uploaded CPython 3.10+musllinux: musl 1.2+ i686

tree_sitter_matlab-1.2.1-cp310-abi3-musllinux_1_2_aarch64.whl (97.7 kB view details)

Uploaded CPython 3.10+musllinux: musl 1.2+ ARM64

tree_sitter_matlab-1.2.1-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (99.5 kB view details)

Uploaded CPython 3.10+manylinux: glibc 2.17+ ARM64

tree_sitter_matlab-1.2.1-cp310-abi3-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (97.5 kB view details)

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

tree_sitter_matlab-1.2.1-cp310-abi3-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (97.0 kB view details)

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

tree_sitter_matlab-1.2.1-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.1.tar.gz.

File metadata

  • Download URL: tree_sitter_matlab-1.2.1.tar.gz
  • Upload date:
  • Size: 125.2 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.1.tar.gz
Algorithm Hash digest
SHA256 126c5775948c829ed6831580712c33cc854da7378fecda01aae2b6fd97eac159
MD5 f0f046d68c85125610a9a8429a12caf0
BLAKE2b-256 bee2f95e0944de86dbc939a3211f0fbfd6b6f261dbb3e9fc63c806a9b8e5e0ec

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for tree_sitter_matlab-1.2.1-cp310-abi3-win_arm64.whl
Algorithm Hash digest
SHA256 3b54f038d3a7964883c14fe5afb7e37ab03090fed0c027e802c37c5c698ec07a
MD5 8fe1c16bc0ac845ba36cf4d521a45884
BLAKE2b-256 3bd94ddaeabe276131f0a1ce10612d364709bf60df7b915fb2aa871ed230822b

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for tree_sitter_matlab-1.2.1-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 c222573b4289dd4427202d5a6b8194064d6dae5149bb6f55222c806cc1454171
MD5 d213719939216a822d28073750ad766f
BLAKE2b-256 02ac4065a9e12b5582d39d222f10049651639d3bc7f7d723b3a72348144f7186

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for tree_sitter_matlab-1.2.1-cp310-abi3-win32.whl
Algorithm Hash digest
SHA256 3e597d155fb76dbf55d203d7a8c6328ca786b8e27ee05da6457f55dd03012e88
MD5 cfa8051191e8c07aa1677050bb48b2e0
BLAKE2b-256 73edfb751b42dfc29bd58e5b5b24e3dd448d1a900a5a3c404f4ad19cc53d2adf

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for tree_sitter_matlab-1.2.1-cp310-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 e0a8cd5a7240185c11d36c9be882d606a7e40fe0f1089140d6cda2ae6ca3067b
MD5 d3c88926b86a052990c4641cf1be512c
BLAKE2b-256 64fd78a1a334c505f0adda469ead88e74cbf6f1c5a643559ad805375491697c3

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for tree_sitter_matlab-1.2.1-cp310-abi3-musllinux_1_2_i686.whl
Algorithm Hash digest
SHA256 0fb5d317bb7a0e65ee7f228dc4ad067c241453173ddfb3a88f9eaf3f489bf5b2
MD5 a14a82ded025c47258ce232c8de0b146
BLAKE2b-256 1118a3cd49d587439b29921d45fcd2e9938696dbc845a94be8276c64e39fc31a

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for tree_sitter_matlab-1.2.1-cp310-abi3-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 aab549da6c50a21bcfc48dd47b6fedd641c2190088fa2120e6a13bee6882fa16
MD5 d0b7668b746d0fd70c62af4f01c242b9
BLAKE2b-256 ef9f900d2cb0f90232fca31d4d76b94ecac7e705e5a27029f87a1704faeb4120

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for tree_sitter_matlab-1.2.1-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 b6b04ec1bf1fb9799e656469b7b1b22322c60ef34b82921f189d53e556c60d82
MD5 3dde464eb6fa114d6a3d12decbeef4d4
BLAKE2b-256 937a20d643d235a8a64352387d7498f18161c9001bc58e829fdcd04465ebe5ed

See more details on using hashes here.

Provenance

The following attestation bundles were made for tree_sitter_matlab-1.2.1-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.1-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.1-cp310-abi3-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 8828e23fea35754aa7dab06eb6f9afe6db4eb61d553cded25b99fd19326e8b2d
MD5 639940948231937fca306aa1381ab3dc
BLAKE2b-256 236d187c208c0983eee7d51d1600e3f8ede30accf729184f8c261240af0e2732

See more details on using hashes here.

Provenance

The following attestation bundles were made for tree_sitter_matlab-1.2.1-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.1-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.1-cp310-abi3-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 e8fd97664df10ae9f761c3cf69d57b087c16958bf9c502175994eeb0bae37ad4
MD5 4def678a48910d54a05410e9f09e029a
BLAKE2b-256 5d70d1f86ee179ba92c9242b7f3305366fbe63634385637b3e68bf8e78baf96b

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for tree_sitter_matlab-1.2.1-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 0ba352d873fdfbe482459bf6955332940261aa31b35b42a3e9670031f9f94f9f
MD5 002826c6a06e99bab2e1daebda8b9cda
BLAKE2b-256 6c19a484af8184bbff868d09b637dd19f2e520bec3feae837d8975540a295ee5

See more details on using hashes here.

Provenance

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