Skip to content

Expand the syntax definition page - #159

Open
michaelblyons wants to merge 17 commits into
sublimetext-io:masterfrom
michaelblyons:syntax
Open

Expand the syntax definition page#159
michaelblyons wants to merge 17 commits into
sublimetext-io:masterfrom
michaelblyons:syntax

Conversation

@michaelblyons

@michaelblyons michaelblyons commented Jun 15, 2026

Copy link
Copy Markdown
Contributor
  • Groups syntax sections in guide and reference
  • Adds a parallel tutorial for sublime-syntax to the existing YAML-tmLanguage one.
  • Splits syntax engine discourse from the tutorial into a new page.

I did not use the "all 1.s" guidance in CONTRIBUTING so it's easier to notice if the "step X" references fall out of line.

Sources:
- Michael Lyons' description of tmLanguage
  https://stackoverflow.com/a/70007359/241211
- Nelo Mitranim's comment block in Go
  sublimehq/Packages#1662
@michaelblyons

This comment was marked as resolved.

@michaelblyons michaelblyons changed the title Start a syntax definition page Expand the syntax definition page Jun 16, 2026
@michaelblyons
michaelblyons marked this pull request as ready for review June 16, 2026 16:53
@FichteFoll
FichteFoll self-requested a review July 10, 2026 17:37

@FichteFoll FichteFoll left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for taking a jab at the syntax definition tutorial. I understand that you mostly used the legacy one for YAML-tmLanguage as the base and iterated on it from there (it shows), which I believe is a good approach. However, the old guide did not only use an old format but it was also not so great in a couple of ways.

I have annotated a couple points already that I would like to see a syntax guide to do better. I did not finish the review, but you can probably interpolate from the comments so far in what direction I personally would like the guide to go. Feel free to address the comments so far, but even if you do not I will try to set aside some time to work on this myself. As usual, no promises for an ETA, though.

Either way, before this can be merged it must provide value over the official documentation and should not provide obviously incomplete or wrong information. It does not have to be perfect, but it should not cause confusion either.

Comment thread docs/guide/extensibility/syntax/tutorial.md Outdated
Comment thread docs/guide/extensibility/syntax/tutorial.md Outdated
:::


## Analyzing Patterns

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm missing a general introduction of what "patterns" are used for, how syntax parsing works/is structured and what a context is. A comparison to a push-down automaton will also be helpful, perhaps even some graphical representation (optional). I believe this to be important to clarify before looking at what a "pattern" looks like.

@michaelblyons michaelblyons Jul 10, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is in the new index.md, but I can link it from here. I may come back to this section after I work on the other comments.

@michaelblyons michaelblyons Jul 10, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let me know what you think about the changes.

@michaelblyons michaelblyons Jul 13, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a diagram engine in the builder already?

sequenceDiagram
    Context->>+Character:Next character

    loop
        Character->>+Rule:First rule of context

        loop Try each rule in context
            alt Rule did not match
                Rule->>Rule:Next rule of context
                deactivate Character
            else Simple rule matched
                Rule->>Character:Consume characters with rule
            else Push / Pop / Set rule matched
                Rule->>-Context:Consume characters and change context stack
            end

            Rule->>Character:Next character
        end
    end
Loading

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alternative:

graph TB
    Start([Start])
    End([End])

    Contexts[(Contexts)]
    Context[/Current context/]
    Characters[(Characters)]
    Character[/Current char position/]
    Rules[(Rules)]
    Rule[/Current rule/]
    Match[/Match/]

    context-main[Set `main` context]

    char-eof{Is EOF?}

    rule-exists{Exists?}
    rule-matches{Matches?}
    rule-exists-no[Advance\n one char]

    Start-->context-main
    context-main-->Contexts
    Contexts-->Context
    Context-->Characters
    Characters-->Character
    Character-->char-eof
    char-eof--Yes.-->End
    char-eof--No.-->Rules
    Rules-->Rule
    Rule-->rule-exists
    rule-exists--No.-->rule-exists-no
    rule-exists-no-->Characters
    rule-exists--Yes.-->rule-matches
    rule-matches--No.-->Rules
    rule-matches--Yes.-->Match
    Match-->scope[Apply Scopes]
    scope-->advance-chars[Advance chars\n to end of match]
    advance-chars-->match-type{Context change?\n Push / Pop / Set}
    match-type--No.-->Characters
    match-type--Yes.-->change-context[Modify context stack]
    change-context-->Contexts
Loading

with a fallback to [Oniguruma][]'s engine.
Several existing syntax definitions make use of
features supported by Oniguruma that aren't part of
perl-style regular expressions, hence the requirement for the fallback.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's really not that many nowadays.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not in the shipped packages, but there's a whole ecosystem of third-party languages made God-knows-when.

Comment thread docs/guide/extensibility/syntax/tutorial.md Outdated
Comment thread docs/guide/extensibility/syntax/tutorial.md Outdated
Comment thread docs/guide/extensibility/syntax/tutorial.md Outdated
Comment thread docs/guide/extensibility/syntax/tutorial.md Outdated
Comment thread docs/guide/extensibility/syntax/tutorial.md Outdated
Multiple matches can have `pop` instructions.
Optional.

We'll use this rule to style nested complex fields in snippets:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I ran out of time here. (this is just a marker)

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

Successfully merging this pull request may close these issues.

2 participants