(Ruby) Character literal notation not supported for some cases
See original GitHub issueDescribe the issue Only some cases of Character Literals seem to be supported. Support is missing for the following groups of cases (in decreasing importance):
- Single slash character (
?/
), breaks following lines as it gets treated as starting a regex - Escaped backslash character (
?\\
) - Non-ascii character (
?あ
) - Unicode using curly-bracket notation (
?\u{1AF9}
) - Control and Meta characters (
?\C-a
)
Which language seems to have the issue?
ruby
Are you using highlight
or highlightAuto
?
highlight
Sample Code to Reproduce
c = ?a #=> "a"
c = ?abc #=> SyntaxError
c = ?\n #=> "\n"
c = ?\s #=> " "
c = ?\\ #=> "\\"
c = ?\u{41} #=> "A"
c = ?\C-a #=> "\x01"
c = ?\M-a #=> "\xE1"
c = ?\M-\C-a #=> "\x81"
c = ?\C-\M-a #=> "\x81", same as above
c = ?あ #=> "あ"
c = ?/ #=> /
c = ?\123 # octal bit pattern, where nnn is 1-3 octal digits ([0-7])
c = ?\xA1 # hexadecimal bit pattern, where nn is 1-2 hexadecimal digits ([0-9a-fA-F])
c = ?\uAF09 # Unicode character, where nnnn is exactly 4 hexadecimal digits ([0-9a-fA-F])
c = ?\cx # control character, where x is an ASCII printable character
c = ?\c\M-x # meta control character, where x is an ASCII printable character
c = ?\c? # delete, ASCII 7Fh (DEL)
c = ?\C-? # delete, ASCII 7Fh (DEL)
Expected behavior
Additional context Seen in this StackExchange/CodeGolf answer: https://codegolf.stackexchange.com/a/217367/25026
->(n,g=->c,d{(1..n).map{|i|" "*(n-i)+d+" "*2*(n+i-1)+c}},l=g[?/,e=?\\].reverse){[" "*n+?_*n*2,g[e,?/],l[0..-2],l[-1].sub(/ +(?=\/)/,?_*n*2)]}
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (5 by maintainers)
Top Results From Across the Web
literals - Documentation for Ruby 2.4.0
Literals create objects you can use in your program. Literals include: Booleans and nil. Numbers. Strings. Symbols. Arrays. Hashes.
Read more >Is there a literal notation for an array of symbols?
Yes! This is possible now in Ruby 2.0.0. One way to write it is: %i{foo bar} # => [:foo, :bar]. You can also...
Read more >Understanding 'String Literals' in Ruby - ThoughtCo
Learn the Ruby basics of strings, string interpolation, single and double quotes, escape sequences and alternate string literal syntaxes.
Read more >How To Work with Strings in Ruby - DigitalOcean
A string literal is the string as it is written in the source code, including quotations. A string value is what you see...
Read more >String literal in Ruby - Coding Ninjas CodeStudio
In most cases, backslashes in string literals do not need to be ... Another syntax utilizing quotes and strings is supported by Ruby....
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Ah, but that character does not form a word boundary so
\b
will abort the match.If we’re going to fix this we need variants, not one big regex. 😃
\S
seems to match unicode: