Skip to content

Commit

Permalink
Fix tokenizing of defined? in Ruby lexer (#1247)
Browse files Browse the repository at this point in the history
Due to the fact that `defined?` ends in a question mark, this was
causing issues with its tokenization. This commit fixes the error.
  • Loading branch information
ashmaroli authored and pyrmont committed Jul 8, 2019
1 parent f82edb2 commit 23ae3ea
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/rouge/lexers/ruby.rb
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ def self.detect?(text)

mixin :strings

rule %r/(?:#{keywords.join('|')})\b/, Keyword, :expr_start
rule %r/(?:#{keywords.join('|')})(?=\W|$)/, Keyword, :expr_start
rule %r/(?:#{keywords_pseudo.join('|')})\b/, Keyword::Pseudo, :expr_start

rule %r(
Expand Down
29 changes: 29 additions & 0 deletions spec/visual/samples/ruby
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,35 @@ a/ b #comment
x.a / 1 # comment
Foo::a / 3 + 4

########
# Keywords that may be immediately followed by an opening
# parenthesis
########

# defined?
return if defined? Rouge
return unless defined?(Foobar)

# super
class Beta < Alpha
def gamma(msg)
super
@msg = msg
end
end

class Bar < Foo
def log(msg)
super()
end
end

class Ipsum < Lorem
def dolor(txt)
super(txt)
end
end

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

0 comments on commit 23ae3ea

Please sign in to comment.