Skip to content

Commit

Permalink
Fix symbol lexing in Scala lexer (#1438)
Browse files Browse the repository at this point in the history
The Scala lexer currently matches symbols by ensuring that the last
character in the match is not a `'`.

The problem with this approach is that if the symbol occurs within a
larger structure (e.g. parentheses), the first character after the
symbol (e.g. the closing parenthesis) is matched as part of the symbol.

This commit uses a negative lookahead to avoid this problem.
  • Loading branch information
pyrmont committed Feb 16, 2020
1 parent 36f1b72 commit fcddd15
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/rouge/lexers/scala.rb
Expand Up @@ -40,7 +40,7 @@ class Scala < RegexLexer
groups Keyword, Text
push :class
end
rule %r/'#{idrest}[^']/, Str::Symbol
rule %r/'#{idrest}(?!')/, Str::Symbol
rule %r/[^\S\n]+/, Text

rule %r(//.*), Comment::Single
Expand Down
6 changes: 5 additions & 1 deletion spec/visual/samples/scala
Expand Up @@ -64,4 +64,8 @@ class why_would_you_name_a_class_this_way_oh_well_we_need_to_highlight_it(a: Int
def hex = 0x123
}

// Comment at EOF
StorageState.table(StorageState.NewUsers()).format(
keyParams('app_id).asInstanceOf[String]
)

// Comment at EOF

0 comments on commit fcddd15

Please sign in to comment.