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

how do I write my own syntax? #475

Closed
duckfromdiscord opened this issue Apr 30, 2023 · 3 comments
Closed

how do I write my own syntax? #475

duckfromdiscord opened this issue Apr 30, 2023 · 3 comments

Comments

@duckfromdiscord
Copy link

It is not really clear how I can write my own syntaxes start to finish for use with syntect. I have the regexes I need to figure out what needs to be highlighted where, but I do not know how to make these into a .sublime-syntax file that will work with syntect. For one thing, I see in the Sublime docs that definitions generally look like this:

contexts:
  main:
    - match: \b(if|else|for|while)\b
      scope: keyword.control.c
    - match: '"'
      push: string

How does syntect know that the keyword.control.c scope needs to be highlighted as any color in particular? Does the color theme have some sort of marking for keyword.control.* that will highlight any statement with a given Scope as long as it starts with keyword.control.*?

The docs explain quite well how to load and manipulate syntaxes, but they don't say anything about how to write them.

@keith-hall
Copy link
Collaborator

How does syntect know that the keyword.control.c scope needs to be highlighted as any color in particular? Does the color theme have some sort of marking for keyword.control.* that will highlight any statement with a given Scope as long as it starts with keyword.control.*?

Yes: http://www.sublimetext.com/docs/scope_naming.html

http://www.sublimetext.com/docs/selectors.html

The [syntect] docs explain quite well how to load and manipulate syntaxes, but they don't say anything about how to write them.

It's generally assumed that syntaxes are written for Sublime Text or Sublime Merge, as opposed to directly for syntect, but these days syntaxes are written especially for https://github.com/sharkdp/bat, so probably we should add some more documentation in syntect on this subject, even if it is just linking to other docs. Thanks for the feedback.

There's also some tips at sublimehq/Packages#757, but they assume you already know the basics.

If you prefer tutorial videos, @OdatNurd has done a great job covering all of these concepts. I'm not sure about a specific video to link to, but one/some of these may be a good starting point: https://www.youtube.com/@OdatNurd/search?query=syntax

@duckfromdiscord
Copy link
Author

Scope naming is exactly what I needed. Thank you. Very great to see that you take a lot of care maintaining syntect 😃

@duckfromdiscord
Copy link
Author

So I'll close this then. Thank you :)

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