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

fix(ruby): stricter block params, allowing bitwise OR #4188

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ CAVEATS / POTENTIALLY BREAKING CHANGES

Core Grammars:

- fix(ruby) correct bitwise OR(|) highlighting
- fix(rust) - adds emoji support in single quote strings [joshgoebel][]
- fix(apache) - support line continuation via `\` [Josh Goebel][]
- fix(makefile) - allow strings inside `$()` expressions [aneesh98][]
Expand Down
24 changes: 13 additions & 11 deletions src/languages/ruby.js
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,16 @@ export default function(hljs) {
]
};


const BLOCK_PARAMS = {
className: 'params',
begin: /(do|\{)\s\|(?!=)/,
end: /\|/,
excludeBegin: true,
excludeEnd: true,
keywords: RUBY_KEYWORDS,
};

const INCLUDE_EXTEND = {
match: [
/(include|extend)\s+/,
Expand Down Expand Up @@ -326,7 +336,9 @@ export default function(hljs) {
METHOD_DEFINITION,
{
// swallow namespace qualifiers before symbols
begin: hljs.IDENT_RE + '::' },
begin: hljs.IDENT_RE + '::'
},
BLOCK_PARAMS,
{
className: 'symbol',
begin: hljs.UNDERSCORE_IDENT_RE + '(!|\\?)?:',
Expand All @@ -348,15 +360,6 @@ export default function(hljs) {
className: "variable",
begin: '(\\$\\W)|((\\$|@@?)(\\w+))(?=[^@$?])' + `(?![A-Za-z])(?![@$?'])`
},
{
className: 'params',
begin: /\|(?!=)/,
end: /\|/,
excludeBegin: true,
excludeEnd: true,
relevance: 0, // this could be a lot of things (in other languages) other than params
keywords: RUBY_KEYWORDS
},
{ // regexp container
begin: '(' + hljs.RE_STARTERS_RE + '|unless)\\s*',
keywords: 'unless',
Expand Down Expand Up @@ -398,7 +401,6 @@ export default function(hljs) {

SUBST.contains = RUBY_DEFAULT_CONTAINS;
PARAMS.contains = RUBY_DEFAULT_CONTAINS;

// >>
// ?>
const SIMPLE_PROMPT = "[>?]>";
Expand Down
3 changes: 3 additions & 0 deletions test/markup/ruby/blocks.expect.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,6 @@
names |= users.map <span class="hljs-keyword">do</span> |<span class="hljs-params">user</span>|
user.name
<span class="hljs-keyword">end</span>

bitwise_or = <span class="hljs-number">1</span> | <span class="hljs-number">2</span>
not_registered_as_param
3 changes: 3 additions & 0 deletions test/markup/ruby/blocks.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,6 @@ end
names |= users.map do |user|
user.name
end

bitwise_or = 1 | 2
not_registered_as_param