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

Simplify class and module grammar for more consistency #2242

Merged
merged 1 commit into from
Jul 5, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 22 additions & 24 deletions vscode/grammars/ruby.cson.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,20 +51,21 @@
"2": {
"name": "entity.name.type.class.ruby"
},
"4": {
"name": "entity.other.inherited-class.ruby"
},
"5": {
"name": "punctuation.separator.namespace.ruby"
},
"7": {
"name": "punctuation.separator.inheritance.ruby"
},
"6": {
"name": "variable.other.object.ruby"
"8": {
"name": "entity.other.inherited-class.ruby"
},
"7": {
"name": "punctuation.definition.variable.ruby"
"11": {
"name": "punctuation.separator.namespace.ruby"
}
},
"match": "(?x)\n^\\s*(class)\\s+\n(\n (\n [.a-zA-Z0-9_:]+\n (\\s*(<)\\s*[.a-zA-Z0-9_:]+)? # class A < B\n )\n |\n ((<<)\\s*[.a-zA-Z0-9_:]+) # class << C\n)",
"comment": "class Namespace::ClassName < OtherNamespace::OtherClassName",
"match": "(class)\\s*(([a-zA-Z0-9_]+)((::)[a-zA-Z0-9_]+)*)\\s*((<)\\s*(([a-zA-Z0-9_]+)((::)[a-zA-Z0-9_]+)*))?",
Copy link
Contributor

@andyw8 andyw8 Jul 5, 2024

Choose a reason for hiding this comment

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

For illustration:

s = "class Namespace::ClassName < OtherNamespace::OtherClassName"
re_old = "(?x)\n^\\s*(class)\\s+\n(\n  (\n    [.a-zA-Z0-9_:]+\n    (\\s*(<)\\s*[.a-zA-Z0-9_:]+)?   # class A < B\n 
 )\n  |\n  ((<<)\\s*[.a-zA-Z0-9_:]+)         # class << C\n)"
s.match(re_old)
=> 
#<MatchData
 "class Namespace::ClassName < OtherNamespace::OtherClassName"
 1:"class"
 2:"Namespace::ClassName < OtherNamespace::OtherClassName"
 3:"Namespace::ClassName < OtherNamespace::OtherClassName"
 4:" < OtherNamespace::OtherClassName"
 5:"<"
 6:nil
 7:nil>

re_new = "(class)\\s*(([a-zA-Z0-9_]+)((::)[a-zA-Z0-9_]+)*)\\s*((<)\\s*(([a-zA-Z0-9_]+)((::)[a-zA-Z0-9_]+)*))?"
s.match(re_new)
=> 
#<MatchData
 "class Namespace::ClassName < OtherNamespace::OtherClassName"
 1:"class"
 2:"Namespace::ClassName"
 3:"Namespace"
 4:"::ClassName"
 5:"::"
 6:"< OtherNamespace::OtherClassName"
 7:"<"
 8:"OtherNamespace::OtherClassName"
 9:"OtherNamespace"
 10:"::OtherClassName"
 11:"::">

"name": "meta.class.ruby"
},
{
Expand All @@ -75,27 +76,24 @@
"2": {
"name": "entity.name.type.module.ruby"
},
"3": {
"name": "entity.other.inherited-class.module.first.ruby"
},
"4": {
"name": "punctuation.separator.inheritance.ruby"
},
"5": {
"name": "entity.other.inherited-class.module.second.ruby"
},
"6": {
"name": "punctuation.separator.inheritance.ruby"
},
"7": {
"name": "entity.other.inherited-class.module.third.ruby"
"name": "punctuation.separator.namespace.ruby"
}
},
"match": "(module)\\s*(([a-zA-Z0-9_]+)((::)[a-zA-Z0-9_]+)*)",
"name": "meta.module.ruby"
},
{
"captures": {
"1": {
"name": "keyword.control.class.ruby"
},
"8": {
"2": {
"name": "punctuation.separator.inheritance.ruby"
}
},
"match": "(?x)\n^\\s*(module)\\s+\n(\n ([A-Z]\\w*(::))?\n ([A-Z]\\w*(::))?\n ([A-Z]\\w*(::))*\n [A-Z]\\w*\n)",
"name": "meta.module.ruby"
"match": "(class)\\s*(<<)\\s*",
"name": "meta.class.ruby"
},
{
"comment": "else if is a common mistake carried over from other languages. it works if you put in a second end, but it’s never what you want.",
Expand Down
Loading