Comments (13)
For me this is highlighted as a regular expression:
/\/\d+\Z/
Sorry, but I don't know how to copy with colors, but it's the same as any other regular expression.
from language-ruby.
Reproduced using Atom v0.193.0-b1d005f on Mac OS X 10.10.3
from language-ruby.
I see, my fault.
from language-ruby.
Ugh. I was playing with this for a while to no avail. I added commit 6a5a77c to my local fork that adds a test for this behavior (which obviously fails). Since it fails, I won't do a PR but someone with a better feel for what's wrong can feel free to grab them and use them to fix. I am at a loss. 😞
For posterity, here is a reduced version:
In TextMate it seems like the whole thing is mostly treated like a regex, AFAICT:
from language-ruby.
Yeah it's one crazy tricky problem that's why I never tried to fix it, I attempted as well and was just like "I can't solve this easily right now I'll come back when I have time since it's a rare problem."
from language-ruby.
Yeah, part of the problem I ran into is the layout and regexes in the ruby.cson file. It looks like it was a CSON conversion of a JSON conversion of a TextMate file (obviously a heroic feat!) but my eyes glaze over regexes like '(?<![\\w)])((/))(?![*+?])(?=(?:\\\\/|[^/])*/[eimnosux]*\\s*([\\]#).,?:}]|$|\\|\\||&&|<=>|=>|==|=~|!~|!=|;|if|else|elsif|then|do|end|unless|while|until|or|and))'
I think the original TextMate file is better commented (I can see it in TM but can't find it online, but here is the Sublime Text version with the "cleaner" regex style. At a glance, however, it seems that the Atom one has diverged from these other two so it's not as simple as just porting it over. Again, someone with more knowledge might be able to make heads or tails of it.
from language-ruby.
So the issue with recognizing the start of a regular expression is distinguishing between it and the /
operator. The rule for TextMate and Atom take a similar approach by looking and the surrounding code to try to ascertain the context.
The rule in TextMate looks at the code preceding the opening slash to try to rule out false positives. Besides looking directly after the slash a single character it does not look forward at all.
The rule in Atom however starts with the slash and then tries to look at what follows the expression string. This is where the problem is, the expression to match the content of the regular expression string is very naive simply looking for escaped slashes or any character except slashes. The problem is that a slash can appear unescaped inside embedded ruby code or even a simple character class as in this also breaking example:
/test[/f]/
It's a complicated issue we've been trying to perfect for many years now, not sure which is the better approach. For the Atom approach to work though it needs to flawlessly match the contents of any regular expression to know when it is at the end of one.
from language-ruby.
I think both approaches have certain limits (or flaws). From what I know, language-ruby's approach
- can't deal with unescaped
/
.
While ruby.tmbundle's approach
- can't deal with situations where a method invocation that accepts a regexp as its first argument, with no parentheses around the arguments.
@50Wliu Rather than to say which is better, I say language-ruby's problem is slightly bigger.
from language-ruby.
When are unescaped slashes allowed? If they're only allowed in character classes I might have an idea.
from language-ruby.
Regexps allow Interpolations, in which you can use /
unescaped.
- As a division operator:
/#{a / b}/
- As regexps delimiters as in @envygeeks' example:
/#{…cidr.gsub(/\/\d+\Z/, "")…}…/
But people rarely create regexps like that, so we're ready to hear your great idea. 😄
from language-ruby.
I'm assuming if we move the division operator above the regexp block that'll break regexes entirely, correct?
from language-ruby.
Indeed.
from language-ruby.
My case:
DB_DUMP_REGEXP = /^
#{db_config[:database]}_#{DB_DUMP_TIMESTAMP_REGEXP}
#{Regexp.escape(DB_DUMP_EXTENSION)}
$/xo
from language-ruby.
Related Issues (20)
- Inconsistent highlighting of constants HOT 1
- Tree Sitter doesn't highlight public/private/protected HOT 1
- Symbol literals have incorrect class HOT 4
- Final `end` does not get highlighted after a block with a rescue inside a method HOT 2
- Inconsistency in Ruby symbol with TreeSitter HOT 2
- where is the path language-ruby get installed to on Windows HOT 1
- Hello HOT 1
- Failed to load a language-ruby package grammar - RHEL 7.7 HOT 20
- Failed to load a language-ruby package grammar HOT 1
- Syntax highlighting stops after <<base in for-each statement
- VS code support HOT 1
- Regex causes Gray (discolored) for large portion of Beginning HOT 13
- Abandoned? HOT 7
- Inconsistent highlighting of heredocs HOT 1
- Syntax highlighting broken in Markdown with inline comment at method definition line
- No release since Nov 2019 HOT 5
- Escaped characters in Ruby regex throws off color syntax highlighter HOT 3
- self.public shouldn't be colored as keyword
- Heredoc wrong colors
- Inconsistent color of local variable
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from language-ruby.