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

enh(scala) add Scala 3 end and extension soft keywords #3327

Merged
merged 3 commits into from Sep 9, 2021

Conversation

nicolasstucki
Copy link
Contributor

@nicolasstucki nicolasstucki commented Sep 6, 2021

Changes

Add Scala 3 end of definition or expression marker (see https://docs.scala-lang.org/scala3/reference/soft-modifier.html)

Simplified version of https://github.com/scala/vscode-scala-syntax/blob/main/src/typescript/Scala.tmLanguage.ts#L599-L634. Here we only need one kind of keyword.

Based on #3326

Checklist

  • Added markup tests, or they don't apply here because...
  • Updated the changelog at CHANGES.md


const END = {
className: 'keyword',
begin: /(?<=^\s*)end(\s+extension|\b)/
Copy link
Member

Choose a reason for hiding this comment

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

Is there some reason both these are special and can't simply be added to the keywords list? Is there a reason they absolutely need mode rules instead?

Are these not reserved words everywhere?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Are these not reserved words everywhere?

Unfortunately, they are not reserved keywords. It is not part of the Scala 2 syntax and Scala 3 only allows them in this particular context. Otherwise, they are considered normal identifiers. We can have names end/extension that can be defined with def extension: FileExtension = ... or members called end such as in line.end.

Is there some reason both these are special and can't simply be added to the keywords list? Is there a reason they absolutely need mode rules instead?

This is to avoid breaking code in Scala 2 and code in Scala 3 (in particular contexts).

Copy link
Member

Choose a reason for hiding this comment

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

Ok, I figured once I saw you using the normal keyword feature in your other PR. We'll still need to remove the look-behind here though and find another way.

@joshgoebel joshgoebel changed the title enh(scala) add Scala 3 end soft keyword enh(scala) add Scala 3 end and extension soft keywords Sep 7, 2021
@joshgoebel
Copy link
Member

@nicolasstucki Thanks for the work on this!

@joshgoebel
Copy link
Member

Looks good to me, reason it's still draft?

@nicolasstucki
Copy link
Contributor Author

It is a draft only because it depends on #3326 and any changes that might happen to that PR. Though we could skip/close #3326 and merge this one instead.

@nicolasstucki nicolasstucki marked this pull request as ready for review September 9, 2021 07:32
Add Scala 3 end of definition or expression.

Simplified verion of https://github.com/scala/vscode-scala-syntax/blob/main/src/typescript/Scala.tmLanguage.ts#L599-L634. Here we only need one kind of keyword.
@nicolasstucki
Copy link
Contributor Author

Managed to join the END rules to avoid having to modes.

begin: [
/^\s*/, // Is first token on the line
'extension',
/\s+(?=[[(])/, // followed by at least one space and `[` or `(`
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should I use escapes for ( and [ as in the other PR?
The rule would be /\s+(?=\[|\()/.

Copy link
Member

Choose a reason for hiding this comment

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

This is fine, it's a character group. But we don't generally use a single character group to avoid escapes, hence my flagging the other.

@joshgoebel joshgoebel merged commit 32bde79 into highlightjs:main Sep 9, 2021
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.

None yet

2 participants