Skip to content

Commit

Permalink
support MATLAB
Browse files Browse the repository at this point in the history
  • Loading branch information
hhatto committed Apr 10, 2016
1 parent 5631a57 commit 4fc4a7a
Show file tree
Hide file tree
Showing 3 changed files with 232 additions and 211 deletions.
257 changes: 138 additions & 119 deletions language.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@ package main

import (
"bufio"
"fmt"
"os"
"path/filepath"
"regexp"
"strings"

"github.com/generaltso/linguist"
)

type Language struct {
Expand Down Expand Up @@ -37,125 +40,127 @@ func (ls Languages) Less(i, j int) bool {
}

var Exts map[string]string = map[string]string{
"as": "as",
"asm": "s",
"S": "s",
"s": "s",
"awk": "awk",
"bat": "bat",
"btm": "bat",
"cmd": "bat",
"bash": "bash",
"sh": "sh",
"c": "c",
"csh": "csh",
"ec": "c",
"erl": "erl",
"hrl": "erl",
"pgc": "c",
"cs": "cs",
"clj": "clj",
"coffee": "coffee",
"cfm": "cfm",
"cfc": "cfc",
"cmake": "cmake",
"cc": "cpp",
"cpp": "cpp",
"cxx": "cpp",
"pcc": "cpp",
"c++": "cpp",
"css": "css",
"cu": "cu",
"d": "d",
"dart": "dart",
"dtrace": "dtrace",
"dts": "dts",
"dtsi": "dts",
"el": "lisp",
"exp": "exp",
"ex": "exs",
"exs": "exs",
"lisp": "lisp",
"lsp": "lisp",
"lua": "lua",
"sc": "lisp",
"f": "f77",
"f77": "f77",
"for": "f77",
"ftn": "f77",
"pfo": "f77",
"f90": "f90",
"f95": "f90",
"f03": "f90",
"f08": "f90",
"go": "go",
"h": "h",
"hs": "hs",
"hpp": "hpp",
"hh": "hpp",
"html": "html",
"hxx": "hpp",
"il": "il",
"jai": "jai",
"java": "java",
"js": "js",
"jl": "jl",
"json": "json",
"jsx": "jsx",
"lds": "lds",
"less": "less",
"m": "m",
"md": "md",
"markdown": "md",
"ml": "ml",
"mli": "ml",
"mm": "mm",
"maven": "maven",
"makefile": "makefile",
"mustache": "mustache",
"m4": "m4",
"l": "lex",
"php": "php",
"pas": "pas",
"PL": "pl",
"pl": "pl",
"pm": "pl",
"plan9sh": "plan9sh",
"ps1": "ps1",
"text": "text",
"txt": "text",
"polly": "polly",
"proto": "proto",
"py": "py",
"r": "r",
"rake": "rb",
"rb": "rb",
"rkt": "rkt",
"rhtml": "rhtml",
"rs": "rs",
"sass": "sass",
"scala": "scala",
"scss": "sass",
"scm": "scm",
"sed": "sed",
"sml": "sml",
"sql": "sql",
"swift": "swift",
"tex": "tex",
"sty": "tex",
"toml": "toml",
"ts": "ts",
"csproj": "vcproj",
"vcproj": "vcproj",
"vim": "vim",
"xml": "xml",
"xsl": "xsl",
"xslt": "xsl",
"wxs": "wxs",
"yaml": "yaml",
"yml": "yaml",
"y": "y",
"zsh": "zsh",
"as": "as",
"asm": "s",
"S": "s",
"s": "s",
"awk": "awk",
"bat": "bat",
"btm": "bat",
"cmd": "bat",
"bash": "bash",
"sh": "sh",
"c": "c",
"csh": "csh",
"ec": "c",
"erl": "erl",
"hrl": "erl",
"pgc": "c",
"cs": "cs",
"clj": "clj",
"coffee": "coffee",
"cfm": "cfm",
"cfc": "cfc",
"cmake": "cmake",
"cc": "cpp",
"cpp": "cpp",
"cxx": "cpp",
"pcc": "cpp",
"c++": "cpp",
"css": "css",
"cu": "cu",
"d": "d",
"dart": "dart",
"dtrace": "dtrace",
"dts": "dts",
"dtsi": "dts",
"el": "lisp",
"exp": "exp",
"ex": "exs",
"exs": "exs",
"lisp": "lisp",
"lsp": "lisp",
"lua": "lua",
"sc": "lisp",
"f": "f77",
"f77": "f77",
"for": "f77",
"ftn": "f77",
"pfo": "f77",
"f90": "f90",
"f95": "f90",
"f03": "f90",
"f08": "f90",
"go": "go",
"h": "h",
"hs": "hs",
"hpp": "hpp",
"hh": "hpp",
"html": "html",
"hxx": "hpp",
"il": "il",
"jai": "jai",
"java": "java",
"js": "js",
"jl": "jl",
"json": "json",
"jsx": "jsx",
"lds": "lds",
"less": "less",
"Objective-C": "Objective-C", // deplicated Obj-C/Matlab
"Matlab": "Matlab", // both use ext '.m'
"md": "md",
"markdown": "md",
"ml": "ml",
"mli": "ml",
"mm": "mm",
"maven": "maven",
"makefile": "makefile",
"mustache": "mustache",
"m4": "m4",
"l": "lex",
"php": "php",
"pas": "pas",
"PL": "pl",
"pl": "pl",
"pm": "pl",
"plan9sh": "plan9sh",
"ps1": "ps1",
"text": "text",
"txt": "text",
"polly": "polly",
"proto": "proto",
"py": "py",
"r": "r",
"R": "r",
"rake": "rb",
"rb": "rb",
"rkt": "rkt",
"rhtml": "rhtml",
"rs": "rs",
"sass": "sass",
"scala": "scala",
"scss": "sass",
"scm": "scm",
"sed": "sed",
"sml": "sml",
"sql": "sql",
"swift": "swift",
"tex": "tex",
"sty": "tex",
"toml": "toml",
"ts": "ts",
"csproj": "vcproj",
"vcproj": "vcproj",
"vim": "vim",
"xml": "xml",
"xsl": "xsl",
"xslt": "xsl",
"wxs": "wxs",
"yaml": "yaml",
"yml": "yaml",
"y": "y",
"zsh": "zsh",
}

var LanguageByScript map[string]string = map[string]string{
Expand Down Expand Up @@ -219,6 +224,20 @@ func getFileType(path string) (ext string, ok bool) {
ext = filepath.Ext(path)
base := filepath.Base(path)

switch ext {
case ".m":
hints := linguist.LanguageHints(path)
cont, err := getContents(path)
if err != nil {
return "", false
}
lang := linguist.LanguageByContents(cont, hints)
if opts.Debug {
fmt.Printf("path=%v, lang=%v\n", path, lang)
}
return lang, true
}

switch base {
case "CMakeLists.txt":
return "cmake", true
Expand Down
Loading

0 comments on commit 4fc4a7a

Please sign in to comment.