rouge-ruby / rouge

A pure Ruby code highlighter that is compatible with Pygments
https://rouge.jneen.net/
Other
3.3k stars 732 forks source link

Fix Wollok lexer: entity list is shared between lexer instances #1954

Closed nsfisis closed 1 year ago

nsfisis commented 1 year ago

cf. https://github.com/rouge-ruby/rouge/pull/1939#issuecomment-1532634686

Problem

Wollok lexer had entities class variable to track defined entities, e.g., class, object.

If a token is included in entities, it will be recognized as Name.Class; if not, Keyword.Variable

          if entities.include?(variable) || ('A'..'Z').cover?(variable[0])
            token Name::Class
          else
            token Keyword::Variable
          end

Since a class variable is shared between instances, each lexer shared entity list.

Solution

I changed entities to an instance variable.