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.5.tar.gz (174.3 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.5-cp310-abi3-win_arm64.whl (82.8 kB view details)

Uploaded CPython 3.10+Windows ARM64

tree_sitter_matlab-1.2.5-cp310-abi3-win_amd64.whl (84.2 kB view details)

Uploaded CPython 3.10+Windows x86-64

tree_sitter_matlab-1.2.5-cp310-abi3-win32.whl (83.4 kB view details)

Uploaded CPython 3.10+Windows x86

tree_sitter_matlab-1.2.5-cp310-abi3-musllinux_1_2_x86_64.whl (114.3 kB view details)

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

tree_sitter_matlab-1.2.5-cp310-abi3-musllinux_1_2_i686.whl (116.5 kB view details)

Uploaded CPython 3.10+musllinux: musl 1.2+ i686

tree_sitter_matlab-1.2.5-cp310-abi3-musllinux_1_2_aarch64.whl (117.1 kB view details)

Uploaded CPython 3.10+musllinux: musl 1.2+ ARM64

tree_sitter_matlab-1.2.5-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (119.2 kB view details)

Uploaded CPython 3.10+manylinux: glibc 2.17+ ARM64

tree_sitter_matlab-1.2.5-cp310-abi3-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (116.9 kB view details)

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

tree_sitter_matlab-1.2.5-cp310-abi3-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (118.0 kB view details)

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

tree_sitter_matlab-1.2.5-cp310-abi3-macosx_11_0_arm64.whl (88.4 kB view details)

Uploaded CPython 3.10+macOS 11.0+ ARM64

File details

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

File metadata

  • Download URL: tree_sitter_matlab-1.2.5.tar.gz
  • Upload date:
  • Size: 174.3 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.5.tar.gz
Algorithm Hash digest
SHA256 a9fe5effab8e8c99f6d71d35157ef895e1c7d99702d8d54a63dfb79bfd52e911
MD5 c1f39e85e29345b5dda9c05ffcde8f32
BLAKE2b-256 2116115141e54ed764fdcbf27e1952f4d72151d35e3483eebc1d00a6a346f8d8

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for tree_sitter_matlab-1.2.5-cp310-abi3-win_arm64.whl
Algorithm Hash digest
SHA256 a0d8274d413e201745679501619d3e8a8f29982c17a432e3f440cd6eefbe0808
MD5 d2687a8219b029d6b322aab27c9d6157
BLAKE2b-256 eb7d67f7ecfc920fbc6cefa20cf002da6a92ce693ebbaee7ead3d6dc490cd3fc

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for tree_sitter_matlab-1.2.5-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 cd9f37f7b5c6ecd74691487677f46df99bdad2bb81cddd8f028d4cad82d206b8
MD5 fb6ec4cfe40e4f58836d154bab1e1a5a
BLAKE2b-256 3616ac136c5ead54e2327bf9a1832003198b2739432c6467e23f3233765b9a5d

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for tree_sitter_matlab-1.2.5-cp310-abi3-win32.whl
Algorithm Hash digest
SHA256 0910d9982cbd1c0edee6e476553d94557c3e8155ed001387150b6f45a5988389
MD5 8193515da73ab81706d633cdeb6b0679
BLAKE2b-256 5dab9106b51fb5ce0ee4cf2294755e63bc7987310b5e7c18998bbaf6d64108bb

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for tree_sitter_matlab-1.2.5-cp310-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 ebe637baa349b76295bce43554d7b336a8daf702e8128f6a92ef97170ce888bf
MD5 859c6e9966289a25f55044e6738792c6
BLAKE2b-256 b66bafa4114b4d4dfc9485279c509b091aec9709b2274608d0efb88d3a928a95

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for tree_sitter_matlab-1.2.5-cp310-abi3-musllinux_1_2_i686.whl
Algorithm Hash digest
SHA256 7e67a082246977e876b61ef1631016cf1a00ac2fd32b44e39a0ac17df436f368
MD5 9327ab9e9d4f4face09ac61bf40b645e
BLAKE2b-256 e01be7f4baeb9a7e49051bcb69cad93b5746d9562f0403c6864eda512dbdea2e

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for tree_sitter_matlab-1.2.5-cp310-abi3-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 cfb00e5142bc6860eb86294a51e1b8cd03907cc9556b43b0f7b956819d243dc7
MD5 9ed956847192fcd8b6e91c9dfe01e586
BLAKE2b-256 87b7cb2b6d552fe0d2bbc7aad1bf69313181d45263d3d16338ef8697c2485955

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for tree_sitter_matlab-1.2.5-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 d65fd7048cf1722e2d4169d6f3147544c7d878290f8d0b795fc94b8b11024510
MD5 36dfc1c122a307e388122ff003fa6ca0
BLAKE2b-256 63d8522176e23a14418c033d2ff320ba6a72f875ed07e155443e6d7a5e99c20c

See more details on using hashes here.

Provenance

The following attestation bundles were made for tree_sitter_matlab-1.2.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.2.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.2.5-cp310-abi3-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 420da382598931c037e164623ec65b3ba7afd07a46391eb2eae52b01184b7619
MD5 5a44f196b5bd6ce4fc96a14fa7030d92
BLAKE2b-256 94cf2c8fa8f1ed068a313866f8756cdfbbfb3d3c2499da9037114f2f2c618296

See more details on using hashes here.

Provenance

The following attestation bundles were made for tree_sitter_matlab-1.2.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.2.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.2.5-cp310-abi3-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 9a0af37d3df325c81fcd2891d30421776f1549280ecaa3fc7474bc955b5dbae4
MD5 41bcdc12babc66e146388006a1bbff0d
BLAKE2b-256 66bfb48912b12761fddfbd1a4ade79bbbc0ac90b147e8ebd0caf36a35c5443ca

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for tree_sitter_matlab-1.2.5-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 7f53ac908b0d61583df6758d7e3277b2ca06c8ab93a8ffac52a4669c1dc6f687
MD5 2515541c59504c37859c5a7d3b49b492
BLAKE2b-256 2740955e1938418a439bc5ebb775f92cc5c8e175c4f4ca5627a88a9e2acf8f20

See more details on using hashes here.

Provenance

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