Skip to content

Highly maintained improved version of source code detection algorithm. Including NNET improvements, large datasets training, support for python3 and more.

License

Notifications You must be signed in to change notification settings

NextSecurity/SourceCodeDetector

 
 

Repository files navigation

SourceCodeDetector Build Status Documentation Status

Guesslang

Source code detector detects the programming language of a given source code:

echo '
package main
import "fmt"

func main() {
    fmt.Println("My mascot is a gopher and Google loves me. Who am I?")
}

' | guesslang

# ⟶ Programming language: Go

Guesslang supports 30 programming languages:

Languages
Batchfile C C# C++ CSS
CoffeeScript Erlang Go HTML Haskell
Java JavaScript Jupyter Notebook Lua Markdown
Matlab Objective-C PHP Perl PowerShell
Python R Ruby Rust SQL
Scala Shell Swift TeX TypeScript

With a guessing accuracy higher than 90%.

Apps powered by Guesslang

Chameledit

Chameledit is a simple web-editor that automatically highlights your code.

Pasta

Pasta is a Slack bot that pretty pastes source code.

Watch the demo here

GG

GG is a silly guessing game.

Documentation

Installation

  • Python 3.6+ is required

  • Windows specific

To run Tensorflow on Microsoft Windows you need to install Visual C++ runtime libraries, available on Microsoft website

Guesslang command line

  • Show all available options
guesslang --help
  • Detect the programming language of /bin/which:
guesslang /bin/which

# ⟶ Programming language: Shell
  • Detect the programming language of a given text:
echo '
/** Turn command line arguments to uppercase */
object Main {
  def main(args: Array[String]) {
    val res = for (a <- args) yield a.toUpperCase
    println("Arguments: " + res.toString)
  }
}
' | guesslang

# ⟶ Programming language: Scala
  • Show the detection probabilities for a given source code:
echo "
def qsort(items):
    if not items:
        return []
    else:
        pivot = items[0]
        less = [x for x in items if x <  pivot]
        more = [x for x in items[1:] if x >= pivot]
        return qsort(less) + [pivot] + qsort(more)


if __name__ == '__main__':
    items = [1, 4, 2, 7, 9, 3]
    print(f'Sorted: {qsort(items)}')

" | guesslang --probabilities

# Language name       Probability
#  Python               80.53%
#  Batchfile             6.16%
#  CoffeeScript          2.18%
#  Markdown              1.66%
#  JavaScript            1.47%
# ...
from guesslang import Guess


guess = Guess()

name = guess.language_name("""
    % Quick sort

    -module (recursion).
    -export ([qsort/1]).

    qsort([]) -> [];
    qsort([Pivot|T]) ->
          qsort([X || X <- T, X < Pivot])
          ++ [Pivot] ++
          qsort([X || X <- T, X >= Pivot]).
""")

print(name)  # ⟶ Erlang

About

Highly maintained improved version of source code detection algorithm. Including NNET improvements, large datasets training, support for python3 and more.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Python 98.9%
  • Shell 1.1%