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.3.tar.gz (144.9 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.3-cp310-abi3-win_arm64.whl (71.5 kB view details)

Uploaded CPython 3.10+Windows ARM64

tree_sitter_matlab-1.2.3-cp310-abi3-win_amd64.whl (73.2 kB view details)

Uploaded CPython 3.10+Windows x86-64

tree_sitter_matlab-1.2.3-cp310-abi3-win32.whl (72.3 kB view details)

Uploaded CPython 3.10+Windows x86

tree_sitter_matlab-1.2.3-cp310-abi3-musllinux_1_2_x86_64.whl (102.9 kB view details)

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

tree_sitter_matlab-1.2.3-cp310-abi3-musllinux_1_2_i686.whl (104.9 kB view details)

Uploaded CPython 3.10+musllinux: musl 1.2+ i686

tree_sitter_matlab-1.2.3-cp310-abi3-musllinux_1_2_aarch64.whl (105.4 kB view details)

Uploaded CPython 3.10+musllinux: musl 1.2+ ARM64

tree_sitter_matlab-1.2.3-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (107.7 kB view details)

Uploaded CPython 3.10+manylinux: glibc 2.17+ ARM64

tree_sitter_matlab-1.2.3-cp310-abi3-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (105.3 kB view details)

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

tree_sitter_matlab-1.2.3-cp310-abi3-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (106.3 kB view details)

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

tree_sitter_matlab-1.2.3-cp310-abi3-macosx_11_0_arm64.whl (76.2 kB view details)

Uploaded CPython 3.10+macOS 11.0+ ARM64

File details

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

File metadata

  • Download URL: tree_sitter_matlab-1.2.3.tar.gz
  • Upload date:
  • Size: 144.9 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.3.tar.gz
Algorithm Hash digest
SHA256 cb2f35ed25235130c9d91ebc28f5a2d6d988af9f2c7d1b831b9c2cbf19e8826c
MD5 3c82e9dfc9beebdbc5c5d578a81b8548
BLAKE2b-256 bbe6874ddeca12dfce25278543007dbaad8e062d9cdd7a75a1912bce82749286

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for tree_sitter_matlab-1.2.3-cp310-abi3-win_arm64.whl
Algorithm Hash digest
SHA256 5b8fceeeaa21f4dcab27562a12606509b7865080fbb82bee9b31228e58b97b9a
MD5 0cd69a8ebc7162471903d7ec758b2bdc
BLAKE2b-256 df3aff12f3b944c0bdf520cfece318f544a76a45489dc697ca13be685c50ade7

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for tree_sitter_matlab-1.2.3-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 c82f79a453fbf9be1144f5d1195c5eed4faa61b06842afcb1e3bacc27f81b916
MD5 caa80220dea0a9e74f7d86c2f6d5baac
BLAKE2b-256 246dc6140d3ae7fb771b4c7de1eb81d617c3dfee0d58ec7d418be6d7fe20515e

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for tree_sitter_matlab-1.2.3-cp310-abi3-win32.whl
Algorithm Hash digest
SHA256 bc76999fe05564a04692acba4edb7123d494fde4664d5ef5be09ee0a2f1eb5e7
MD5 0abc17f151c5d9b16f9c67373f8e3218
BLAKE2b-256 f0571e19b31f611ad3cb18b5be9c9aef12d3f9829475cbbb7c5557f5039a59d5

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for tree_sitter_matlab-1.2.3-cp310-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 a0a069a5b1393abff0f85ff7b91bcbf51e6e79c2abcafbdbea0429977ba57eb7
MD5 10cd4243e65f31e988e28ff171fb9e30
BLAKE2b-256 08eac4121eb125774b4f476d5ab9fe0110db63a22c722286c9dff877a41db7f0

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for tree_sitter_matlab-1.2.3-cp310-abi3-musllinux_1_2_i686.whl
Algorithm Hash digest
SHA256 2b53379130d2b5f5c8a46f06c92404760e046590b1f2276770216ce98b3ad41b
MD5 7f4da4a040156acc0419947d72a75ea7
BLAKE2b-256 2a6e3adb01753aa38b16aeadc965e322835f1711f64241405fe4aad9dccae4ca

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for tree_sitter_matlab-1.2.3-cp310-abi3-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 53555da1f991b15c5e95b984fed4c44b7e3c624b8850649a76b1a9b455b73e9c
MD5 a7492ee2c4edeed6e36e64018d1f6cd7
BLAKE2b-256 8404a95203372eb8e373dfd72802adfe059e2929a6e09a3c42b2a2e9b3f4cac6

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for tree_sitter_matlab-1.2.3-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 fa5ef7041addd9d01887723b21bf603480e534bd059e414a981311c7d7194a01
MD5 59cb02657e4e310389e3b826335f18ea
BLAKE2b-256 c1fc05b94254b94fdfb67792d7c64d1f32e08648975ebb64821e7da022bca6e2

See more details on using hashes here.

Provenance

The following attestation bundles were made for tree_sitter_matlab-1.2.3-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.3-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.3-cp310-abi3-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 a1f63d004045a0e90137088f471dff78d7c441a27d3435985cbfd5731a075e24
MD5 c29e1372e0781ad7d299f170ebee79fc
BLAKE2b-256 4d4edac96f253a810c3e688eaa62339e74314856a9624564198e89218c9da6e1

See more details on using hashes here.

Provenance

The following attestation bundles were made for tree_sitter_matlab-1.2.3-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.3-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.3-cp310-abi3-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 75a3654f9635aa14599e2124b7a6e24fd5408840b446275c864529da418be009
MD5 8a892794e69d41b2a7bc28bea298a205
BLAKE2b-256 efff413fb899c72490c6b03afb0be75ce32b21db12fac000ec2eacb0c3671956

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for tree_sitter_matlab-1.2.3-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 e21f646e0c3073f30690aba37c4b449d5cc8963aa6a15346237158e1a06b8ee7
MD5 c88fba6d7264ac91c5a2da9c3f133f87
BLAKE2b-256 05824d4dd547e51673fd995d416565e66c01b30e78a87a9079688303b29c4569

See more details on using hashes here.

Provenance

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