Repository navigation
❇️ Add Matlab support #82
Description
Activity
@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-matlabpackage had an SPM resolution bug that prevented it from being added as a dependency. I filed an issue and PR upstream:- Issue: SPM package resolution fails due to dynamic FileManager check in Package.swift acristoffers/tree-sitter-matlab#144
- Fix: fix: SPM compatibility for Package.swift acristoffers/tree-sitter-matlab#145
- My fork has the fix here if you want to reference it -- https://github.com/kkilchrist/tree-sitter-matlab/tree/main
So the SPM blocker is now resolved!
.mExtension ConflictHowever, there's a significant challenge: both MATLAB and Objective-C use the
.mextension. 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/#includepreprocessor 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 startclassdef ClassNameat 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) endkeyword (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.swiftto handle this case, similar to how the codebase already handles shebang and modeline detection.
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fields🆕 New
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