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.0.10.tar.gz (103.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.0.10-cp310-abi3-win_arm64.whl (55.6 kB view details)

Uploaded CPython 3.10+Windows ARM64

tree_sitter_matlab-1.0.10-cp310-abi3-win_amd64.whl (57.5 kB view details)

Uploaded CPython 3.10+Windows x86-64

tree_sitter_matlab-1.0.10-cp310-abi3-win32.whl (56.2 kB view details)

Uploaded CPython 3.10+Windows x86

tree_sitter_matlab-1.0.10-cp310-abi3-musllinux_1_2_x86_64.whl (83.2 kB view details)

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

tree_sitter_matlab-1.0.10-cp310-abi3-musllinux_1_2_i686.whl (85.7 kB view details)

Uploaded CPython 3.10+musllinux: musl 1.2+ i686

tree_sitter_matlab-1.0.10-cp310-abi3-musllinux_1_2_aarch64.whl (86.3 kB view details)

Uploaded CPython 3.10+musllinux: musl 1.2+ ARM64

tree_sitter_matlab-1.0.10-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (88.6 kB view details)

Uploaded CPython 3.10+manylinux: glibc 2.17+ ARM64

tree_sitter_matlab-1.0.10-cp310-abi3-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (86.2 kB view details)

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

tree_sitter_matlab-1.0.10-cp310-abi3-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (87.6 kB view details)

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

tree_sitter_matlab-1.0.10-cp310-abi3-macosx_11_0_arm64.whl (58.8 kB view details)

Uploaded CPython 3.10+macOS 11.0+ ARM64

File details

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

File metadata

  • Download URL: tree_sitter_matlab-1.0.10.tar.gz
  • Upload date:
  • Size: 103.4 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.10.tar.gz
Algorithm Hash digest
SHA256 a9ea4f3554a70ebf66001b28c61131a5337681141a8f841c41a9fed8254c5bb0
MD5 65c9008fd43aa5c9bcbac2503590ceae
BLAKE2b-256 c20c3fa54cf285fdf6bf5d3e2e0b407d45e1ec0fa0efdbce1616c9d5492a1001

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for tree_sitter_matlab-1.0.10-cp310-abi3-win_arm64.whl
Algorithm Hash digest
SHA256 1e25d997bd69bfde3213073fdcca2284fa810a7133cab80e6d5a4153500dedec
MD5 ec18231c893731f7b76291c490781486
BLAKE2b-256 3f5a2f5899edb1b84dba6b9191d73191b47e6e46e040063e9d337a0baa1dfd1d

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for tree_sitter_matlab-1.0.10-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 5b9d79a066419c780116ba568013f1bd31c2e9366f9d6a59aed33e4449bdf279
MD5 6123e42e68a183c9069c518f1be8e6a0
BLAKE2b-256 fb51d34bb2b5c2bd38da17b9ab1560c67a0d29edb459e1ce3b7cb11b394e5123

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for tree_sitter_matlab-1.0.10-cp310-abi3-win32.whl
Algorithm Hash digest
SHA256 0934a544a33a2049cb1fd062030fc07454b6dd3e29e9c14fcdde46fb7a049302
MD5 d15a3bbe74d057591f7fa83ed1c9ec33
BLAKE2b-256 6182ccf19748769564838489b44647a585912f83dea95f9a3351ba3885d210c4

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for tree_sitter_matlab-1.0.10-cp310-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 faf5a8fe4c048f667688b278ebd3cabb3a1ed36171d8082bb6a344598ca49f83
MD5 ea5994e02ce9d8fd5cbcb0cf9367e8ba
BLAKE2b-256 b29c36dd3e29f1e11fc2617f63c7117526370215398fb0be37ff8a83c15755b2

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for tree_sitter_matlab-1.0.10-cp310-abi3-musllinux_1_2_i686.whl
Algorithm Hash digest
SHA256 6786c6de8929e8c9edff6fcc327dde2f5600ddebc43945e5fb3c1dddaff324fd
MD5 8997c02d2bc16febac9a7d66320f758c
BLAKE2b-256 0fb58aca0e67eef6393dfd6076dab685fa0e104c57033009a99cfa1e2b3e9844

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for tree_sitter_matlab-1.0.10-cp310-abi3-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 7b1f59139fefd1bf0644e5639e5574f171f283bf2bf8089d3238f0c30fdc468a
MD5 b6d82dd9bc5b2eee7ce010152b91bcf8
BLAKE2b-256 666d3c1a65add237099b807b592c8eef6720bb89d9ce6c3f7341a1ffb6fd1c28

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for tree_sitter_matlab-1.0.10-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 72a7c2aa44f41dc3c958c03ca8c40564bb9302794f68bea182fd47e6c6e9e203
MD5 f712f7ee65b4d22f9e5b20ad61a68ca9
BLAKE2b-256 a1062abdf65350228756281692234fe5268cce869c437addbd806c7b8789cd74

See more details on using hashes here.

Provenance

The following attestation bundles were made for tree_sitter_matlab-1.0.10-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.10-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.10-cp310-abi3-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 321924a57605b6fb2150c37698d67b788d898436f704cfc94ed560df5b4df054
MD5 99953bc6bc1c01ae4f53ad76b09ab8f1
BLAKE2b-256 10fdad468ddb32e2b4c0fac27f9ea6c3c781281184a58fb8f7d2a1d2a7e2f9eb

See more details on using hashes here.

Provenance

The following attestation bundles were made for tree_sitter_matlab-1.0.10-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.10-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.10-cp310-abi3-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 ed64bbf5b1cf276c6d7597fef88413b6ff8aaa5258e7964c328f61ac14f0bfe0
MD5 69e84bd9aafdaca63b897abc226c65f1
BLAKE2b-256 60d2dc56087b553890cc860297a5fa3c62ad159c914b8915a383b90406a26cd0

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for tree_sitter_matlab-1.0.10-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 ab774930fb6b2c3c90c814bdbeb42f998b831c4db27223dbe73fa8628aa39330
MD5 bba3324be183cb4bbb84edc11f3117fd
BLAKE2b-256 57cd93d1d3bd459311b65cb570638aaf951963cff248ada62a55c593a19c5d22

See more details on using hashes here.

Provenance

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