Search code examples
pythonsyntaxpattern-recognition

Syntax recognizer in python


I need a module or strategy for detecting that a piece of data is written in a programming language, not syntax highlighting where the user specifically chooses a syntax to highlight. My question has two levels, I would greatly appreciate any help, so:

  1. Is there any package in python that receives a string(piece of data) and returns if it belongs to any programming language syntax ?
  2. I don't necessarily need to recognize the syntax, but know if the string is source code or not at all.

Any clues are deeply appreciated.


Solution

  • Maybe you can use existing multi-language syntax highlighters. Many of them can detect language a file is written in.