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

Identify newline separated segments #15

Merged
merged 17 commits into from
Sep 6, 2024

Conversation

sungshik
Copy link
Collaborator

@sungshik sungshik commented Aug 23, 2024

This PR adds improved support for segment-based "gobbling up" tokens in begin/end patterns. To motivate, suppose we have the following grammar:

lexical String = @category="string" "\"" Char* "\"";

lexical Char
    = [a-z]
    | "\\" [\"]
    ;

For instance, "asdf" and "foo\"bar" should be fully highlighted, but "foo"bar" should not be.

Before this PR, the following TextMate rule is generated (simplified):

{
  "begin": "\""
  "end": "\""
  "name": "string"
  "patterns": [
    { "match": "[a-z]" },
    { "match": "[\\]" },
    { "match": "[\"]" }
  ]
}

That is, roughly, for each symbol s in Char, a nested pattern is included to gobble up content between begin and end that matches individually s. However, gobbling up individual symbols is too fine-grained. For instance, with this rule, "foo\"bar" will not be fully highlighted: only "foo\" will be highlighted (because the \ is not considered in combination with the second ").

Instead of gobbling up individual symbols, the tokenizer should gobble up segments of symbols that belong together. That is what this PR adds.

After this PR, the following TextMate rule is generated (simplified):

{
  "begin": "\""
  "end": "\""
  "name": "string"
  "patterns": [
    { "match": "[a-z]" },
    { "match": "[\\][\"]" }
  ]
}

Copy link
Collaborator Author

@sungshik sungshik left a comment

Choose a reason for hiding this comment

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

A few additional comments

@sungshik sungshik marked this pull request as ready for review September 2, 2024 12:29
@sungshik sungshik marked this pull request as draft September 6, 2024 07:48
@sungshik sungshik marked this pull request as ready for review September 6, 2024 10:39
Copy link
Member

@DavyLandman DavyLandman left a comment

Choose a reason for hiding this comment

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

This looks a lot better indeed 👍 also the textmate regexes look more like you would expect them too.

Copy link
Collaborator Author

@sungshik sungshik left a comment

Choose a reason for hiding this comment

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

Thank you for the quick review, @DavyLandman, 🙂

@sungshik sungshik merged commit 17df6e6 into main Sep 6, 2024
2 checks passed
@sungshik sungshik deleted the identify-newline-separated-segments branch September 6, 2024 13:19
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