branch: externals/matlab-mode
commit 9a5abdd38dbcbae2457caf7e5c3e37e3c97250e4
Author: John Ciolfi <[email protected]>
Commit: John Ciolfi <[email protected]>
matlab-ts-mode: improve font-lock
---
Makefile | 4 +-
contributing/treesit-mode-how-to.org | 283 ++++++++++++---------
matlab-ts-mode.el | 56 ++--
tests/metest.el | 6 +-
.../test-matlab-ts-mode-font-lock-files/FlowRate.m | 9 +
.../FlowRate_expected.txt | 9 +
.../MyClass_expected.txt | 2 +-
.../MySubSubClass_expected.txt | 2 +-
.../MySubclass_expected.txt | 2 +-
tests/test-matlab-ts-mode-font-lock-files/Prop.m | 11 +
.../Prop_expected.txt | 11 +
.../attributeDemo.m | 14 +
.../attributeDemo_expected.txt | 14 +
.../small_in_args.m | 2 +-
.../small_in_args_expected.txt | 2 +-
.../test_arguments.m | 3 +
.../test_arguments_expected.txt | 11 +-
.../test_classdef_MultiplePropBlocks_expected.txt | 8 +-
.../test_classdef_PropertyAccess_expected.txt | 8 +-
.../test_classdef_events.m | 11 +
.../test_classdef_events_expected.txt | 11 +
.../test_enum.m | 8 +
.../test_enum_expected.txt | 8 +
.../test_methods.m | 11 +
.../test_methods_expected.txt | 11 +
tests/test-matlab-ts-mode-font-lock.el | 1 +
26 files changed, 344 insertions(+), 174 deletions(-)
diff --git a/Makefile b/Makefile
index 492dea3c9b..93663888c1 100644
--- a/Makefile
+++ b/Makefile
@@ -31,7 +31,9 @@ LOADPATH = ./
LOADDEFS = matlab-autoload.el
LOADDIRS = .
-EL_SRCS = $(filter-out $(LOADDEFS), $(wildcard *.el))
+EL_SRCS := $(filter-out $(LOADDEFS), $(wildcard *.el))
+# Ignore flycheck_* files created by the flycheck Emacs package
+EL_SRCS := $(filter-out flycheck_%, $(EL_SRCS))
# Emacs 30 or later has treesit built-in. If running older Emacs, don't build
it.
HAVE_TREESIT_EMACS = $(shell "$(EMACS)" --batch -Q --eval \
diff --git a/contributing/treesit-mode-how-to.org
b/contributing/treesit-mode-how-to.org
index 5a9ff32477..7066b62b89 100644
--- a/contributing/treesit-mode-how-to.org
+++ b/contributing/treesit-mode-how-to.org
@@ -29,174 +29,215 @@
This is a set of notes that I'm taking as I develop matlab-ts-mode.el with the
goal of this
becoming a guide for writting a tree-sitter mode for Emacs 30 or later.
-* Issues
+* Guide to building a tree-sitter mode
-- [ ] Building libtree-sitter-matlab.dll from src on Windows produces a DLL
that fails.
+** Syntax trees and queries
- - Install MSYS2
- - Run MSYS2 bash, then: pacman -S gcc
- - Install gpg from https://www.gpg4win.org/ and place it on on the path
before MSYS2.
- - Install matlab tree sitter from src using Emacs 30.1
- #+begin_example
- emacs
- M-x treesit-install-language-grammar
- Language: matlab
- There is no recipe for matlab, do you want to build it interactively? (y
or n) y
- Enter the URL of the Git repository of the language grammar:
https://github.com/acristoffers/tree-sitter-matlab
- Enter the tag or branch (default: default branch): abi/14
- Enter the subdirectory in which the parser.c file resides (default: "src"):
- Enter the C compiler to use (default: auto-detect):
- Enter the C++ compiler to use (default: auto-detect):
- Install to (default: ~/.emacs.d/tree-sitter):
- #+end_example
+If you are not familar with the concepts behind tree-sitter, see
+https://tree-sitter.github.io/tree-sitter. In particular, learn the notion of
queries and try out
+queries in the playground section of the site on one of the languages
supported by the site. A
+good understanding of the syntax tree and queires are required to implement a
new tree-sitter
+major mode. You don't need to understand how to implement a lanugage parser if
one already
+exists, otherwise you'll need to write a tree-sitter language parser.
- The resulting dll is bad. Maybe gcc 13 is not a valid version of gcc.
+The tree-sitter parser produces a syntax tree:
- Note the build of the dll from
https://github.com/emacs-tree-sitter/tree-sitter-langs is good.
+#+begin_example
+ +-------+ +-----------------------------+
+ | | | |
+ | Emacs |<===>| libtree-sitter-LANUGAGE.EXT |
+ | | | |
+ +-------+ +-----------------------------+
+#+end_example
-- [ ] M-x treesit-install-language-grammar should specify the tree-sitter ABI
version.
+The libtree-sitter-LANUAGE.EXT shared library (EXT = .so on Linux, .dll on
Windows, or .dylib on
+Mac) is used to create a syntax tree of LANUAGE:
- Emacs 30.1 is ABI 14 from =(treesit-library-abi-version)=, which is behind
the current tree-sitter
- version, 15.
+#+begin_example
+ LANUAGE program Syntax Tree
- Emacs should do something like:
+ c = a + b =
+ / \
+ c +
+ a b
+#+end_example
- : tree-sitter generate --abi 13
- : gcc src/*.c -I./src -o ~/.emacs.d/tree-sitter/libtree-sitter-matlab.EXT
--shared -fPIC -Os
+Each node in the syntax tree knows it start point and end point in the
LANGUAGE program. The
+parser is fast and incrementally updates as you type. The memory required to
represent the syntax
+tree is roughly 10 times the text size of the program being analyzed. However,
the benefits of
+tree sitter are highly accuracte and fast syntax coloring (font-lock),
indentation, code
+navigation via syntatic expressions, etc.
- where EXT = .dll, .so, or .dylib.
+** Documentation
-* Guide to building a tree-sitter mode
+ -
[[https://www.gnu.org/software/emacs/manual/html_node/elisp/Parsing-Program-Source.html][Emacs
manual: Parsing Program Source]]
+ -
[[https://www.gnu.org/software/emacs/manual/html_node/elisp/Parser_002dbased-Indentation.html][Emacs
manual: Parser-based Indentation]]
+
+** libtree-sitter-LANGUAGE.EXT
+
+Place the tree-sitter language library in
=~/.emacs.d/tree-sitter/libtree-sitter-LANGUAGE.EXT=
+(EXT=.so on Linux, .dll on Windows, .dylib on Mac). There are other locations
that this can
+reside in, though =~/.emacs.d/tree-sitter/= is the default.
+
+- You can grab the LANGUAGE.EXT from
https://github.com/emacs-tree-sitter/tree-sitter-langs/releases
+ and rename it to =~/.emacs.d/tree-sitter/libtree-sitter-LANGUAGE.EXT=.
+
+- You can build it using
+
+ : M-x treesit-install-language-grammar
-1. Syntax trees and queries. If you are not familar with the concepts behind
tree-sitter, see
- https://tree-sitter.github.io/tree-sitter. In particular, learn the notion
of queries and try out
- queries in the playground section of the site on one of the languages
supported by the site. A
- good understanding of the syntax tree and queires are required to implement
a new tree-sitter
- major mode. You don't need to understand how to implement a lanugage parser.
+Next, create a basic LANGUAGE-ts-mode.el to validate your tree-sitter shared
library is good.
-2. Documentation
+It is possible that =~/.emacs.d/tree-sitter/libtree-sitter-LANGUAGE.EXT= was
built incorrectly,
+so we create the following to validate it, replacing LANGUAGE with your
language name.
- -
[[https://www.gnu.org/software/emacs/manual/html_node/elisp/Parsing-Program-Source.html][Emacs
manual: Parsing Program Source]]
- -
[[https://www.gnu.org/software/emacs/manual/html_node/elisp/Parser_002dbased-Indentation.html][Emacs
manual: Parser-based Indentation]]
+#+begin_src emacs-lisp
+ ;; Basic LANGUAGE-ts-mode.el
-3. Place the tree-sitter language library in
=~/.emacs.d/tree-sitter/libtree-sitter-LANGUAGE.EXT=
- (EXT=.so on Linux, .dll on Windows, .dylib on Mac)
+ (require 'treesit)
- - You can grab the LANGUAGE.EXT from
https://github.com/emacs-tree-sitter/tree-sitter-langs/releases
- and rename it to =~/.emacs.d/tree-sitter/libtree-sitter-LANGUAGE.EXT=.
+ (define-derived-mode LANGUAGE-ts-mode prog-mode "LANGUAGE"
+ "Major mode for editing LANGUAGE files with tree-sitter."
- - You can build it using
+ (when (treesit-ready-p 'LANGUAGE)
+ (treesit-parser-create 'LANGUAGE)
+ (treesit-major-mode-setup)))
- : M-x treesit-install-language-grammar
+ (provide 'LANGUAGE-ts-mode)
-4. Create a basic LANGUAGE-ts-mode.el to validate your tree-sitter shared
library is good.
+#+end_src
- It is possible that =~/.emacs.d/tree-sitter/libtree-sitter-LANGUAGE.EXT=
was built incorrectly,
- so we create the following to validate it, replacing LANGUAGE with your
language name.
+Validate your LANGAUGE-ts-mode works. Create foo.txt containing valid LANGUAGE
content, then open
+foo.txt in Emacs and run:
- #+begin_src emacs-lisp
- ;; Basic LANGUAGE-ts-mode.el
+: M-x LANGUAGE-ts-mode
- (require 'treesit)
+You should now be able to use:
- (define-derived-mode LANGUAGE-ts-mode prog-mode "LANGUAGE"
- "Major mode for editing LANGUAGE files with tree-sitter."
+: M-x treesit-inspect-mode
+: M-x treesit-explore-mode
- (when (treesit-ready-p 'LANGUAGE)
- (treesit-parser-create 'LANGUAGE)
- (treesit-major-mode-setup)))
+** Setup font-lock
- (provide 'LANGUAGE-ts-mode)
+Queries are needed to identify syntax tree nodes to fontify. See
+https://www.gnu.org/software/emacs/manual/html_node/elisp/Pattern-Matching.html
- #+end_src
+You can use =M-x treesit-explore-mode= to see the nodes of the syntax tree.
- Validate your LANGAUGE-ts-mode works. Create foo.txt containing valid
LANGUAGE content, then open
- foo.txt in Emacs and run:
+An example of a query that identifies comments (assuming =comment= is a valid
node type), in a
+file that has =M-x LANGUAGE-ts-mode= active.
- : M-x LANGUAGE-ts-mode
+: M-: (treesit-query-capture (treesit-buffer-root-node) '((comment) @comments))
- You should now be able to use:
+Suppose your lanugage contains the keyword "if", you can find all "if"
keywords using:
- : M-x treesit-inspect-mode
- : M-x treesit-explore-mode
+: M-: (treesit-query-capture (treesit-buffer-root-node) '("if" @keywords))
-5. Setup font-lock
+To capture all keywords of your language, use alternation. Here we are
capturing the "if"
+and "else" keywords:
- Queries are needed to identify syntax tree nodes to fontify. See
-
https://www.gnu.org/software/emacs/manual/html_node/elisp/Pattern-Matching.html
+: M-: (treesit-query-capture (treesit-buffer-root-node) '(["if" "else"]
@keywords))
- You can use =M-x treesit-explore-mode= to see the nodes of the syntax tree.
+Note, to validate your queries use:
- An example of a query that identifies comments (assuming =comment= is a
valid node type), in a
- file that has =M-x LANGUAGE-ts-mode= active.
+: M-x (treesit-query-validate 'LANGUAGE '(QUERRY @catpture-name))
- : M-: (treesit-query-capture (treesit-buffer-root-node) '((comment)
@comments))
+Once we know the queries, we can setup font-lock. For example, here we fontify
comments
+and keywords.
- Suppose your lanugage contains the keyword "if", you can find all "if"
keywords using:
+#+begin_src emacs-lisp
+ (require 'treesit)
- : M-: (treesit-query-capture (treesit-buffer-root-node) '("if" @keywords))
+ (defvar LANGUAGE-ts-mode--keywords
+ '("else"
+ "if"
+ ;; <snip>
+ )
+ "LANGUAGE keywords for tree-sitter font-locking.")
- To capture all keywords of your language, use alternation. Here we are
capturing the "if"
- and "else" keywords:
-
- : M-: (treesit-query-capture (treesit-buffer-root-node) '(["if" "else"]
@keywords))
+ (defvar LANGUAGE-ts-mode--font-lock-settings
+ (treesit-font-lock-rules
+ :language 'LANGUAGE
+ :feature 'comment
+ '((comment) @font-lock-comment-face)
- Note, to validate your queries use:
+ :language 'LANGUAGE
+ :feature 'keyword
+ `([,@LANGUAGE-ts-mode--keywords] @font-lock-keyword-face)))
+ "LANGUAGE tree-sitter font-lock settings.")
- : M-x (treesit-query-validate 'LANGUAGE '(QUERRY @catpture-name))
+ ;;;###autoload
+ (define-derived-mode LANGUAGE-ts-mode prog-mode "LANGUAGE"
+ "Major mode for editing LANGUAGE files using tree-sitter."
- Once we know the queries, we can setup font-lock. For example, here we
fontify comments
- and keywords.
+ (when (treesit-ready-p 'LANGUAGE)
+ (treesit-parser-create 'LANGUAGE)
- #+begin_src emacs-lisp
- (require 'treesit)
+ ;; Font-lock
+ (setq-local treesit-font-lock-settings
LANGUAGE-ts-mode--font-lock-settings)
- (defvar LANGUAGE-ts-mode--keywords
- '("else"
- "if"
- ;; <snip>
- )
- "LANGUAGE keywords for tree-sitter font-locking.")
+ ;; `treesit-font-lock-feature-list' contains four sublists where the
first
+ ;; sublist is level 1, and so on. Each sublist contains a set of feature
+ ;; names that correspond to the
+ ;; :feature 'NAME
+ ;; entries in LANGUAGE-ts-mode--font-lock-settings. For example,
'comment for comments,
+ ;; 'definition for function definitions, 'keyword for language keywords,
etc.
+ ;; Font-lock applies the faces defined in each sublist up to and
including
+ ;; `treesit-font-lock-level', which defaults to 3.
+ (setq-local treesit-font-lock-feature-list
+ '((comment definition)
+ (keyword string type)
+ (builtin constant escape-sequence label number)
+ (bracket delimiter error function operator property
variable)))
- (defvar LANGUAGE-ts-mode--font-lock-settings
- (treesit-font-lock-rules
- :language 'LANGUAGE
- :feature 'comment
- '((comment) @font-lock-comment-face)
+ (treesit-major-mode-setup)))
+#+end_src
- :language 'LANGUAGE
- :feature 'keyword
- `([,@LANGUAGE-ts-mode--keywords] @font-lock-keyword-face)))
- "LANGUAGE tree-sitter font-lock settings.")
+Notice how the @capture-name in the comment query is @font-lock-comment-face.
This face is
+applied to the items captured by the query. You can see available faces by
using =M-x
+list-faces-display=. You'll probably want to stick with faces that come with
stock Emacs to
+avoid dependenices on other packages or create your own face.
- ;;;###autoload
- (define-derived-mode LANGUAGE-ts-mode prog-mode "LANGUAGE"
- "Major mode for editing LANGUAGE files using tree-sitter."
+* Issues
+
+- [ ] Building libtree-sitter-matlab.dll from src on Windows produces a DLL
that fails.
+
+ - Install MSYS2
+ - Run MSYS2 bash, then: pacman -S gcc
+ - Install gpg from https://www.gpg4win.org/ and place it on on the path
before MSYS2.
+ - Install matlab tree sitter from src using Emacs 30.1
+ #+begin_example
+ emacs
+ M-x treesit-install-language-grammar
+ Language: matlab
+ There is no recipe for matlab, do you want to build it interactively? (y
or n) y
+ Enter the URL of the Git repository of the language grammar:
https://github.com/acristoffers/tree-sitter-matlab
+ Enter the tag or branch (default: default branch): abi/14
+ Enter the subdirectory in which the parser.c file resides (default: "src"):
+ Enter the C compiler to use (default: auto-detect):
+ Enter the C++ compiler to use (default: auto-detect):
+ Install to (default: ~/.emacs.d/tree-sitter):
+ #+end_example
- (when (treesit-ready-p 'LANGUAGE)
- (treesit-parser-create 'LANGUAGE)
+ The resulting dll is bad. Maybe gcc 13 is not a valid version of gcc.
- ;; Font-lock
- (setq-local treesit-font-lock-settings
LANGUAGE-ts-mode--font-lock-settings)
+ Note the build of the dll from
https://github.com/emacs-tree-sitter/tree-sitter-langs is good.
+
+- [ ] M-x treesit-install-language-grammar should specify the tree-sitter ABI
version.
+
+ Emacs 30.1 is ABI 14 from =(treesit-library-abi-version)=, which is behind
the current tree-sitter
+ version, 15.
+
+ Emacs should do something like:
+
+ : tree-sitter generate --abi 13
+ : gcc src/*.c -I./src -o ~/.emacs.d/tree-sitter/libtree-sitter-matlab.EXT
--shared -fPIC -Os
+
+ where EXT = .dll, .so, or .dylib.
- ;; `treesit-font-lock-feature-list' contains four sublists where the
first
- ;; sublist is level 1, and so on. Each sublist contains a set of
feature
- ;; names that correspond to the
- ;; :feature 'NAME
- ;; entries in LANGUAGE-ts-mode--font-lock-settings. For example,
'comment for comments,
- ;; 'definition for function definitions, 'keyword for language
keywords, etc.
- ;; Font-lock applies the faces defined in each sublist up to and
including
- ;; `treesit-font-lock-level', which defaults to 3.
- (setq-local treesit-font-lock-feature-list
- '((comment definition)
- (keyword string type)
- (builtin constant escape-sequence label number)
- (bracket delimiter error function operator property
variable)))
+- [ ] Easy deployment?
- (treesit-major-mode-setup)))
- #+end_src
+ : M-x list-packages
- Notice how the @capture-name in the comment query is
@font-lock-comment-face. This face is
- applied to the items captured by the query. You can see available faces by
using =M-x
- list-faces-display=. You'll probably want to stick with faces that come
with stock Emacs to
- avoid dependenices on other packages or create your own face.
+ makes it easy to install packages from ELPA, MELPA, etc. but how to we get
+ libtree-sitter-LANUGAGE.EXT (EXT = .so, .dll, .dylib) installed?
diff --git a/matlab-ts-mode.el b/matlab-ts-mode.el
index d558886a94..19370da7da 100644
--- a/matlab-ts-mode.el
+++ b/matlab-ts-mode.el
@@ -6,8 +6,7 @@
;; SPDX-License-Identifier: GPL-3.0-or-later
;;
;; Author: John Ciolfi <[email protected]>
-;; Maintainer: Eric M. Ludlam <[email protected]>, Uwe Brauer
<[email protected]>, John Ciolfi <[email protected]>
-;; Created: Jun-6-2025
+;; Created: Jun-14-2025
;; Keywords: MATLAB(R)
;; Package-Requires: ((emacs "30.1"))
@@ -82,6 +81,8 @@
"else"
"elseif"
"end"
+ "enumeration"
+ "events"
"for"
"function"
"global"
@@ -172,7 +173,8 @@ START and END specify the region to be fontified."
:language 'matlab
:feature 'comment
:override t
- '(((comment) @matlab-ts-comment-heading-face (:match "^%%\\(?:[ \t].+\\)?$"
@matlab-ts-comment-heading-face)))
+ '(((comment) @matlab-ts-comment-heading-face (:match "^%%\\(?:[ \t].+\\)?$"
+
@matlab-ts-comment-heading-face)))
;; Doc help comments
:language 'matlab
@@ -193,39 +195,29 @@ START and END specify the region to be fontified."
:feature 'definition
'((function_definition name: (identifier) @font-lock-function-name-face)
(class_definition name: (identifier) @font-lock-function-name-face)
- (superclasses (property_name (identifier)) @font-lock-function-name-face))
-
- ;; Function input and output arguments - variables
- :language 'matlab
- :feature 'definition
- '(
- ;; The input arguments: function functionName(in1, in2, in3)
+ (superclasses (property_name (identifier)) @font-lock-function-name-face)
+ ;; Function inputs: functionName(in1, in2, in3)
(function_arguments arguments:
(identifier) @font-lock-variable-name-face
("," (identifier) @font-lock-variable-name-face) :*)
- ;; Single output arugment: function out = functionName(in1, in2)
+ ;; Function single output arugment: function out = functionName(in1, in2)
(function_output (identifier) @font-lock-variable-name-face)
- ;; Multiple ouptut arguments: function [out1, out2] = functionName(in1,
in2)
+ ;; Function multiple ouptut arguments: function [out1, out2] =
functionName(in1, in2)
(function_output (multioutput_variable (identifier)
@font-lock-variable-name-face))
- ;; arguments block
- (arguments_statement (property name:
- (identifier) @font-lock-variable-name-face
- (_) @font-lock-type-face))
- (arguments_statement (property name:
- (property_name)
@font-lock-variable-name-face
- (_) @font-lock-type-face)))
-
- ;; classdef MyClass
- ;; properties (attributes)
- ;; Properties
- ;; end
- :language 'matlab
- :feature 'definition
- '(
- ;; Property block attributes
- (attribute (identifier) @font-lock-type-face "=" (_)
@font-lock-builtin-face)
- (attribute (identifier) @font-lock-type-face)
- (property name: (identifier) @font-lock-variable-name-face))
+ ;; Fields of: arguments ... end , properties ... end
+ (property (validation_functions (identifier) @font-lock-builtin-face))
+ (property name: (identifier) @font-lock-property-name-face
+ (identifier) @font-lock-type-face :?)
+ (property name: (property_name (identifier) @font-lock-property-name-face)
+ (identifier) @font-lock-type-face :?)
+ ;; (property name: (property_name (identifier)
@font-lock-property-name-face))
+ ;; Enumeration's
+ (enum (identifier) @font-lock-property-name-face)
+ ;; events block in classdef
+ (events (identifier) @font-lock-property-name-face)
+ ;; attributes of properties, methods
+ (attribute (identifier) @font-lock-type-face "=" (identifier)
@font-lock-builtin-face)
+ (attribute (identifier) @font-lock-type-face))
;; Strings
:language 'matlab
@@ -287,7 +279,7 @@ START and END specify the region to be fontified."
(setq-local treesit-font-lock-settings matlab-ts-mode--font-lock-settings)
(setq-local treesit-font-lock-feature-list
'((comment definition)
- (keyword string type variable)
+ (keyword string type)
(number)
(bracket delimiter error)))
diff --git a/tests/metest.el b/tests/metest.el
index 7707c4da9a..af924fd5fb 100644
--- a/tests/metest.el
+++ b/tests/metest.el
@@ -40,8 +40,6 @@
(require 'metest-imenu)
(require 'metest-imenu-tlc)
-(require 'test-matlab-ts-mode-font-lock)
-
(defun metest-all-syntax-tests ()
"Run all the syntax test cases in this file."
(setq debug-on-error t)
@@ -85,7 +83,9 @@
(metest-fill-paragraph))
;; matlab-ts-mode tests
- (metest-run 'test-matlab-ts-mode-font-lock))
+ (when (>= emacs-major-version 30)
+ (require 'test-matlab-ts-mode-font-lock)
+ (metest-run 'test-matlab-ts-mode-font-lock)))
(defun metest-run (test)
"Run and time TEST."
diff --git a/tests/test-matlab-ts-mode-font-lock-files/FlowRate.m
b/tests/test-matlab-ts-mode-font-lock-files/FlowRate.m
new file mode 100644
index 0000000000..f6c12cf3d5
--- /dev/null
+++ b/tests/test-matlab-ts-mode-font-lock-files/FlowRate.m
@@ -0,0 +1,9 @@
+% -*- matlab-ts -*-
+% See https://github.com/acristoffers/tree-sitter-matlab/issues/28
+classdef FlowRate < int32
+ enumeration
+ Low (10)
+ Medium (FlowRate.Low*5)
+ High (FlowRate.Low*10)
+ end
+end
diff --git a/tests/test-matlab-ts-mode-font-lock-files/FlowRate_expected.txt
b/tests/test-matlab-ts-mode-font-lock-files/FlowRate_expected.txt
new file mode 100644
index 0000000000..c707600a1f
--- /dev/null
+++ b/tests/test-matlab-ts-mode-font-lock-files/FlowRate_expected.txt
@@ -0,0 +1,9 @@
+c ccc ccccccccc ccc
+c ccc cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
+wwwwwwww wwwwwwww w wwwww
+ wwwwwwwwwww
+ www wwww
+ wwwwww wwwwwwwwwwwwwwww
+ wwww wwwwwwwwwwwwwwwww
+ www
+www
diff --git a/tests/test-matlab-ts-mode-font-lock-files/MyClass_expected.txt
b/tests/test-matlab-ts-mode-font-lock-files/MyClass_expected.txt
index 430286050f..16dc2200a3 100644
--- a/tests/test-matlab-ts-mode-font-lock-files/MyClass_expected.txt
+++ b/tests/test-matlab-ts-mode-font-lock-files/MyClass_expected.txt
@@ -4,7 +4,7 @@ h hhhh hhhhhhh
c ccccccc ccccc ccccccccccc
kkkkkkkkkk
- vvvvvvvvvv dddddd d nD c cccccc cccccccc cccc c ccccccc ccccc
+ PPPPPPPPPP tttttt d nD c cccccc cccccccc cccc c ccccccc ccccc
kkk
kkkkkkk
diff --git
a/tests/test-matlab-ts-mode-font-lock-files/MySubSubClass_expected.txt
b/tests/test-matlab-ts-mode-font-lock-files/MySubSubClass_expected.txt
index 5632a069c7..ed0d7ac1c2 100644
--- a/tests/test-matlab-ts-mode-font-lock-files/MySubSubClass_expected.txt
+++ b/tests/test-matlab-ts-mode-font-lock-files/MySubSubClass_expected.txt
@@ -2,7 +2,7 @@ c ccc ccccccccc ccc
kkkkkkkk ffffffffff d ffffffffffff d ffffffffffff
h hhhh hhhhhhh
kkkkkkkkkk
- vvvvvvvvvv dddddd d nD c cccccc cccccccc cccc c ccccccc ccccc
+ PPPPPPPPPP tttttt d nD c cccccc cccccccc cccc c ccccccc ccccc
kkk
kkkkkkk
diff --git a/tests/test-matlab-ts-mode-font-lock-files/MySubclass_expected.txt
b/tests/test-matlab-ts-mode-font-lock-files/MySubclass_expected.txt
index b860c8d50a..1e47f1aa5d 100644
--- a/tests/test-matlab-ts-mode-font-lock-files/MySubclass_expected.txt
+++ b/tests/test-matlab-ts-mode-font-lock-files/MySubclass_expected.txt
@@ -2,7 +2,7 @@ c ccc ccccccccc ccc
kkkkkkkk ffffffffff d fffffffffff
h hhhh hhhhhhh
kkkkkkkkkk
- vvvvvvvvvv dddddd d nD c cccccc cccccccc cccc c ccccccc ccccc
+ PPPPPPPPPP tttttt d nD c cccccc cccccccc cccc c ccccccc ccccc
kkk
kkkkkkk
diff --git a/tests/test-matlab-ts-mode-font-lock-files/Prop.m
b/tests/test-matlab-ts-mode-font-lock-files/Prop.m
new file mode 100644
index 0000000000..5e21e05dd9
--- /dev/null
+++ b/tests/test-matlab-ts-mode-font-lock-files/Prop.m
@@ -0,0 +1,11 @@
+% -*- matlab-ts -*-
+classdef Prop
+ properties
+ p0
+ p1 double;
+ p2 double = 0;
+ p3 (1,1) double;
+ p4 (1,1) double = 0;
+ p5 (1,1) double {mustBePositive} = 0;
+ end
+end
diff --git a/tests/test-matlab-ts-mode-font-lock-files/Prop_expected.txt
b/tests/test-matlab-ts-mode-font-lock-files/Prop_expected.txt
new file mode 100644
index 0000000000..c12de247c6
--- /dev/null
+++ b/tests/test-matlab-ts-mode-font-lock-files/Prop_expected.txt
@@ -0,0 +1,11 @@
+c ccc ccccccccc ccc
+kkkkkkkk ffff
+ kkkkkkkkkk
+ PP
+ PP ttttttD
+ PP tttttt d nD
+ PP bnDnb ttttttD
+ PP bnDnb tttttt d nD
+ PP bnDnb tttttt bBBBBBBBBBBBBBBb d nD
+ kkk
+kkk
diff --git a/tests/test-matlab-ts-mode-font-lock-files/attributeDemo.m
b/tests/test-matlab-ts-mode-font-lock-files/attributeDemo.m
new file mode 100644
index 0000000000..d915b5c901
--- /dev/null
+++ b/tests/test-matlab-ts-mode-font-lock-files/attributeDemo.m
@@ -0,0 +1,14 @@
+% -*- matlab-ts -*-
+% See https://github.com/acristoffers/tree-sitter-matlab/issues/29
+classdef attributeDemo
+ methods (Access = protected)
+ function out = method1(obj,inputArg)
+ ...
+ end
+ end
+ methods (Access = private)
+ function out = method2(obj,inputArg)
+ ...
+ end
+ end
+end
diff --git
a/tests/test-matlab-ts-mode-font-lock-files/attributeDemo_expected.txt
b/tests/test-matlab-ts-mode-font-lock-files/attributeDemo_expected.txt
new file mode 100644
index 0000000000..d98325a3a7
--- /dev/null
+++ b/tests/test-matlab-ts-mode-font-lock-files/attributeDemo_expected.txt
@@ -0,0 +1,14 @@
+c ccc ccccccccc ccc
+c ccc cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
+wwwwwwww wwwwwwwwwwwww
+ wwwwwww wwwwwww w wwwwwwwwww
+ wwwwwwww www w wwwwwwwwwwwwwwwwwwwww
+ www
+ www
+ www
+ wwwwwww wwwwwww w wwwwwwww
+ wwwwwwww www w wwwwwwwwwwwwwwwwwwwww
+ www
+ www
+ www
+www
diff --git a/tests/test-matlab-ts-mode-font-lock-files/small_in_args.m
b/tests/test-matlab-ts-mode-font-lock-files/small_in_args.m
index 4fa8490ec3..a1856f234b 100644
--- a/tests/test-matlab-ts-mode-font-lock-files/small_in_args.m
+++ b/tests/test-matlab-ts-mode-font-lock-files/small_in_args.m
@@ -3,5 +3,5 @@ function small_in_args(in)
% help comment
% code comment
- out = in;
+ disp(num2str(in));
end
diff --git
a/tests/test-matlab-ts-mode-font-lock-files/small_in_args_expected.txt
b/tests/test-matlab-ts-mode-font-lock-files/small_in_args_expected.txt
index 5735ea55b6..91012a77ad 100644
--- a/tests/test-matlab-ts-mode-font-lock-files/small_in_args_expected.txt
+++ b/tests/test-matlab-ts-mode-font-lock-files/small_in_args_expected.txt
@@ -3,5 +3,5 @@ kkkkkkkk fffffffffffffbvvb
h hhhh hhhhhhh
c cccc ccccccc
- ddd d ddD
+ ddddbdddddddbddbbD
kkk
diff --git a/tests/test-matlab-ts-mode-font-lock-files/test_arguments.m
b/tests/test-matlab-ts-mode-font-lock-files/test_arguments.m
index cf94ebcdbf..7c1a18f351 100644
--- a/tests/test-matlab-ts-mode-font-lock-files/test_arguments.m
+++ b/tests/test-matlab-ts-mode-font-lock-files/test_arguments.m
@@ -3,6 +3,9 @@ function test_arguments(in1, properties, options)
arguments
in1 (1,:) {mustBeNumeric}
properties double
+ foo (1,1) string
+ options.goo
+ options.bar double
options.LineStyle (1,1) string = "-"
options.LineWidth (1,1) {mustBeNumeric} = 1
end
diff --git
a/tests/test-matlab-ts-mode-font-lock-files/test_arguments_expected.txt
b/tests/test-matlab-ts-mode-font-lock-files/test_arguments_expected.txt
index fc26c3d61f..7d40474cb7 100644
--- a/tests/test-matlab-ts-mode-font-lock-files/test_arguments_expected.txt
+++ b/tests/test-matlab-ts-mode-font-lock-files/test_arguments_expected.txt
@@ -1,9 +1,12 @@
c ccc ccccccccc ccc
kkkkkkkk ffffffffffffffbvvvD vvvvvvvvvvD vvvvvvvb
kkkkkkkkk
- vvv ttttt ttttttttttttttt
- vvvvvvvvvv tttttt
- vvvvvvvvvvvvvvvvv ttttt tttttt t ttt
- vvvvvvvvvvvvvvvvv ttttt ttttttttttttttt t t
+ PPP bnDDb bBBBBBBBBBBBBBb
+ PPPPPPPPPP tttttt
+ PPP bnDnb tttttt
+ PPPPPPPDPPP
+ PPPPPPPDPPP tttttt
+ PPPPPPPDPPPPPPPPP bnDnb tttttt d SsS
+ PPPPPPPDPPPPPPPPP bnDnb bBBBBBBBBBBBBBb d n
kkk
kkk
diff --git
a/tests/test-matlab-ts-mode-font-lock-files/test_classdef_MultiplePropBlocks_expected.txt
b/tests/test-matlab-ts-mode-font-lock-files/test_classdef_MultiplePropBlocks_expected.txt
index 7fdad344de..b6af91a1bc 100644
---
a/tests/test-matlab-ts-mode-font-lock-files/test_classdef_MultiplePropBlocks_expected.txt
+++
b/tests/test-matlab-ts-mode-font-lock-files/test_classdef_MultiplePropBlocks_expected.txt
@@ -1,10 +1,10 @@
c ccc ccccccccc ccc
kkkkkkkk ffffffffffffffffff
- kkkkkkkkkk bttttttttt d BBBBBBBD ttttttttt d BBBBBBBBBBBBBb
- vvvvvvvvv
- vvvvvvvvv
+ kkkkkkkkkk bttttttttt d BBBBBBBD ttttttttt d bDddddddddddbb
+ PPPPPPPPP
+ PPPPPPPPP
kkk
kkkkkkkkkk bttttttttb
- vvvvvvvvv
+ PPPPPPPPP
kkk
kkk
diff --git
a/tests/test-matlab-ts-mode-font-lock-files/test_classdef_PropertyAccess_expected.txt
b/tests/test-matlab-ts-mode-font-lock-files/test_classdef_PropertyAccess_expected.txt
index 94cfae4fb2..bd3e0a56f6 100644
---
a/tests/test-matlab-ts-mode-font-lock-files/test_classdef_PropertyAccess_expected.txt
+++
b/tests/test-matlab-ts-mode-font-lock-files/test_classdef_PropertyAccess_expected.txt
@@ -1,9 +1,9 @@
c ccc ccccccccc ccc
kkkkkkkk ffffffffffffffffffffffffffff
- kkkkkkkkkk bttttttttt d BBBBBBBBB BBBBBBBBb
- vvvvv
+ kkkkkkkkkk bttttttttt d bDddddddD Dddddddbb
+ PPPPP
kkk
- kkkkkkkkkk btttttt d BBBBBBBb
- vvvvv
+ kkkkkkkkkk btttttt d Dddddddb
+ PPPPP
kkk
kkk
diff --git a/tests/test-matlab-ts-mode-font-lock-files/test_classdef_events.m
b/tests/test-matlab-ts-mode-font-lock-files/test_classdef_events.m
new file mode 100644
index 0000000000..3de94593ba
--- /dev/null
+++ b/tests/test-matlab-ts-mode-font-lock-files/test_classdef_events.m
@@ -0,0 +1,11 @@
+% -*- matlab-ts -*-
+classdef test_classdef_events < handle
+ events
+ StateChange
+ end
+ methods
+ function triggerEvent(obj)
+ notify(obj,'StateChange')
+ end
+ end
+end
diff --git
a/tests/test-matlab-ts-mode-font-lock-files/test_classdef_events_expected.txt
b/tests/test-matlab-ts-mode-font-lock-files/test_classdef_events_expected.txt
new file mode 100644
index 0000000000..c4b61f5613
--- /dev/null
+++
b/tests/test-matlab-ts-mode-font-lock-files/test_classdef_events_expected.txt
@@ -0,0 +1,11 @@
+c ccc ccccccccc ccc
+kkkkkkkk ffffffffffffffffffff d ffffff
+ kkkkkk
+ PPPPPPPPPPP
+ kkk
+ kkkkkkk
+ kkkkkkkk ffffffffffffbvvvb
+ ddddddbdddDSsssssssssssSb
+ kkk
+ kkk
+kkk
diff --git a/tests/test-matlab-ts-mode-font-lock-files/test_enum.m
b/tests/test-matlab-ts-mode-font-lock-files/test_enum.m
new file mode 100644
index 0000000000..dee39a74bc
--- /dev/null
+++ b/tests/test-matlab-ts-mode-font-lock-files/test_enum.m
@@ -0,0 +1,8 @@
+% -*- matlab-ts -*-
+classdef test_enum < int32
+ enumeration
+ Low (0)
+ Medium (1)
+ High (2)
+ end
+end
diff --git a/tests/test-matlab-ts-mode-font-lock-files/test_enum_expected.txt
b/tests/test-matlab-ts-mode-font-lock-files/test_enum_expected.txt
new file mode 100644
index 0000000000..9b76b1a75a
--- /dev/null
+++ b/tests/test-matlab-ts-mode-font-lock-files/test_enum_expected.txt
@@ -0,0 +1,8 @@
+c ccc ccccccccc ccc
+kkkkkkkk fffffffff d fffff
+ kkkkkkkkkkk
+ PPP bnb
+ PPPPPP bnb
+ PPPP bnb
+ kkk
+kkk
diff --git a/tests/test-matlab-ts-mode-font-lock-files/test_methods.m
b/tests/test-matlab-ts-mode-font-lock-files/test_methods.m
new file mode 100644
index 0000000000..4bf39f001b
--- /dev/null
+++ b/tests/test-matlab-ts-mode-font-lock-files/test_methods.m
@@ -0,0 +1,11 @@
+% -*- matlab-ts -*-
+classdef test_methods
+ methods (Access = protected)
+ function out = method1(obj,inputArg)
+ end
+ end
+ methods (Access = private)
+ function out = method2(obj,inputArg)
+ end
+ end
+end
diff --git
a/tests/test-matlab-ts-mode-font-lock-files/test_methods_expected.txt
b/tests/test-matlab-ts-mode-font-lock-files/test_methods_expected.txt
new file mode 100644
index 0000000000..074ebd0bcf
--- /dev/null
+++ b/tests/test-matlab-ts-mode-font-lock-files/test_methods_expected.txt
@@ -0,0 +1,11 @@
+c ccc ccccccccc ccc
+kkkkkkkk ffffffffffff
+ kkkkkkk btttttt d BBBBBBBBBb
+ kkkkkkkk vvv d fffffffbvvvDvvvvvvvvb
+ kkk
+ kkk
+ kkkkkkk btttttt d BBBBBBBb
+ kkkkkkkk vvv d fffffffbvvvDvvvvvvvvb
+ kkk
+ kkk
+kkk
diff --git a/tests/test-matlab-ts-mode-font-lock.el
b/tests/test-matlab-ts-mode-font-lock.el
index 340b2cf1e1..dca7cd9966 100644
--- a/tests/test-matlab-ts-mode-font-lock.el
+++ b/tests/test-matlab-ts-mode-font-lock.el
@@ -88,6 +88,7 @@ For debugging, you can run with a specified M-FILE,
("s" . font-lock-string-face)
("S" . matlab-ts-string-delimiter-face)
("p" . matlab-ts-pragma-face)
+ ("P" . font-lock-property-name-face)
("t" . font-lock-type-face)
("v" . font-lock-variable-name-face)
("w" . font-lock-warning-face)