Skip to content
This repository has been archived by the owner on Sep 8, 2023. It is now read-only.

Commit

Permalink
Fix tokenization of compact class names in Ruby lexer (rouge-ruby#1470)
Browse files Browse the repository at this point in the history
The Ruby lexer currently tokenises compact class names differently to
how they are tokenised if nested. This commit makes both results
consistent.
  • Loading branch information
ashmaroli authored and mattt committed May 21, 2020
1 parent a0cce91 commit 6f63ff0
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/rouge/lexers/ruby.rb
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,8 @@ def self.detect?(text)

state :classname do
rule %r/\s+/, Text
rule %r/\w+(::\w+)+/, Name::Class

rule %r/\(/ do
token Punctuation
push :defexpr
Expand Down
39 changes: 39 additions & 0 deletions spec/visual/samples/ruby
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,45 @@ class Ipsum < Lorem
end
end

########
# Various types of class definitions
########

# Singleton class definition
module Table
module Row
DEFAULTS = { cell_width: 80, cell_height: 60 }

class << self
def styles hsh
hsh.merge DEFAULTS
end
end
end
end

# Nested class name
module Table
module Row
class Cell < Table::Block
WIDTH = TABLE::ROW::styles[:cell_width]

def text string, width = WIDTH
string.center width
end
end
end
end

# Compact class name
class Table::Row::Cell < Table::Block
WIDTH = TABLE::ROW::styles[:cell_width]

def text string, width = WIDTH
string.center width
end
end

########
# The popular . :bow:
########
Expand Down

0 comments on commit 6f63ff0

Please sign in to comment.