Is there a website that can recognize and identify what programming language is being input (pasted)?

My pastebin dpaste does this - when you paste stuff in the “Content” box and wait three seconds, it makes a guess.

The REST API I use for this feature is not publicized or documented, but you can use it if it suits you.

Here’s a usage example. Enter the curl command given below, then paste your content, then hit Enter, then hit ctrl-D. You get a JSON response with ranked guesses.

  1. $ curl -s -F "content=<-" dpaste.com/api/v2/guess-syntax/  
  2.  
  3. # Python 3: Fibonacci series up to n 
  4. >>> def fib(n): 
  5. >>> a, b = 0, 1 
  6. >>> while a < n: 
  7. >>> print(a, end=' ') 
  8. >>> a, b = b, a+b 
  9. >>> print() 
  10. >>> fib(1000) 
  11.  
  12. ^d 
  13. ["Python console session", "pycon", [["pycon", 1.25], ["python", 0.17]]] 

Riconosce questi linguaggi/sintassi attualmente:

Bash, BBcode, C, Clojure, C#, diff, HTML, HTML + Django template, HTML + PHP, Java, Javascript, JSON, nginx config, Objective-C, Python console, Python traceback, Python, Ruby, Tex, XML.

Tutti gli altri strumenti che ho visto per questo si sono occupati di identificare programmi completi, piuttosto che brevi frammenti di codice. Ma i brevi snippet sono tipici in un pastebin, così ho fatto il mio. È grezzo ma funziona.

A un certo punto ho intenzione di rendere questo un servizio autonomo alimentato da AWS Lambda o simili, e migliorarlo con qualche magia ML.