Skip to content

Add MATLAB support (.m files) — grammar already exists on PyPI #1702

Open

Description

@catalystdream

Summary

graphify currently has no MATLAB/tree-sitter support at all — .m files fall through to a bare file-stub node with zero structural edges (no functions, no calls, no cross-file imports/references detected), even though a real, maintained tree-sitter grammar for MATLAB already exists and is installable as a normal dependency.

Evidence

  • Checked the installed graphifyy package dependencies (uv tool install graphifyy) — no tree-sitter-matlab among the 27 language grammars bundled.
  • A working grammar exists: acristoffers/tree-sitter-matlab — actively maintained (updated within the last ~2 weeks as of filing), and already published on PyPI as tree-sitter-matlab (currently v1.3.0), same packaging convention as graphify's other tree-sitter-<language> dependencies.
  • Confirmed the gap concretely on a real corpus: 4 MATLAB files with genuine call/usage relationships (one script calling into another, importing shared config) extracted to 4 isolated nodes, 0 edges via graphify extract. By contrast, a 6-file Python module with equivalent internal structure extracted to 72 nodes, 152 edges in the same session — same tool, same AST-only pass, only the language differed.
  • This isn't just "reduced fidelity" — it produces a wrong-by-omission answer for any code-navigation question touching MATLAB. Asked graphify query "what code implements X", where X is a MATLAB-only feature — the correct files never appeared anywhere in a 35-node depth-2 BFS, because they have no edges to be traversed through.

Why it matters

MATLAB is heavily used in engineering/scientific domains (controls, aerospace, signal processing, simulation) where graphify's docs+code+papers pitch is otherwise a great fit — but right now those codebases get effectively no structural graph at all for their primary language.

What I looked at on the implementation side

Per-language extraction in extract.py looks hand-written per language (~150-300 lines each, e.g. the Julia block), not a generic tree-sitter-node walker — so this isn't a one-line pip install fix, it'd need a new extraction function targeting tree-sitter-matlab's specific node-type names (function definitions, classdef blocks, calls, etc.), following the same pattern as the existing per-language blocks. Flagging that context in case it's useful for scoping the work, not assuming it's trivial.

Happy to help test against a real MATLAB corpus if that's useful once there's a WIP branch.

Activity

  1. catalystdream commented on Jul 6, 2026

    @catalystdream
    Author

    Correction/sharpening after digging into the actual source — the diagnosis is more specific than "no MATLAB support," and the fix path is more precedented than I first thought:

    .m is not unhandled — it's claimed by Objective-C. detect.py's CODE_EXTENSIONS and extract.py route .m/.mm to extract_objc() via tree_sitter_objc unconditionally. There's no content check for .m specifically.

    Feeding real MATLAB source through the Objective-C parser produces a broken parse, not a clean skip. Tested directly against one of the files from my original report:

    import tree_sitter_objc as tsobjc
    from tree_sitter import Language, Parser
    language = Language(tsobjc.language())
    parser = Parser(language)
    tree = parser.parse(open('rendezvous_dynamics.m', 'rb').read())
    print(tree.root_node.has_error)  # True

    root.has_error = True, with the top-level children coming back as generic declaration/expression_statement nodes that don't correspond to any real MATLAB semantics — the parser is just doing its best to force MATLAB syntax into a C-family grammar. This is worse than silently skipping the file: it's a genuine risk of extracting garbage nodes/edges from whatever fragments happen to parse as "valid enough" Objective-C, not just missing coverage.

    The fix has a direct precedent already in this codebase. extract.py already content-sniffs .h files to route between extract_cpp and extract_objc rather than trusting the extension alone (see the comments around line 12093/12383: "a .h may route to either extract_cpp or extract_objc by content"). The natural fix for .m is the same pattern: content-sniff for Objective-C markers (@interface, @implementation, @end, #import) vs. MATLAB markers (function ... end block structure, %/%{ %} comment style), and route non-Objective-C .m files to a new extract_matlab() built on tree-sitter-matlab (still needs writing, per my original report, but the dispatch half of this is a small, idiomatic addition matching existing code).

    Happy to share the two-line repro above against a larger MATLAB sample set if useful for testing the content-sniff heuristic.

  2. safishamsi commented on Jul 7, 2026

    @safishamsi
    Member

    Thanks to @catalystdream for the sharpened diagnosis — the content-sniff precedent (.h routing to extract_cpp vs extract_objc) was exactly the right pointer.

    On v8 (next release) I've fixed the garbage-parse half: .m is now content-sniffed like .h. A genuine Objective-C .m (carrying @implementation/@interface/@import/#import) still routes to extract_objc; a .m without any ObjC directive (MATLAB, Octave) no longer gets force-parsed by the Objective-C grammar into root.has_error garbage — it gets no extractor and is surfaced by the no-AST-extractor warning (#1689) instead of silently mis-parsed. .mm is unambiguously Objective-C++ and is untouched. Regression tests cover ObjC .m -> objc, MATLAB function/classdef .m -> no extractor, and .mm -> objc.

    Leaving this issue open for the primary ask — a real tree-sitter-matlab extractor (functions, classdef, calls). Now that .m won't produce wrong data in the meantime, that's a clean additive follow-up, and I'll take you up on the offer to test against a real MATLAB corpus when there's a WIP branch.

  3. added a commit that references this issue on Jul 7, 2026
  4. mgcooper commented on Sep 24, 2026

    @mgcooper

    Is MATLAB extraction still planned? PR #1888 ("feat(matlab): add first-class MATLAB extraction support") was closed unmerged on 2026-09-12, and its fork branch is gone, but refs/pull/1888/head still resolves (fbc69dd). Issue #2935 asks for the same extractor. We run graphify on MATLAB repositories and can test a successor branch against a MATLAB dependency-analysis oracle and report per-class recall. Is a successor branch planned, or should we test #1888's head?

  5. SyedFahad7 commented on Oct 2, 2026

    @SyedFahad7
    Contributor

    Yes. A new branch is the way to go, not #1888's head. That PR was closed by the author and the branch is gone, so that commit will just be behind current v8.

    The extractor is still the open part of this issue. tree-sitter-matlab is already on PyPI, and the .m sniff is already in: MATLAB files are skipped instead of parsed as Objective-C. What's left is the reader (functions, classdef, calls) wired to those .m files.

    If you open a PR against v8 and link this issue, the test you described is the useful part. Per-class recall against your MATLAB dependency oracle is exactly what this thread asked for once there's a branch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions