Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use textmate grammar instead of pygments #244

Open
watermarkhu opened this issue Mar 11, 2024 · 5 comments
Open

Use textmate grammar instead of pygments #244

watermarkhu opened this issue Mar 11, 2024 · 5 comments

Comments

@watermarkhu
Copy link

watermarkhu commented Mar 11, 2024

Hi @joeced, great work on maintaining this repo.

A year ago, I wanted to contribute to support argument blocks. However, I've found that the logic in mat_types.py based on the Pygments tokens to be very hard to work with, and a bit unstable.

Following MathWorks' support for VSCode, I had started on working a parser based on TextMate grammars using Python, which is used for syntax highlighting in VSCode. MathWorks is now also maintaining the MATLAB grammar.

The package is available at https://github.com/watermarkhu/textmate-grammar-python. If you are interested, I think this can be a good replacement for the currently in-house parsing of matlabdomain. The benefit of using TextMate grammar is that 1) due to its nested nature, the output is already a syntax tree and 2) parsing is now officially supported by MathWorks and the contributors of the VSCode extension.

On a different topic, due to some requirements, I will need to have an auto-documenter that is compatible with markdown docstrings. To this end, I've already started work on a new extension that is dependent on the myst-parser and based on autodoc2. I would love to get in touch with you to understand the matlabdomain better to see what I can re-use.

@joeced
Copy link
Collaborator

joeced commented Mar 12, 2024

Hi @watermarkhu

This looks really interesting. At the moment I started tackling #44 and #222, and the pygments token output is just a mess to start parsing. I'll give a shot a see if it can replace pygments and then improve the functionality.

Regarding starting up a new auto-documenter, I can only tell how this domain was started. The original author basically built the documenter directly upon autodoc for Python. This gave them a good start and basis.
However, the code is not the easiest to work with in my opinion. We still run into features that needs to be reimplemented, for instance #180. Even after maintaining the package for many years now, I still struggle with the Sphinx internals of Documenter and Directives 😵.

A different approach for autodoc is done in https://github.com/mozilla/sphinx-js. I hope this helps.

@watermarkhu
Copy link
Author

Good to hear!

I'm currently mostly struggling with setting up roles in a new domain in order to make cross-referencing possible eventually. Can we possibly setup a call?

@joeced
Copy link
Collaborator

joeced commented Mar 12, 2024

I tried textmate-grammar-python and looks way nicer with the tokenization (see #222 (comment)). Definitely makes it easier to deduce if it's method definition in an abstract class. Further, I really like the nested dictionaries, where I can just skip the body of a function, once I collected what I need.
It will require a lot of re-writing, but I'm quite tempted by it.

We can setup a call, but be warned I am by no means an expert in the cross-referencing. You can contact me at jorgen at cederberg dot be.

@joeced
Copy link
Collaborator

joeced commented Mar 12, 2024

@watermarkhu Two comments to https://github.com/watermarkhu/textmate-grammar-python:

  • Requirement for Python 3.11 is hard for sphinxcontrib-matlabdomain. I still support version 3.9.
  • Requirement for PyYAML >=7 is in conflict with conan version requirement of PyYAML>=6.0, <7.0.

Do you want me to add them as issues?

@watermarkhu
Copy link
Author

Good to see! Adding the issues would be great.

Let's discuss about 3.9 support on the PR that you submitted.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants