-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Highlight Ruby method definitions without arguments #1523
Changes from 6 commits
8173ec6
2d2d9f1
d4695ca
eee0b86
2946ba0
1c7df91
5789c7d
5f60430
782ef55
79efe51
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,7 +13,7 @@ | |
greedy: true | ||
} | ||
], | ||
'keyword': /\b(?:alias|and|BEGIN|begin|break|case|class|def|define_method|defined|do|each|else|elsif|END|end|ensure|false|for|if|in|module|new|next|nil|not|or|protected|private|public|raise|redo|require|rescue|retry|return|self|super|then|throw|true|undef|unless|until|when|while|yield)\b/ | ||
'keyword': /\b(?:alias|and|BEGIN|begin|break|case|class|def|define_method|defined|do|each|else|elsif|END|end|ensure|false|for|if|in|module|new|next|nil|not|or|protected|private|public|raise|redo|require|rescue|retry|return|self|super|then|throw|true|undef|unless|until|when|while|yield)\b/, | ||
}); | ||
|
||
var interpolation = { | ||
|
@@ -27,6 +27,8 @@ | |
} | ||
}; | ||
|
||
delete Prism.languages.ruby.function; | ||
|
||
Prism.languages.insertBefore('ruby', 'keyword', { | ||
'regex': [ | ||
{ | ||
|
@@ -75,6 +77,10 @@ | |
'symbol': { | ||
pattern: /(^|[^:]):[a-zA-Z_]\w*(?:[?!]|\b)/, | ||
lookbehind: true | ||
}, | ||
'function': { | ||
pattern: /(def )[\w.]+/, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I had a little fun with a Ruby REPL and found that this pattern will also happily match: my_function_def variable But at the same time, it doesn't match def
extra_spaces_and_new_line(arg)
end Changing the lookbehind group to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good catch. (Although I’ve never seen someone put a newline between There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Well, me either, but the compiler can handle it, so there is probably someone out there using it. |
||
lookbehind: true, | ||
} | ||
}); | ||
|
||
|
@@ -128,4 +134,4 @@ | |
} | ||
} | ||
]; | ||
}(Prism)); | ||
}(Prism)); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
class Circle | ||
def self.of_diameter(diameter) | ||
new diameter / 2 | ||
end | ||
|
||
def initialize(radius) | ||
@radius = radius | ||
end | ||
|
||
def circumference | ||
Math::PI * radius ** 2 | ||
end | ||
|
||
# Seattle style | ||
def grow_by factor: | ||
@radius = @radius * factor | ||
end | ||
end | ||
|
||
---------------------------------------------------- | ||
|
||
[ | ||
["keyword", "class"], | ||
["class-name", ["Circle"]], | ||
["keyword", "def"], | ||
["function", "self.of_diameter"], | ||
["punctuation", "("], | ||
"diameter", | ||
["punctuation", ")"], | ||
["keyword", "new"], | ||
["class-name", ["diameter"]], | ||
["operator", "/"], | ||
["number", "2"], | ||
["keyword", "end"], | ||
["keyword", "def"], | ||
["function", "initialize"], | ||
["punctuation", "("], | ||
"radius", | ||
["punctuation", ")"], | ||
["variable", "@radius"], | ||
["operator", "="], | ||
" radius\n ", | ||
["keyword", "end"], | ||
["keyword", "def"], | ||
["function", "circumference"], | ||
["constant", "Math"], | ||
["punctuation", ":"], | ||
["punctuation", ":"], | ||
["constant", "PI"], | ||
["operator", "*"], | ||
" radius ", | ||
["operator", "*"], | ||
["operator", "*"], | ||
["number", "2"], | ||
["keyword", "end"], | ||
["comment", "# Seattle style"], | ||
["keyword", "def"], | ||
["function", "grow_by"], | ||
" factor", | ||
["punctuation", ":"], | ||
["variable", "@radius"], | ||
["operator", "="], | ||
["variable", "@radius"], | ||
["operator", "*"], | ||
" factor\n ", | ||
["keyword", "end"], | ||
["keyword", "end"] | ||
] | ||
|
||
---------------------------------------------------- | ||
|
||
Checks that method definitions are highlighted correctly |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably just nitpicking, but could you please remove the additional comma?