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

Text blocks in Enso grammar for TextMate based editor #7539

Merged
merged 5 commits into from
Aug 18, 2023

Conversation

JaroslavTulach
Copy link
Member

@JaroslavTulach JaroslavTulach commented Aug 10, 2023

Pull Request Description

New rules to recognize """ and ''' at the end of line and color everything that's inside nested block of text as string. It properly stops the string literal when nested block ends.

Important Notes

The text mate grammar rules properly end the text block when the block ends. For example in:

main =
    x = """
        a text
    y

a text is properly recognized as string.

Checklist

Please ensure that the following checklist has been satisfied before submitting the PR:

Text Block properly ends

  • Screenshots/screencasts have been attached, if there are any visual changes. For interactive or animated visual changes, a screencast is preferred.
  • All code follows the style guides.
  • All code has been tested:
    • I tried to write a test for the grammar, but failed. Giving up for now.

@JaroslavTulach JaroslavTulach added the CI: No changelog needed Do not require a changelog entry for this PR. label Aug 10, 2023
@JaroslavTulach JaroslavTulach self-assigned this Aug 10, 2023
@JaroslavTulach JaroslavTulach force-pushed the wip/jtulach/TextMateGrammarStringBlocks branch from 361e542 to 1d40989 Compare August 10, 2023 05:54
@JaroslavTulach
Copy link
Member Author

foreign keyword is also painted in green as the line ends with """, but at least the main can follow and is rendered properly:
Pair_Spec_foreign

Copy link
Member

@Akirathan Akirathan left a comment

Choose a reason for hiding this comment

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

Very good and fast job, thanks! It is certainly much better than it used to be. Finally, all the tests that contains a lot of foreign functions will be rendered (almost) correctly

@radeusgd
Copy link
Member

Awesome! Would be cool to get the prefixes working, but it's already an improvement so I probably wouldn't wait on that. I don't have any ideas how to approach this - to do the end marker we need to capture the indentation before prefix, right? So I don't know if there's a way to not make it part of the match.

I have one small request, can we also add this change?

 					"name": "keyword.other",
-					"match": "\\b(here|this|type)\\b"
+					"match": "\\b(here|self|type)\\b"

We got rid of this a loooong time ago and replaced it with self - let's make the grammar reflect that - this is no longer a special keyword.

@JaroslavTulach
Copy link
Member Author

we need to capture the indentation before prefix, right?
I don't know if there's a way to not make it part of the match.

Right. The regexp is correct, but somebody needs to study the TextMate JSON to express that in spite whole line match only the """ is the token.

Or somehow use regexp look behind assertions?

@somebody1234
Copy link
Contributor

i'm not sure lookbehinds are an option here unfortunately, since the leading indentation still needs to be captured

@JaroslavTulach JaroslavTulach added the CI: Ready to merge This PR is eligible for automatic merge label Aug 18, 2023
@mergify mergify bot merged commit eb86d69 into develop Aug 18, 2023
25 checks passed
@mergify mergify bot deleted the wip/jtulach/TextMateGrammarStringBlocks branch August 18, 2023 07:55
@radeusgd
Copy link
Member

I have one small request, can we also add this change?

 					"name": "keyword.other",
-					"match": "\\b(here|this|type)\\b"
+					"match": "\\b(here|self|type)\\b"

We got rid of this a loooong time ago and replaced it with self - let's make the grammar reflect that - this is no longer a special keyword.

I assume we should do this as a follow up PR then?

Akirathan added a commit to Akirathan/enso-tmbundle that referenced this pull request Aug 21, 2023
@JaroslavTulach
Copy link
Member Author

I assume we should do this as a follow up PR then?

Ops. Sorry. I thought I merged the change, but I must have forgotten. Subsequent improvements to official Enso grammar are always welcomed.

mergify bot pushed a commit that referenced this pull request Aug 22, 2023
Following up on #7539 which introduced great improvements to the Enso grammar, I add some more to try to make it even better.

- Changing to highlight `self` instead of `this` (as the keyword was renamed a long time ago).
- Trying to include the string quotes to be highlighted as part of the string - a bit more controversial but IMO it looks more consistent with simple literals.

Before:
![image](https://github.com/enso-org/enso/assets/1436948/7d455c22-042a-4b43-a603-d661190aa7a4)

After:
![image](https://github.com/enso-org/enso/assets/1436948/5bfab6c0-ad67-4302-b5d3-0ef2fce232a9)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CI: No changelog needed Do not require a changelog entry for this PR. CI: Ready to merge This PR is eligible for automatic merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants