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.

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.5.tar.gz (86.6 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.5-cp310-abi3-win_amd64.whl (52.6 kB view details)

Uploaded CPython 3.10+Windows x86-64

tree_sitter_matlab-1.0.5-cp310-abi3-win32.whl (51.2 kB view details)

Uploaded CPython 3.10+Windows x86

tree_sitter_matlab-1.0.5-cp310-abi3-musllinux_1_2_x86_64.whl (77.9 kB view details)

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

tree_sitter_matlab-1.0.5-cp310-abi3-musllinux_1_2_i686.whl (78.3 kB view details)

Uploaded CPython 3.10+musllinux: musl 1.2+ i686

tree_sitter_matlab-1.0.5-cp310-abi3-musllinux_1_2_aarch64.whl (80.1 kB view details)

Uploaded CPython 3.10+musllinux: musl 1.2+ ARM64

tree_sitter_matlab-1.0.5-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (81.4 kB view details)

Uploaded CPython 3.10+manylinux: glibc 2.17+ ARM64

tree_sitter_matlab-1.0.5-cp310-abi3-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (81.1 kB view details)

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

tree_sitter_matlab-1.0.5-cp310-abi3-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (80.3 kB view details)

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

tree_sitter_matlab-1.0.5-cp310-abi3-macosx_11_0_arm64.whl (52.3 kB view details)

Uploaded CPython 3.10+macOS 11.0+ ARM64

File details

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

File metadata

  • Download URL: tree_sitter_matlab-1.0.5.tar.gz
  • Upload date:
  • Size: 86.6 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.5.tar.gz
Algorithm Hash digest
SHA256 77f665789361441a3d40d14227622ab558756fccf604cbaf310fea9cbfac0bf2
MD5 cbf4504ade88ebb4f0e263c6bd75a5d5
BLAKE2b-256 7359e4c4c90509c76f883792e06d71622d22460cafb2a5d7376504ab47a3c725

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for tree_sitter_matlab-1.0.5-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 6d9f7f4452e35707b69d1ede85867a86ca12783cff3a2173a0859d997e7b678d
MD5 454c182a7dc7c815e6f38e152bfe8a42
BLAKE2b-256 93a7f68314efb585975ffbf747813e385e7c15b1853fd2b6208bef2ec6a66787

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for tree_sitter_matlab-1.0.5-cp310-abi3-win32.whl
Algorithm Hash digest
SHA256 c0724f992676d6a7b99e1b833ff93a17888f1b4178076a55e01bfaa212a6c3f0
MD5 78c13f0499350f8c8d8a75b7b42dec81
BLAKE2b-256 b4929808730c558fd9e256a821943b7cfedfe75ba590d85c024c2e7ac2c948f1

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for tree_sitter_matlab-1.0.5-cp310-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 0b63de4f5d8d874004aa0809b891a9c23fc46623fcf134dadf75f7b08220787e
MD5 1d7bf3537053de5fd3dbb24d68dcf0a4
BLAKE2b-256 7e216fc6f7c874e7c34193d46e5483057d2817b475c2d59be801dba7df86e573

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for tree_sitter_matlab-1.0.5-cp310-abi3-musllinux_1_2_i686.whl
Algorithm Hash digest
SHA256 38f74149a04a34a30c7f025d057b63dd4212691adba418c34900239cf4f38fee
MD5 e0b342378a345d003ffe1d2675d86e77
BLAKE2b-256 bd81d353cc9f9ce2cbf53e7c075a5df7c3b2d04a73e56bd31aad6a5a1e708a79

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for tree_sitter_matlab-1.0.5-cp310-abi3-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 a8ffbcdc4e9019648bbd700c511d650da0289c1a3e3764931314425ec3dcedc3
MD5 55f9e6d602afb0e783e7da7e5dc5fa56
BLAKE2b-256 dd8f40e12412dbd813a9b26c3cd92f5474a209c5796d594b4c8d672145ed97f9

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for tree_sitter_matlab-1.0.5-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 29249db368042efe5b8cbac58187f356808cb9fd8dfe50158a8f7a256fbd7587
MD5 d4340bcd03aca35c6ef7dfbdfc2a48f8
BLAKE2b-256 79dc6519120077164991519e17ac994a0219ca55460142eeb50fc23faa513a76

See more details on using hashes here.

Provenance

The following attestation bundles were made for tree_sitter_matlab-1.0.5-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.5-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.5-cp310-abi3-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 9ab32a39d641fa32034f8f6ed23e8b3ace3e7dd3cc3db4496f72576861187bb1
MD5 0725ad4b36fd76cc1b3d73919aabf158
BLAKE2b-256 2df4da67850b2b0a7d3334d5ca86d4d5c7b888ecf74d721e72f90e04a8d66d0b

See more details on using hashes here.

Provenance

The following attestation bundles were made for tree_sitter_matlab-1.0.5-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.5-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.5-cp310-abi3-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 857b811768b04d7cc008af39709271c34b5ea7d8120f4f1fcf99dde2e2692017
MD5 9c995f3463bdf7c2517a6ec525524136
BLAKE2b-256 b37e05e885689e62b5233a4784d37ecc7622e137f7657d5dadc5aa1c1f7db283

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for tree_sitter_matlab-1.0.5-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 4c2e0e836ab47a0ccf519e695a2663c545f9f9f2698a4b1580cf0c70ac1c0075
MD5 b86af875680110488d52915fc75ac55a
BLAKE2b-256 ba8685d52c77a0defef4bf44e1157ad606e6ec13521e896543af10012d04ef3f

See more details on using hashes here.

Provenance

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