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 available in the following editors:

Editor Plugin Highlights Folds Indents Code Format Injections Locals
Emacs Emacs-MATLAB-Mode
Helix Builtin
NeoVim nvim-treesitter

The columns have the following meaning:

  • Highlights: supports syntax highlight
  • Folds: supports code folding
  • Indents: supports code indenting, which adjusts the leftmost whitespace on each line.
  • Code Format: indent includes code formatting that standardizes the spacing of language elements within code lines, aligns matrix columns, adds missing commas within cells and matrices, etc.
  • Injections: supports embedding the language into another language (i.e.: MATLAB code blocks inside Markdown or org-mode)
  • Locals: supports identifying variables/functions/etc scope

Known issues

  • There is a conflict between numbers and element-wise operators that will cause a wrong parse if there is no space between the number and the operator. For example, 1./a will be interpreted as 1. / a instead of the correct 1 ./ a. This problem does not happen if there is a space between the number and the operator.

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.3.0.tar.gz (172.1 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.3.0-cp314-cp314t-win_arm64.whl (83.5 kB view details)

Uploaded CPython 3.14tWindows ARM64

tree_sitter_matlab-1.3.0-cp314-cp314t-win_amd64.whl (84.9 kB view details)

Uploaded CPython 3.14tWindows x86-64

tree_sitter_matlab-1.3.0-cp314-cp314t-win32.whl (84.3 kB view details)

Uploaded CPython 3.14tWindows x86

tree_sitter_matlab-1.3.0-cp314-cp314t-musllinux_1_2_x86_64.whl (117.7 kB view details)

Uploaded CPython 3.14tmusllinux: musl 1.2+ x86-64

tree_sitter_matlab-1.3.0-cp314-cp314t-musllinux_1_2_aarch64.whl (123.4 kB view details)

Uploaded CPython 3.14tmusllinux: musl 1.2+ ARM64

tree_sitter_matlab-1.3.0-cp314-cp314t-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl (125.8 kB view details)

Uploaded CPython 3.14tmanylinux: glibc 2.17+ ARM64manylinux: glibc 2.28+ ARM64

tree_sitter_matlab-1.3.0-cp314-cp314t-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl (119.1 kB view details)

Uploaded CPython 3.14tmanylinux: glibc 2.28+ x86-64manylinux: glibc 2.5+ x86-64

tree_sitter_matlab-1.3.0-cp314-cp314t-macosx_11_0_arm64.whl (86.5 kB view details)

Uploaded CPython 3.14tmacOS 11.0+ ARM64

tree_sitter_matlab-1.3.0-cp310-abi3-win_arm64.whl (81.0 kB view details)

Uploaded CPython 3.10+Windows ARM64

tree_sitter_matlab-1.3.0-cp310-abi3-win_amd64.whl (82.6 kB view details)

Uploaded CPython 3.10+Windows x86-64

tree_sitter_matlab-1.3.0-cp310-abi3-win32.whl (81.6 kB view details)

Uploaded CPython 3.10+Windows x86

tree_sitter_matlab-1.3.0-cp310-abi3-musllinux_1_2_x86_64.whl (114.9 kB view details)

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

tree_sitter_matlab-1.3.0-cp310-abi3-musllinux_1_2_aarch64.whl (120.7 kB view details)

Uploaded CPython 3.10+musllinux: musl 1.2+ ARM64

tree_sitter_matlab-1.3.0-cp310-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl (123.1 kB view details)

Uploaded CPython 3.10+manylinux: glibc 2.17+ ARM64manylinux: glibc 2.28+ ARM64

tree_sitter_matlab-1.3.0-cp310-abi3-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl (116.3 kB view details)

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

tree_sitter_matlab-1.3.0-cp310-abi3-macosx_11_0_arm64.whl (86.5 kB view details)

Uploaded CPython 3.10+macOS 11.0+ ARM64

File details

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

File metadata

  • Download URL: tree_sitter_matlab-1.3.0.tar.gz
  • Upload date:
  • Size: 172.1 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.3.0.tar.gz
Algorithm Hash digest
SHA256 a3c470dc7acfa996473496fa72917bff3c073121793c07af3a58123efe165bfb
MD5 339a7968a24a3db810dc1d6763d42999
BLAKE2b-256 c48f741f97fa6a33bea1e860610ddfe285cc54719b22874e579e00c82a3320ee

See more details on using hashes here.

Provenance

The following attestation bundles were made for tree_sitter_matlab-1.3.0.tar.gz:

Publisher: release.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.3.0-cp314-cp314t-win_arm64.whl.

File metadata

File hashes

Hashes for tree_sitter_matlab-1.3.0-cp314-cp314t-win_arm64.whl
Algorithm Hash digest
SHA256 d9db720b63888eb250de13029cdea324042f92f5f2c2934fd5f0a2eaa5f03b90
MD5 89607ead5e81062d94dfb528a7f165a6
BLAKE2b-256 206d57fe704e91a893d310e589c2363bcfc1342edce5868d72b4bc060f04eeb2

See more details on using hashes here.

Provenance

The following attestation bundles were made for tree_sitter_matlab-1.3.0-cp314-cp314t-win_arm64.whl:

Publisher: release.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.3.0-cp314-cp314t-win_amd64.whl.

File metadata

File hashes

Hashes for tree_sitter_matlab-1.3.0-cp314-cp314t-win_amd64.whl
Algorithm Hash digest
SHA256 101e6150555a788baef87b4d04e8790bd8aad9ba7dd6048c58d1d0f5d6b1e234
MD5 456b9f893c9a0af08a0e2b53e5aa5cea
BLAKE2b-256 2993c8502111da9c2cdab0da37e51bb9ce63abbba4314754b262ae4ea2eb7e9c

See more details on using hashes here.

Provenance

The following attestation bundles were made for tree_sitter_matlab-1.3.0-cp314-cp314t-win_amd64.whl:

Publisher: release.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.3.0-cp314-cp314t-win32.whl.

File metadata

File hashes

Hashes for tree_sitter_matlab-1.3.0-cp314-cp314t-win32.whl
Algorithm Hash digest
SHA256 b415bd72381a3545a6381b5fd84a3cc0014205c917fba25a0d4263fbe07b091e
MD5 ea31fda6866e0cd2b8ff54cc7db48867
BLAKE2b-256 2070677c17d14baa6070ea27d24b3f65763c8f17c0d41a0491ea9b21c1ad20b5

See more details on using hashes here.

Provenance

The following attestation bundles were made for tree_sitter_matlab-1.3.0-cp314-cp314t-win32.whl:

Publisher: release.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.3.0-cp314-cp314t-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for tree_sitter_matlab-1.3.0-cp314-cp314t-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 7af56374457af40849552fa6f8804f409ddeb00e9df83f2a6f41215b769397a0
MD5 d42d4b90e14259543f5edfd13da1b6fa
BLAKE2b-256 49021ccc465c00c04994dd12ca82c6cac45380c45798892fa68a357f254b8ba7

See more details on using hashes here.

Provenance

The following attestation bundles were made for tree_sitter_matlab-1.3.0-cp314-cp314t-musllinux_1_2_x86_64.whl:

Publisher: release.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.3.0-cp314-cp314t-musllinux_1_2_aarch64.whl.

File metadata

File hashes

Hashes for tree_sitter_matlab-1.3.0-cp314-cp314t-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 3780544ffa1e952c66bcaa852af0090a3e83578a710a1bc0fd70bed468317b33
MD5 eeb81d904bcf62928e9ceeee0ff6fe33
BLAKE2b-256 f1980b7ea7cc546a5d4f98ae9c06cd72555ffa88575dc0faf10da5a324bbbb3e

See more details on using hashes here.

Provenance

The following attestation bundles were made for tree_sitter_matlab-1.3.0-cp314-cp314t-musllinux_1_2_aarch64.whl:

Publisher: release.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.3.0-cp314-cp314t-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for tree_sitter_matlab-1.3.0-cp314-cp314t-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 8dd3ed28eb3531b0001d8d007142f18cd9fb9abc643e395b6938c2b4d59bf2f5
MD5 149d4fe4c78a53a50759d733ec5678cc
BLAKE2b-256 17b4f0d7e1b7a391d6c15d8dae4c64b70acc44d84b5dbc329e29525f6cebedce

See more details on using hashes here.

Provenance

The following attestation bundles were made for tree_sitter_matlab-1.3.0-cp314-cp314t-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl:

Publisher: release.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.3.0-cp314-cp314t-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl.

File metadata

File hashes

Hashes for tree_sitter_matlab-1.3.0-cp314-cp314t-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl
Algorithm Hash digest
SHA256 96b54b44ff720e5da4f61fdf307bbf875fb6673659e39038f65cc5466e35fe28
MD5 1bb59c27a3bb19218de5ea71b69974c8
BLAKE2b-256 fde2aef2727d8a0334a53439073c9e259bfcb96b771146613ecb5ed85ff911e6

See more details on using hashes here.

Provenance

The following attestation bundles were made for tree_sitter_matlab-1.3.0-cp314-cp314t-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl:

Publisher: release.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.3.0-cp314-cp314t-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for tree_sitter_matlab-1.3.0-cp314-cp314t-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 b9e17969162fd8bc130a1088b7502ad1c7f19e72cfd8d8091c4f0ef6100923ea
MD5 224763330a59ae1b1916129f75defc3f
BLAKE2b-256 5bf5da0ddb58a7537be3adfee2aa88dce597b4f8021e046f50767364cb000d65

See more details on using hashes here.

Provenance

The following attestation bundles were made for tree_sitter_matlab-1.3.0-cp314-cp314t-macosx_11_0_arm64.whl:

Publisher: release.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.3.0-cp310-abi3-win_arm64.whl.

File metadata

File hashes

Hashes for tree_sitter_matlab-1.3.0-cp310-abi3-win_arm64.whl
Algorithm Hash digest
SHA256 9064fb4d9494f9e8c183e56840aa34504056e856e8623939c7021764fc1de422
MD5 ac8a18ea90ede15ed90d8d1ea136c0e6
BLAKE2b-256 7fdb94778e6f58ba16de8807819316b0851ef0a999fa1c177a73756379598095

See more details on using hashes here.

Provenance

The following attestation bundles were made for tree_sitter_matlab-1.3.0-cp310-abi3-win_arm64.whl:

Publisher: release.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.3.0-cp310-abi3-win_amd64.whl.

File metadata

File hashes

Hashes for tree_sitter_matlab-1.3.0-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 7ca52f75fe09b68efc567c2e69e6a329c31e999946a25528942dffdc73686224
MD5 c09ab74cf93a49b61ea92b8750243736
BLAKE2b-256 e650c09e2a9ff9ac3e3be0e1c2786a4ab179eb4aca06784c36f357e67ac7f563

See more details on using hashes here.

Provenance

The following attestation bundles were made for tree_sitter_matlab-1.3.0-cp310-abi3-win_amd64.whl:

Publisher: release.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.3.0-cp310-abi3-win32.whl.

File metadata

File hashes

Hashes for tree_sitter_matlab-1.3.0-cp310-abi3-win32.whl
Algorithm Hash digest
SHA256 3e7044be254569d832268974cde313c5c094399325e5b597811276d4acf3a766
MD5 2446d3bbdbe5177a9bf0d0c2b45c4cdb
BLAKE2b-256 937012731db61d859211176dac6da4df993d7b69c998ad6f0e2839d8638b376e

See more details on using hashes here.

Provenance

The following attestation bundles were made for tree_sitter_matlab-1.3.0-cp310-abi3-win32.whl:

Publisher: release.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.3.0-cp310-abi3-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for tree_sitter_matlab-1.3.0-cp310-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 68cc60df281b15c5d852f15bfddc3e8d120e1c9eb77dc46fcddc75e55ffe41e5
MD5 b214cb89ee64d96d9e03dad69e7a4147
BLAKE2b-256 9bc8cb7479ef3eeb23975820668d37dfb9262f837bd40dbd9ec650d37af142c1

See more details on using hashes here.

Provenance

The following attestation bundles were made for tree_sitter_matlab-1.3.0-cp310-abi3-musllinux_1_2_x86_64.whl:

Publisher: release.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.3.0-cp310-abi3-musllinux_1_2_aarch64.whl.

File metadata

File hashes

Hashes for tree_sitter_matlab-1.3.0-cp310-abi3-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 96913579ed39d4d8d6c8c56a2c320a588a50befbc8d3d441e9fe02a308c0b59b
MD5 6b7508b6c1e59b4475570ff1422394b6
BLAKE2b-256 9e3cdb0b7a8f07125aec0172a7ed9688da7001fcd93a364478653275590acc1d

See more details on using hashes here.

Provenance

The following attestation bundles were made for tree_sitter_matlab-1.3.0-cp310-abi3-musllinux_1_2_aarch64.whl:

Publisher: release.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.3.0-cp310-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for tree_sitter_matlab-1.3.0-cp310-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 f84ecacbdc83b149d2b954d5fbd7101db4abf19f0cdd4c50d08022ed60c0b9b7
MD5 ae5e57988c2511ba6d089957e6d366c9
BLAKE2b-256 0608ad8e452c892a73e58249cbde708cd41e53e62a57ee51e2fdb61e56362191

See more details on using hashes here.

Provenance

The following attestation bundles were made for tree_sitter_matlab-1.3.0-cp310-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl:

Publisher: release.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.3.0-cp310-abi3-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl.

File metadata

File hashes

Hashes for tree_sitter_matlab-1.3.0-cp310-abi3-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl
Algorithm Hash digest
SHA256 6b8515503f2966ee9030654cc14ddf9f66b3c9fe73d5830248a9a0e672d16664
MD5 b2ef488c861c55e1f543bfc2bfbdba47
BLAKE2b-256 9cba8b9bcb5b1452541f0b8a2181ddb8e3181bf42631155de9ed632d0f33930a

See more details on using hashes here.

Provenance

The following attestation bundles were made for tree_sitter_matlab-1.3.0-cp310-abi3-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl:

Publisher: release.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.3.0-cp310-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for tree_sitter_matlab-1.3.0-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 dd343dfa820c40b4eb52f62a7bfce9192510f11f932427d84ecf089228a6517c
MD5 92306ba6839b69c52c249a2fd2bafcf7
BLAKE2b-256 6030b4925490c25451da3c0f94f6a3ed1425bcfe6411bb8261b4af74c4b1898f

See more details on using hashes here.

Provenance

The following attestation bundles were made for tree_sitter_matlab-1.3.0-cp310-abi3-macosx_11_0_arm64.whl:

Publisher: release.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