From fcddd156378296ea642b502c6042695963c29299 Mon Sep 17 00:00:00 2001 From: Michael Camilleri Date: Mon, 17 Feb 2020 07:33:47 +0900 Subject: [PATCH] Fix symbol lexing in Scala lexer (#1438) 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. --- lib/rouge/lexers/scala.rb | 2 +- spec/visual/samples/scala | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/rouge/lexers/scala.rb b/lib/rouge/lexers/scala.rb index 0c34b87d86..d13dbcbd94 100644 --- a/lib/rouge/lexers/scala.rb +++ b/lib/rouge/lexers/scala.rb @@ -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 diff --git a/spec/visual/samples/scala b/spec/visual/samples/scala index c72980b851..3fd6cfc579 100644 --- a/spec/visual/samples/scala +++ b/spec/visual/samples/scala @@ -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 \ No newline at end of file +StorageState.table(StorageState.NewUsers()).format( + keyParams('app_id).asInstanceOf[String] +) + +// Comment at EOF