Twig and Jinja lexers share class variables. Both classes define keywords method like this:
class Jinja
def self.keywords
@@keywords ||= ...
end
end
class Twig < Jinja
def self.keywords
@@keywords ||= ...
end
end
If Twig.keywords is called before Jinja.keywords, @@keywords is set to Twig's and both methods return the same value. If not, @@keywords is initialized to Jinja's.
Solution
I changed class variables to instance variables. Other lexer classes define their keywords as instance variables.
Bug
Twig and Jinja may return incorrect token types for some special tokens like keywords. It depends on loading order.
cf. https://github.com/rouge-ruby/rouge/pull/1939#issuecomment-1499007812
Cause
Twig
andJinja
lexers share class variables. Both classes definekeywords
method like this:If
Twig.keywords
is called beforeJinja.keywords
,@@keywords
is set to Twig's and both methods return the same value. If not,@@keywords
is initialized to Jinja's.Solution
I changed class variables to instance variables. Other lexer classes define their keywords as instance variables.