programming language detection

Log in to Vote
107
107 Votes • 6 Comments
given a code snippet, make a good guess as to what programming language it is written in.

(following up on language detection :) )
• posted 6 years and 3 months ago • type: Spice (API calls) Needs a Developer

anonymous
if anyone thinks this is not a completely bogus idea, i would enjoy taking it up in my spare time.
I'm guessing this would classify as a Goodie, right?
posted by [UserVoice Dan Droid] • 6 years and 3 months ago Link
anonymous
I think that this could be useful. You may want to look at filetype.vim, the script that vim uses to determine filetype and how to highlight syntax. Much of its detection is based on filename, which would not be useful, but it also has many patterns in it for filetypes that do not always have a set extention, and these could be useful.
posted by [UserVoice magicalChicken] • 5 years and 6 months ago Link
anonymous
GitHub has a pretty great library that includes language detection. https://github.com/github/linguist
posted by [UserVoice Michael Joseph Mior] • 5 years and 5 months ago Link
anonymous
Thanks for the source, Michael.
posted by [UserVoice DuckDuckGo Team] • 5 years and 5 months ago Link
anonymous
This would be fairly easy to implement using the existing searchcode API (already a DDH plugin) and not require additional software installed.

You just need to pass the snippet though like so

http://searchcode.com/api/codesearch_I/?...
http://searchcode.com/api/codesearch_I/?...

and then sum up each of the types to make a guess as to the language. Assuming its a real snippet it would work fairly well as all the language detection is already done with support for over 80 languages.
posted by [UserVoice Anonymous] • 5 years and 5 months ago Link
SirCmpwn
This is a bit old, but I can think of two ways to implement it. Both use BSD's 'file' tool (man file).

The first way would be to make "file as a service" and host it somewhere. The second way would be to try and get file running with emscripten, which would be bloaty and complicated, but likely to work.

This could probably be extended to "what is this file" with either of these solutions.
posted by SirCmpwn 4 years and 1 month ago Link