I wonder what would happen to the accuracy of highlight.js highlightAuto method if more languages were to be supported. Highlight.js recognizes languages based on how many language constructs it can recognize. More languages = more overlap in language constructs, and therefore more likelihood of wrong matches.
Yup, it does a terrible job with the C family of languages. Hardly ever gets that right. And if you type in any random keys, it often identifies it as Haskell. ;-)
It does a decent job with Perl, Python, Ruby, Bash, etc.
Might mention that it sees Scala as Ruby or Python (ouch!). But I did just type in, "bunch of stuff, some programming stuff" and it thought that was Haskell or Coffeescript. Guess those win awards for literate programming?
It's in the same sense that PHP is a programming language -- Django has its own idiomatic templating language with loops and other such constructs. It looks like this:
As for why this thing can't recognize "it looks like HTML + JS", I can't answer that for you -- but there should be a family of responses; "HTML + PHP," "HTML + Django", "HTML + JS" etc.
(APL Code for Conway's Game of Life, taken from Wikipedia)
Recognized as Haskell.
This X[⍋X+.≠' ';] is AVRASM or CSS.
UPDATE: It gets better: INTERCAL (the despotic programming language) is recognized as Delphi or SQL. This seems suitable for Delphi ;) (Here's the code: http://cxg.de/_01a19b.htm)
with Ada.Text_IO;
procedure WTF
is
type X is array (Positive range <>) of Integer;
procedure Print (N: X)
is
begin
for I in N loop
Ada.Text_IO.Put_Line
(File => Ada.Text_IO.Standard_Output,
Item => Integer'Image (N (I));
end loop;
end Print;
begin
null;
end WTF;
And it can't recognize Ada :)
Even when you use standard library.
"This looks like VHDL."
"It could also be a VBSCRIPT, though I'm not completely sure"
Nice idea, but the quality and/or the breadth of languages it knows about leaves much to be desired.
The first language I tried was Forth. I have yet to find a piece of code that it recognizes as such. For example the example from http://c2.com/cgi/wiki?ExampleForthCode gets a 'VHDL, could also be VBSCRIPT'
I guess that the thing would look better of with some kind of thresholding that allows it to say 'I don't know, but if I had to guess, I would say RUBY or MEL' instead.
Its a neat idea but seems to struggle - misidentifying PHP as BASH, and struggling with Haskell, Go, Clojure, and told me Bash was PERL. I pulled some test code from the What's That Programming Language site which appeared on HN a few weeks ago http://wtpl.heroku.com/.
35 comments
[ 0.24 ms ] story [ 29.3 ms ] threadhttp://i.imgur.com/wITwa.png
Update:
Reading your blog post, I see that this is a wrapper around highlight.js, which is doing the language-guessing (including the second-best guess): http://softwaremaniacs.org/wiki/doku.php/highlight.js:api
It uses the highlight.js API for making the guesses, which provides the 2nd best option as well. :)
++++++++++[>+++++++>++++++++++>+++>+<<<<-]>++.>+.+++++++..+++.>++.<<+++++++++++++++.>.+++.------.--------.>+.>.
XML or django. then again this could be anything. :P
http://softwaremaniacs.org/media/soft/highlight/test.html
I wonder what would happen to the accuracy of highlight.js highlightAuto method if more languages were to be supported. Highlight.js recognizes languages based on how many language constructs it can recognize. More languages = more overlap in language constructs, and therefore more likelihood of wrong matches.
The idea to reduce language recognition to syntax highlighting is a nice idea, but doesn't seem to work.
Apparantly,
looks like DJANGO or XML.It does a decent job with Perl, Python, Ruby, Bash, etc.
#include<stdio.h> main() { printf("Hello World"); }
#include <stdio.h> XML
printf("%d", i); ERLANG
<cfset foo = "bar">
(defun factorial (n) (apply (function *) (upto n))) - MATLAB or Lua
This looks like xml. It could also be django, though. I'm not completely sure. //--------------------- How come Django is a programming language?
http://i.imgur.com/81uas.jpg
(APL Code for Conway's Game of Life, taken from Wikipedia) Recognized as Haskell.
This X[⍋X+.≠' ';] is AVRASM or CSS.
UPDATE: It gets better: INTERCAL (the despotic programming language) is recognized as Delphi or SQL. This seems suitable for Delphi ;) (Here's the code: http://cxg.de/_01a19b.htm)
The first language I tried was Forth. I have yet to find a piece of code that it recognizes as such. For example the example from http://c2.com/cgi/wiki?ExampleForthCode gets a 'VHDL, could also be VBSCRIPT'
My next attempt was PostScript. I copied http://www.science.uva.nl/~robbert/ps/bluebook/program_01.ht... (which starts with the giveaway line "%!PS-Adobe-2.0"), and it says 'RUBY, could also be MEL'
I guess that the thing would look better of with some kind of thresholding that allows it to say 'I don't know, but if I had to guess, I would say RUBY or MEL' instead.
"This looks like css. It could also be haskell, though. I'm not completely sure."
Erm, okay...
-----------------------
package main
import "fmt"
func main() { fmt.Println("Hello, 世界") }
-----------------------
Response: "This looks like actionscript. It could also be haskell, though. I'm not completely sure."
FAIL