Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Highlight unicode characters in constants #163

Merged
merged 1 commit into from

2 participants

@amarshall

#138 forgot about constants, and this remedies that mistake. Ruby doesn’t allow unicode characters as the first character of a constant (as shown by the below script), so we only highlight constants which have unicode characters as their second or later letter. I separately validated that all valid unicode characters are allowed (with a trivial modification of this script).

unicode_codepoints = 0x80..0x10FFFF

valid_codepoints = unicode_codepoints.select do |codepoint|
  str = [codepoint].pack 'U'
  begin
    eval "class #{str}; end"
  rescue SyntaxError
    false
  else
    true
  end
end

valid_codepoints  #=> []
@amarshall amarshall Highlight unicode characters in constants
Except those which are the first letter (e.g. `Ír`), as Ruby does not
recognize them as valid constants. (See also #138)
ab7c7e4
@dkearns dkearns merged commit ab7c7e4 into from
@amarshall amarshall deleted the branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jul 14, 2013
  1. @amarshall

    Highlight unicode characters in constants

    amarshall authored
    Except those which are the first letter (e.g. `Ír`), as Ruby does not
    recognize them as valid constants. (See also #138)
This page is out of date. Refresh to see the latest.
Showing with 1 addition and 1 deletion.
  1. +1 −1  syntax/ruby.vim
View
2  syntax/ruby.vim
@@ -92,7 +92,7 @@ syn match rubyFloat "\%(\%(\w\|[]})\"']\s*\)\@<!-\)\=\<\%(0\|[1-9]\d*\%(_\d\+\)*
syn match rubyLocalVariableOrMethod "\<[_[:lower:]][_[:alnum:]]*[?!=]\=" contains=NONE display transparent
syn match rubyBlockArgument "&[_[:lower:]][_[:alnum:]]" contains=NONE display transparent
-syn match rubyConstant "\%(\%(^\|[^.]\)\.\_s*\)\@<!\<\u\w*\>\%(\s*(\)\@!"
+syn match rubyConstant "\%(\%(^\|[^.]\)\.\_s*\)\@<!\<\u\%(\w\|[^\x00-\x7F]\)*\>\%(\s*(\)\@!"
syn match rubyClassVariable "@@\%(\h\|[^\x00-\x7F]\)\%(\w\|[^\x00-\x7F]\)*" display
syn match rubyInstanceVariable "@\%(\h\|[^\x00-\x7F]\)\%(\w\|[^\x00-\x7F]\)*" display
syn match rubyGlobalVariable "$\%(\%(\h\|[^\x00-\x7F]\)\%(\w\|[^\x00-\x7F]\)*\|-.\)"
Something went wrong with that request. Please try again.