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.4.tar.gz (145.2 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.4-cp310-abi3-win_arm64.whl (71.6 kB view details)

Uploaded CPython 3.10+Windows ARM64

tree_sitter_matlab-1.2.4-cp310-abi3-win_amd64.whl (73.3 kB view details)

Uploaded CPython 3.10+Windows x86-64

tree_sitter_matlab-1.2.4-cp310-abi3-win32.whl (72.6 kB view details)

Uploaded CPython 3.10+Windows x86

tree_sitter_matlab-1.2.4-cp310-abi3-musllinux_1_2_x86_64.whl (103.0 kB view details)

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

tree_sitter_matlab-1.2.4-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.4-cp310-abi3-musllinux_1_2_aarch64.whl (105.5 kB view details)

Uploaded CPython 3.10+musllinux: musl 1.2+ ARM64

tree_sitter_matlab-1.2.4-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.4-cp310-abi3-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (105.5 kB view details)

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

tree_sitter_matlab-1.2.4-cp310-abi3-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (106.4 kB view details)

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

tree_sitter_matlab-1.2.4-cp310-abi3-macosx_11_0_arm64.whl (76.3 kB view details)

Uploaded CPython 3.10+macOS 11.0+ ARM64

File details

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

File metadata

  • Download URL: tree_sitter_matlab-1.2.4.tar.gz
  • Upload date:
  • Size: 145.2 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.4.tar.gz
Algorithm Hash digest
SHA256 d9c30571d0d531d36378e2f94ec03bef74c83a3c59e3eb36772ed65aceff58a1
MD5 b0092050e5db69a823c154db9a14c562
BLAKE2b-256 ad513fb175db2af259213542e1c4ab37df057f2e46dfce26f4b7e10e3c5d41d6

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for tree_sitter_matlab-1.2.4-cp310-abi3-win_arm64.whl
Algorithm Hash digest
SHA256 925379969a0a2d0b85508ad095335000f8c6f4f0a37402ea0dc56d8dd26bb57f
MD5 cf2541740d52364f362b82d559011141
BLAKE2b-256 27017c64df4b7fc8737403a087b61e034c1fdaab01153726c7b9e467a460fdcc

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for tree_sitter_matlab-1.2.4-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 664246f5a9276d67e7943fc3741ab70bb1b4c3103d41618b482b81c52b097c4a
MD5 e91817195605c089958039cbb692e78c
BLAKE2b-256 e9445b19e62ccbb5216c1bdaab7b3d385c74b932588c28fcef9e4194216eaff5

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for tree_sitter_matlab-1.2.4-cp310-abi3-win32.whl
Algorithm Hash digest
SHA256 42c5c7d5c9c2a5f0931cedaef8d12142289333105c675b08d75ddeb8cee83e79
MD5 4c4b29ae3c9954d018b1a8787aae1b54
BLAKE2b-256 d258ca03c74a72fe76f530f334ec72d6a392b7845e89a2bd1290bfb21d08c96d

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for tree_sitter_matlab-1.2.4-cp310-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 27e93feb8472aa97e62e42b8845e694582610eb687918518d62e2846936ae51d
MD5 5a974a0ec100dbac653296b90b3c8fbe
BLAKE2b-256 6d7c66761e7b29f95e2f9dbb8238358adb9f746872694e22ec291e53f254682d

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for tree_sitter_matlab-1.2.4-cp310-abi3-musllinux_1_2_i686.whl
Algorithm Hash digest
SHA256 1c7ebf5884c564977d6f23570548ac58ca0044426ffde7af2532818991438245
MD5 2f3e52c4d6d9f41ef48974ccc7af2938
BLAKE2b-256 9c14591b2aca84841fd113ac5dfb3ac54dc7c7493b5c1cfbe16ef435aff602ea

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for tree_sitter_matlab-1.2.4-cp310-abi3-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 fc403dd464387b6a8a7f5197274d0c9e3ee22a10e08d777511adbca01d6a98b1
MD5 e5432e45dbb19f816ed8de8ccb5800b1
BLAKE2b-256 32c2b9e485894c2f96f4a7d94f51be0ce4cf731c16184b2fc96183dfcb1f8ff2

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for tree_sitter_matlab-1.2.4-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 08970fb7b1e4a38bcae4cb156aa2dfb088687663140c3ab1b560c7edac96c75b
MD5 058c1a2493576e3c05309090922d78a2
BLAKE2b-256 80b68cfdbed0cd8cb093a493c2882d0992f7c6d54d529c2281784467dd4f3399

See more details on using hashes here.

Provenance

The following attestation bundles were made for tree_sitter_matlab-1.2.4-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.4-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.4-cp310-abi3-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 0c90fe02eb7171675633cc910e44264b3a0180ed0d193c2389a59b4827f87fb9
MD5 fd6965b1125e28b7cdb83306305b1e70
BLAKE2b-256 7179e68c7a30ea911fb8911282560e7b91168285f492698230a305d3139fd5f5

See more details on using hashes here.

Provenance

The following attestation bundles were made for tree_sitter_matlab-1.2.4-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.4-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.4-cp310-abi3-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 ebcb739e660a2299e1c3be3cc409c31bbb7c2634a244e53cb75c5f44db4b3844
MD5 a82b9bb22ffcc402f3f26fef7d823c9f
BLAKE2b-256 70516cddcedf2db698b5aad965f3b0f7a917cebbf8572e930f38901f5b641b51

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for tree_sitter_matlab-1.2.4-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 c5d7f77c2845dc17bf10a93f76a2685acab33836f201288277bb3c992c634dd7
MD5 a49297b1753daaad4d9605fef5cacea1
BLAKE2b-256 1b157720196c93170005fc05c762d3205c8f042bc8d6bda91dfe717f54476497

See more details on using hashes here.

Provenance

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