I am looking for a library that can detect in which programming language a code snippet is written. We can make the assumption that the code snippet is written in one language only.
E.g. for natural languages, I use the Python library guess_language:
>>> from guess_language import guess_language >>> guess_language("Ces eaux regorgent de renégats et de voleurs.") 'fr' >>> guess_language("Tienes que seguir tu corazón.") 'es' >>> guess_language("いいえ！忍者がいます") 'ja' >>> not guess_language("??") True
If possible, it should return the probabilities of belonging to each programming language (e.g. for one code snippet given as input, the ouput could be 94% MATLAB, 30% Python, 5% Java, etc). Ideally, callable from Python/Java/C++ (descending order of preference), and free.