question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

(Ruby) Character literal notation not supported for some cases

See original GitHub issue

Describe 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)

Ruby Character Literals - Actual

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 Ruby Character Literals - Expected

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)]}

image

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
joshgoebelcommented, Jan 6, 2021

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. 😃

0reactions
Hirsecommented, Jan 6, 2021

\S seems to match unicode: image https://regexr.com/5jodu

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found