1. Georg Brandl
  2. pygments-main
  3. Issues
Issue #831 new

Groovy lexer doesn't properly colorize code with division operators

Anonymous created an issue

The Groovy lexer doesn't colorize the following code properly:

def str1 = /String one/
int num = 30 / 3
num /= 10
def str2 = /String two/

If the code does not use slashy strings, an easy workaround would be to simply disable colorization for them as follows (line 331 of jvm.py):

            #(r'/(\\\\|\\"|[^/])*/', String),

However, this code does, and it appears that a fix would need to disambiguate between a '/' that is a division operator and a '/' that is the start of a slashy string. I do not know Pygments enough to do this fix and thus I humbly ask for help from the experts.

Comments (3)

  1. David Corbett

    The solution is to have two states: one for the start of an expression, the other for the middle of an expression. If a slash is at the start of an expression, it’s a regex. Otherwise it’s a division operator. See for example the states _expression and expression in Inform6Lexer; that language doesn’t have regex literals but it’s the same idea.

  2. Log in to comment