1

I have written the following code using pygments to get info on a string:

from pygments.lexers.jvm import JavaLexer
import pygments.lexers.jvm

t = 'float s = 0.5; System.out.println("Hello World");'
lexer = JavaLexer()
lexer.analyse_text(t)

I get a value of 0.0 as a result of running this code while it should be something greater than 0 since quite a lot of the code is java-specific. Where exactly am I going wrong?

1 Answers1

0

Most likely nothing :) The analyze_text method is useful when there are multiple languages sharing the same file extension, in which case the lexers should implement it properly. The JavaLexer has no analyze_text implemented, so it returns 0 by default. Hope that explains it!

Anteru
  • 19,042
  • 12
  • 77
  • 121