Is there an already existing system, or modules to detect the kind of code a text chunk is (if any)??

for example, I read in a file, and I want to check it's syntax and figure out if it's html, javascript, perl, c, etc etc.

The thing I saw somehow close on cpan was : HTML::CGIChecker, it detects certain tags in text. Seems like a grat app I wanna use sometime(?).. But... It's not what I am thinking of.

The ideal program would take a chunk of text, and guess what it is.

Also, this program would.. be able to be fed different languages, so you could detect for english, or french, really it would be exactly the same procedures.

It seems to me ann endless set of heuristics are needed. That is.. The program has to be fed tons of code, told what it is. Then with that data, it can determine that the text analized is... say .. 15% perl, 10% javascript and 75% unknown. (therefore clearly simple text)

Reminds me lot of spam assasin. Perhaps it does something similar.

Is this already made? Would it have more then academic value? Is the task much more hairy then my little mind can glimpse?


In reply to how to guess the kind of spoken or programming language a text is written in by leocharre

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.