镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

❇️ Add Matlab support #82

Description

@Sereinme

Language Name

Matlab (.m)

Tree-Sitter Grammar

https://github.com/acristoffers/tree-sitter-matlab

I will work on this

Yes

Additional Info (optional)

No response

Activity

  1. kkilchrist commented on Dec 30, 2025

    @kkilchrist

    @Sereinme -- just wanted to share an update on MATLAB support. I had started to work on this, but ended up using regex to solve my limited issue. But wanted to share what I learned / fixed. I do NOT plan to revisit this to integrate, but this might help you.

    SPM Resolution Fix

    The tree-sitter-matlab package had an SPM resolution bug that prevented it from being added as a dependency. I filed an issue and PR upstream:

    So the SPM blocker is now resolved!

    .m Extension Conflict

    However, there's a significant challenge: both MATLAB and Objective-C use the .m extension. This will require content-based heuristics to disambiguate between them.

    Here's a scoring approach we sketched out:

    Objective-C Indicators

    Definitive (50 points each):

    • #import / #include preprocessor directives
    • @interface, @implementation, @protocol, @end

    Strong (10-20 points):

    • @property, @synthesize, @dynamic (20)
    • Method declarations: - ( or + ( (20)
    • Nested brackets [[...]] for message sending (15)
    • @selector, @autoreleasepool, @synchronized, @try, @catch (15)
    • String literals @"..." (10)
    • Literals @YES, @NO, @[], @{} (10)
    • Block syntax ^{ or ^( (10)
    • C-style comments // (5)

    MATLAB Indicators

    Definitive (50 points):

    • function result = name(args) at line start
    • classdef ClassName at line start

    Strong (3-15 points):

    • % comments (8)
    • Keywords: elseif, parfor, spmd, persistent, global, arguments (15)
    • Anonymous functions @(args) (15)
    • Element-wise operators .*, ./, .^, .' (10)
    • Function handles @functionName (8)
    • Matrix syntax [1 2; 3 4] (8)
    • Logical NOT ~= or ~ (5)
    • end keyword (5)
    • Range syntax 1:10 (3)
    • Cell arrays {a, b} (3)

    Tie-breaker: If both scores are 0, default to Objective-C (more common on macOS).

    This would require extending the language detection logic in CodeLanguage+DetectLanguage.swift to handle this case, similar to how the codebase already handles shebang and modeline detection.

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

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions