Skip to content
This repository has been archived by the owner on Dec 15, 2022. It is now read-only.

Fix missing scopes on separators and self, differentiate -> #224

Merged
merged 12 commits into from
Feb 4, 2021

Conversation

chbk
Copy link
Contributor

@chbk chbk commented Dec 6, 2017

Description of the Change

  • Added a separators entry to the repository

  • Rewrote the grammar for class and module declarations with begin/end patterns:

    • Included separators
    • Renamed punctuation.separator.inheritance.ruby to punctuation.separator.namespace.ruby for consistency
    • Changed entity.name.type.class.ruby, entity.name.type.module.ruby and entity.other.inherited-class.module.ruby to start with an uppercase letter and to exclude separators

    This is now scoped properly:

    class A::B::C < ::D::E
    class << A::B
    module A::B::C
  • Scoped commas in function declarations:

    def method(a, b)
  • Scoped self and separators in function declarations:

    class A
        def self.method

    Unfortunately, I wasn't able to rewrite the grammar for function declarations with begin/end patterns. I used existing regular expressions to capture separators. Since the captures are placed inside repetition patterns ()*, only the last separator will be scoped. Not perfect, but still an improvement.

  • Changed scopes for ->: support.function.kernel.arrow.ruby

  • Added specs

Applicable Issues

#221 Missing scope on commas
#222 Differentiate -> from other keywords
#223 Namespace separator :: not scoped in class definition

@Interdictor
Copy link

Please review and approve this!

@@ -60,60 +60,88 @@
'''
'patterns': [
{
'begin': '\\bclass\\b'
Copy link
Contributor

Choose a reason for hiding this comment

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

Do classes need to be at the start of the line per the previous ^\\s*class\\s* regex?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, classes can be declared after another statement on the same line.

}
{
'begin': '<<'
'captures':
Copy link
Contributor

Choose a reason for hiding this comment

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

beginCaptures

@@ -60,60 +60,88 @@
'''
'patterns': [
{
'begin': '\\bclass\\b'
'captures':
Copy link
Contributor

Choose a reason for hiding this comment

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

beginCaptures

'include': '#separators'
}
{
'begin': '<<'
Copy link
Contributor

Choose a reason for hiding this comment

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

Seems like you could redo this as (<<)\\s* and directly add a contentName here to get rid of the inner pattern.

]
}
{
'begin': '<'
Copy link
Contributor

Choose a reason for hiding this comment

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

Same as concerns as above.

}
{
'begin': '\\bmodule\\b'
Copy link
Contributor

Choose a reason for hiding this comment

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

Same concerns as above.

}
{
'match': ';'
'name': 'punctuation.separator.statement.ruby'
Copy link
Contributor

Choose a reason for hiding this comment

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

Generally tokenized as punctuation.terminator.statement

}
{
'match': ','
'name': 'punctuation.separator.object.ruby'
Copy link
Contributor

Choose a reason for hiding this comment

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

Generally tokenized as punctuation.separator.delimiter. Is , only for objects in Ruby?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There are also commas in hashes so punctuation.separator.delimiter is indeed better.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is it okay if I replace all instances of punctuation.separator.object by the generic punctuation.separator.delimiter? Commas in method calls are tokenized by line 2325 but commas in method definitions have their own regexes.

'name': 'punctuation.separator.object.ruby'
}
{
'match': '(::)\\s*(?=[A-Z])'
Copy link
Contributor

Choose a reason for hiding this comment

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

The \\s* can be in the lookahead.

Copy link
Contributor Author

@chbk chbk Mar 7, 2018

Choose a reason for hiding this comment

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

For some reason I thought lookaheads could only have a fixed number of characters.

grammars/ruby.cson Show resolved Hide resolved
@chbk
Copy link
Contributor Author

chbk commented Mar 13, 2018

@50Wliu I have a commit pending for punctuation.separator.delimiter, is my suggestion okay to you?

@50Wliu
Copy link
Contributor

50Wliu commented Mar 16, 2018

Yes, I think what you're saying is fine.

@chbk
Copy link
Contributor Author

chbk commented Oct 17, 2018

@50Wliu Do you have any other comments on this pull request? It looks ready to merge for me.

@rsese
Copy link

rsese commented Oct 17, 2018

Sorry for the delay @chbk, someone from the team will take a look as soon as they can.

@darangi
Copy link
Contributor

darangi commented Feb 4, 2021

Thanks for the contribution 🙇🏾 @chbk

@darangi darangi merged commit 3717f1d into atom:master Feb 4, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants